Exemple #1
0
 def test_method_call_chain(self):
     self.assertParsesFirstStatement('o:m1(a):m2(b, c):m3(d, e, f)', [
         MethodCall(
             MethodCall(MethodCall(Var('o'), Var('m1'), [Var('a')]),
                        Var('m2'), [Var('b'), Var('c')]), Var('m3'),
             [Var('d'), Var('e'), Var('f')])
     ])
Exemple #2
0
 def test_comments_lines_are_ignored(self):
     self.assertParsesBlock(
         'x = "lorem ipsum"\n'
         '-- comment\n'
         '-- \n'
         '-- another comment\n'
         'y = "lipsum"',
         Block(Assignment([Var('x')], [LiteralString('lorem ipsum')]),
               Assignment([Var('y')], [LiteralString('lipsum')])))
Exemple #3
0
 def test_table_with_unnamed_fields(self):
     self.assertParsesFirstStatement('x = {"lorem ipsum", true}', [
         Assignment([Var('x')], [
             Table(UnnamedField(LiteralString(value='lorem ipsum')),
                   UnnamedField(Boolean('true')))
         ])
     ])
Exemple #4
0
 def test_table_with_named_fields(self):
     self.assertParsesFirstStatement(
         'x = {field1="lorem ipsum", field2=true}', [
             Assignment([Var('x')], [
                 Table(NamedField('field1', LiteralString('lorem ipsum')),
                       NamedField('field2', Boolean('true')))
             ])
         ])
Exemple #5
0
 def test_method_call_with_args_list(self):
     self.assertParsesFirstStatement(
         'o:f(a)', [MethodCall(Var('o'), Var('f'), [Var('a')])])
Exemple #6
0
 def test_function_call_with_args_list(self):
     self.assertParsesFirstStatement('f(a)',
                                     [FunctionCall(Var('f'), [Var('a')])])
Exemple #7
0
 def test_method_call_without_args(self):
     self.assertParsesFirstStatement('o:f()',
                                     [MethodCall(Var('o'), Var('f'), [])])
Exemple #8
0
 def test_function_call_without_args(self):
     self.assertParsesFirstStatement('f()', [FunctionCall(Var('f'), [])])
Exemple #9
0
 def test_function_chain_of_two_calls(self):
     self.assertParsesFirstStatement(
         'f(a)(b)',
         [FunctionCall(FunctionCall(Var('f'), [Var('a')]), [Var('b')])])
Exemple #10
0
 def test_nil(self):
     self.assertParsesFirstStatement('x = nil',
                                     [Assignment([Var('x')], [nil])])
Exemple #11
0
 def test_mutilple_string_assignments(self):
     self.assertParsesBlock(
         'x = "lorem ipsum"; y = "lipsum"',
         Block(Assignment([Var('x')],
                          [LiteralString('lorem ipsum')]), semicolon,
               Assignment([Var('y')], [LiteralString('lipsum')])))
Exemple #12
0
 def test_comments_are_ignored_at_the_end_of_line(self):
     self.assertParsesFirstStatement(
         'x = "lorem ipsum" -- comment',
         [Assignment([Var('x')], [LiteralString("lorem ipsum")])])
Exemple #13
0
 def test_string(self):
     self.assertParsesFirstStatement(
         'x = "lorem ipsum"',
         [Assignment([Var('x')], [LiteralString("lorem ipsum")])])
Exemple #14
0
 def test_print_assignment(self):
     self.assertPrints(Assignment([Var('x')], [LiteralString('test')]),
                       "x = 'test'")
Exemple #15
0
 def test_function_call_chain_with_strings_arguments(self):
     self.assertParsesFirstStatement('f "a" "b" "c"', [
         FunctionCall(
             FunctionCall(FunctionCall(Var('f'), [LiteralString('a')]),
                          [LiteralString('b')]), [LiteralString('c')])
     ])
Exemple #16
0
 def test_function_call_with_arg_string(self):
     self.assertParsesFirstStatement(
         'f "string"', [FunctionCall(Var('f'), [LiteralString('string')])])
Exemple #17
0
 def test_method_call_with_arg_string(self):
     self.assertParsesFirstStatement(
         'o:f "string"',
         [MethodCall(Var('o'), Var('f'), [LiteralString('string')])])
Exemple #18
0
 def test_empty_table(self):
     self.assertParsesFirstStatement('x = {}',
                                     [Assignment([Var('x')], [Table()])])
Exemple #19
0
 def test_method_chain_of_two_calls(self):
     self.assertParsesFirstStatement('o:m1(a):m2(b)', [
         MethodCall(MethodCall(Var('o'), Var('m1'), [Var('a')]), Var('m2'),
                    [Var('b')])
     ])
Exemple #20
0
 def test_mixed_chain_of_two_calls(self):
     self.assertParsesFirstStatement('o:m1(a)(b)', [
         FunctionCall(MethodCall(Var('o'), Var('m1'), [Var('a')]),
                      [Var('b')])
     ])