Ejemplo n.º 1
0
    def test_read(self):
        [props] = decode('[{foo, bar}, {"foo", 42}, {1, true}].')
        eq_(props[Atom('foo')], Atom('bar'))
        eq_(props["foo"], 42)
        eq_(props[1], True)

        eq_(props.foo, Atom('bar'))
Ejemplo n.º 2
0
 def test_comment(self):
     eq_(decode("% comment"), [])
     eq_(decode("% comment\n"), [])
     eq_(decode('"%% comment". % comment'), ["%% comment"])
     eq_(decode("% comment\n\n"), []) # check multi-line
     eq_(decode("true. % comment\n true."), [True, True])
     eq_(decode("true. % comment\n"), [True])
Ejemplo n.º 3
0
 def test_complex(self):
     eq_(decode('[{outer_key, #{"inner_key" => [whatever]}}, {<<"another_outer_key">>, false}]. punchline.'),
         [[('outer_key', {'inner_key': ['whatever']}),
           ('another_outer_key', False)],
          'punchline'])
Ejemplo n.º 4
0
 def test_map(self):
     eq_(decode('#{}.'), [{}])
     eq_(decode('#{ a=>1}.'), [{"a":1}])
     eq_(decode('#{a =>1, b=>2, c=>3}.'), [{"a":1, "b":2, "c":3}])
     eq_(decode('#{a=> #{a=>1, b => 2}, b=>2}.'), [{"a":{"a":1, "b":2}, "b":2}])
Ejemplo n.º 5
0
 def test_string(self):
     eq_(decode('"ohai".'), [('ohai')])
     eq_(decode(r'"password:\"123\"".'), [('password:"******"')])
Ejemplo n.º 6
0
 def test_tuple(self):
     eq_(decode('{}.'), [()])
     eq_(decode('{1}.'), [(1,)])
     eq_(decode('{18, 4, 9}.'), [(18, 4, 9)])
     eq_(decode('{{18, 4}, 9}.'), [((18, 4), 9)])
Ejemplo n.º 7
0
 def test_list(self):
     eq_(decode('[].'), [[]])
     eq_(decode('[1].'), [[1]])
     eq_(decode('[18, 4, 9].'), [[18, 4, 9]])
     eq_(decode('[[18, 4], 9].'), [[[18, 4], 9]])
Ejemplo n.º 8
0
    def test_write(self):
        [props] = decode('[{foo, bar}, {"foo", 42}, {1, true}].')
        props.foo = Atom('baz')

        eq_(encode([props]), '[{1, true}, {foo, baz}, {"foo", 42}].')
Ejemplo n.º 9
0
 def test_binary(self):
     eq_(decode('<<>>.'), [('')])
     eq_(decode('<<"ohai">>.'), [('ohai')])
     eq_(decode('<<"ohai", "ohai">>.'), [('ohaiohai')])
     eq_(decode('<<97, 98, 99>>.'), [('abc')])
Ejemplo n.º 10
0
 def test_complex(self):
     eq_(decode('[{outer_key, #{"inner_key" => [whatever]}}, {<<"another_outer_key">>, false}]. punchline.'),
         [Proplist({Atom('outer_key'): {'inner_key': [Atom('whatever')]},
           "another_outer_key":  False}),
          Atom('punchline')])
Ejemplo n.º 11
0
 def test_map(self):
     eq_(decode('#{}.'), [{}])
     eq_(decode('#{ a=>1}.'), [{Atom('a'):1}])
     eq_(decode('#{a =>1, b=>2, c=>3}.'), [{Atom('a'):1, Atom('b'):2, Atom('c'):3}])
     eq_(decode('#{a=> #{a=>1, b => 2}, b=>2}.'), [{Atom('a'):{Atom('a'):1, Atom('b'):2}, Atom('b'):2}])
Ejemplo n.º 12
0
 def test_string(self):
     eq_(decode('"ohai".'), [('ohai')])
     eq_(decode(r'"password:\"123\"".'), [('password:"******"')])
     eq_(decode('"ascii code \e[1;34m".'), [('ascii code \e[1;34m')])
Ejemplo n.º 13
0
 def test_proplist(self):
     eq_(decode('[{foo, bar}, {"string", 42}].'), [Proplist({Atom('foo'): Atom('bar'), "string": 42})])
     eq_(decode('[{foo, bar}, baz].'), [[(Atom('foo'), Atom('bar')), Atom('baz')]])
Ejemplo n.º 14
0
 def test_binary(self):
     eq_(decode('<<>>.'), [('')])
     eq_(decode('<<"ohai">>.'), [('ohai')])
     eq_(decode('<<"ohai", "ohai">>.'), [('ohaiohai')])
     eq_(decode('<<97, 98, 99>>.'), [('abc')])
Ejemplo n.º 15
0
 def test_complex2(self):
     eq_(decode('["foo", <<"bar">>].'),
         [['foo', 'bar']])
Ejemplo n.º 16
0
 def test_simple_types(self):
     eq_(decode('18.'), [18])
     eq_(decode('18 .'), [18])
     eq_(decode('18.  19  . 21.'), [18, 19, 21])
     eq_(decode('18.88.'), [18.88])
     eq_(decode('1.5e-2.'), [0.015])
     eq_(decode('2#10.'), [2])
     eq_(decode('true.'), [True])
     eq_(decode('false.'), [False])
     eq_(decode('16#FF.'), [255])
     eq_(decode('atom.'), ['atom'])
     eq_(decode('"String".'), ['String'])
     eq_(decode('<<"Binary">>.'), ['Binary'])
Ejemplo n.º 17
0
 def test_string(self):
     eq_(decode('"ohai".'), [('ohai')])
     eq_(decode(r'"password:\"123\"".'), [('password:"******"')])
     eq_(decode(r'"\\\\".'), [('\\\\')])
     eq_(decode('"ascii code \e[1;34m".'), [('ascii code \e[1;34m')])