+class TestParser(TestConfig):
+ s1 = r"""a="1";z{b='2';w{S.Tr_an-g.e='""'}};c.d='\n';e="{a}{b}";e+='{c.d}';a+="\"\n\{\}";f+='Z{a.b}'"""
+ s2 = '\t\n \n ' + s1.replace('=', '= \n ').replace(';', '\t \n\t \n ').replace('+=',' \n += ') + '\n\n '
+ def test_noWS(s):
+ assert len(s.parse(s.s1)) == 8
+ def test_noWS_COMMENT(s):
+ assert s.eqparse(s.s1+'#COMMENT') == s.eqparse(s.s1+'#') == s.eqparse(s.s1+'#\n') == s.eqparse(s.s1+'\n#')
+ def test_manyWS(s):
+ assert s.eqparse(s.s2) == s.eqparse(s.s1)
+ def test_manyWS_COMMENT(s):
+ assert s.eqparse(s.s2.replace('\n',' #COMMENT \n')) == s.eqparse(s.s2.replace('\n','#\n')) == s.eqparse(s.s1)
+ def test_empty(s):
+ assert s.eqparse('') == s.eqparse('\n') == s.eqparse('') == s.eqparse('a{}') == \
+ s.eqparse('a.b.c{if ""==\'\' {d.e{\n\n#Nothing\n}} }') == []
+ def test_syntax_errors(s):
+ s.assertRaises(ConfigSyntaxError, s.parse, "a=#")
+ s.assertRaises(ConfigSyntaxError, s.parse, "a='\"")
+ s.assertRaises(ConfigSyntaxError, s.parse, 'a="{a@b}"')
+ s.assertRaises(ConfigSyntaxError, s.parse, 'a="A{A"')
+ def test_error_location(s):
+ try: s.parse('\t \n \n { \n \n ')
+ except ConfigSyntaxError, e:
+ assert e.line == 3 and e.column in range(2,4)
+ def test_quoting(s):
+ s.parse(' a="\\"\\{a$b\\}\'\n\n\'{z}" ')
+ assert s.t.lookup('z', create=False)
+ # No escaping in '-string
+ s.assertRaises(ConfigSyntaxError, s.parse, " a='\"\\'\n\n' ")
+ # Variable should not be created
+ s.parse(" a='{z2}' ")
+ s.assertRaises(conf.ConfigError, s.t.lookup, 'z2', create=False)
+ def test_conditions(s):
+ s.assertRaises(ConfigSyntaxError, s.parse, "if '{a}'=='{b}' and ''!='' {}")
+ s.parse('if ((#C\n (\n (not not not""!="")\n#C\n)\t ) ) {}')
+ s.parse('if (""=="" and not (not not ""!="" or ""=="")){}')
+ s.parse('if(""==""){a{if(""==""){if(""==""){b{if(""==""){if(""==""){}}}}}}}')
+ s.assertRaises(ConfigSyntaxError, s.parse, "if notnot'{a}'=='{b}' {}")
+ s.assertRaises(ConfigSyntaxError, s.parse, "if ('{a}'=='{b}' not and ''!='') {}")
+ s.assertRaises(ConfigSyntaxError, s.parse, "if ('{a}'=='{b}' ornot ''!='') {}")