예제 #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'))
예제 #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])
예제 #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'])
예제 #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}])
예제 #5
0
 def test_string(self):
     eq_(decode('"ohai".'), [('ohai')])
     eq_(decode(r'"password:\"123\"".'), [('password:"******"')])
예제 #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)])
예제 #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]])
예제 #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}].')
예제 #9
0
 def test_binary(self):
     eq_(decode('<<>>.'), [('')])
     eq_(decode('<<"ohai">>.'), [('ohai')])
     eq_(decode('<<"ohai", "ohai">>.'), [('ohaiohai')])
     eq_(decode('<<97, 98, 99>>.'), [('abc')])
예제 #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')])
예제 #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}])
예제 #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')])
예제 #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')]])
예제 #14
0
 def test_binary(self):
     eq_(decode('<<>>.'), [('')])
     eq_(decode('<<"ohai">>.'), [('ohai')])
     eq_(decode('<<"ohai", "ohai">>.'), [('ohaiohai')])
     eq_(decode('<<97, 98, 99>>.'), [('abc')])
예제 #15
0
 def test_complex2(self):
     eq_(decode('["foo", <<"bar">>].'),
         [['foo', 'bar']])
예제 #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'])
예제 #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')])