Ejemplo n.º 1
0
 def test(self):
     raw_code = ("result == 'false'", "this is not 'supported'")
     tree = Parser.parse("\n".join(raw_code))
     compiler = DfsCompiler()
     tokens = compiler.accept(tree)
     Decompiler.dfs(tokens)
     Validator().accept(tree)
Ejemplo n.º 2
0
 def test(self):
     raw_code = ("  strong param[0] != 'null'", "  weak param[1] != 'null'",
                 "  strong result != 'null'",
                 "  strong 'The bucket is reset' == true",
                 "  strong 'The bucket must not be shared' == true",
                 "  strong 'parsing is not supported' == false",
                 "  strong 'the text to parse is invalid' == false")
     raw_tokens = ("root", "strong", "!=", "param[0]", "'null'", "weak",
                   "!=", "param[1]", "'null'", "strong", "!=", "result",
                   "'null'", "strong", "==", "'The bucket is reset'",
                   "true", "strong", "==",
                   "'The bucket must not be shared'", "true", "strong",
                   "==", "'parsing is not supported'", "false", "strong",
                   "==", "'the text to parse is invalid'", "false")
     raw_tree = "root(" \
                "strong(!=(param[0],'null'))," \
                "weak(!=(param[1],'null'))," \
                "strong(!=(result,'null'))," \
                "strong(==('The bucket is reset',true))," \
                "strong(==('The bucket must not be shared',true))," \
                "strong(==('parsing is not supported',false))," \
                "strong(==('the text to parse is invalid',false)))"
     tree = Parser.parse("\n".join(raw_code))
     compiler = DfsCompiler()
     tokens = compiler.accept(tree)
     assert len(tokens) == len(raw_tokens)
     assert all(raw_token == token.name
                for token, raw_token in zip(tokens, raw_tokens))
     assert str(tree) == raw_tree
     yet_another_tree = Decompiler.dfs(Decompiler.typing(raw_tokens))
     Validator().accept(yet_another_tree)
     assert str(yet_another_tree) == str(tree)
     assert yet_another_tree == tree
Ejemplo n.º 3
0
 def test(self):
     raw_code = ("  strong param[0] != 'null'",
                 "  weak param[1] != 'null'",
                 "  strong result != 'null'",
                 "  strong 'The bucket is reset' == true",
                 "  strong 'The bucket must not be shared' == true",
                 "  strong 'parsing is not supported' == false",
                 "  strong 'the text to parse is invalid' == false")
     raw_tree = "root(" \
                "strong(!=(param[0],'begin null end'))," \
                "weak(!=(param[1],'begin null end'))," \
                "strong(!=(result,'begin null end'))," \
                "strong(==('begin The bucket is reset end',true))," \
                "strong(==('begin The bucket must not be shared end',true))," \
                "strong(==('begin parsing is not supported end',false))," \
                "strong(==('begin the text to parse is invalid end',false)))"
     tree = Parser.parse("\n".join(raw_code))
     compiler = DfsCompiler()
     tokens = compiler.accept(tree)
     tree = Decompiler.dfs(tokens)
     Validator().accept(tree)
     filtrator = StringFiltrator()
     filtrator.accept(tree)
     Validator().accept(tree)
     assert str(tree) == raw_tree
Ejemplo n.º 4
0
 def test(self):
     raw_code = "strong 'field' is 'supported' strong 'field' is not 'supported'"
     raw_tree = "root(strong(is('field','supported')),strong(is not('field','supported')))"
     tree = Parser.parse(raw_code)
     compiler = DfsCompiler()
     tokens = compiler.accept(tree)
     tree = Decompiler.dfs(tokens)
     Validator().accept(tree)
     assert str(tree) == raw_tree
Ejemplo n.º 5
0
 def test(self):
     raw_code = " strong param[0] == 'null' => \"in default zone\""
     raw_tree = "root(strong(=>(==(param[0],'null'),\"in default zone\")))"
     tree = Parser.parse(raw_code)
     compiler = DfsCompiler()
     tokens = compiler.accept(tree)
     tree = Decompiler.dfs(tokens)
     Validator().accept(tree)
     assert str(tree) == raw_tree
Ejemplo n.º 6
0
 def test(self):
     raw_code = "param[0] == false => param[0] != 'null'"
     raw_tokens = ("root", "strong", "=>", "==", "!=", "param[0]", "false", "param[0]", "'null'")
     tree = Parser.parse(raw_code)
     compiler = DfsCompiler()
     tokens = compiler.accept(tree)
     tree = Decompiler.dfs(tokens)
     Validator().accept(tree)
     compiler = BfsCompiler()
     tokens = compiler.accept(tree)
     assert len(tokens) == len(raw_tokens)
     assert all(token.name == raw_token for token, raw_token in zip(tokens, raw_tokens))
Ejemplo n.º 7
0
 def test(self):
     raw_code = ("  strong param[0] != 'null'", "  weak param[1] != 'null'",
                 "  strong result != 'null'",
                 "  strong 'The bucket is reset' == true",
                 "  strong 'The bucket must not be shared' == true",
                 "  strong 'parsing is not supported' == false",
                 "  strong 'the text to parse is invalid' == false")
     tree = Parser.parse("\n".join(raw_code))
     compiler = DfsCompiler()
     tokens = compiler.accept(tree)
     tree = Decompiler.dfs(tokens)
     Validator().accept(tree)
     code = Shower().accept(tree)
     assert "\n".join(code) == "\n".join(string.strip()
                                         for string in raw_code)
Ejemplo n.º 8
0
 def test(self):
     raw_code = (
         "param[0] != 'null'", "`param[1] == 'null'",
         "param[1] == 'null' => 'default zone'", "param[0] != 'null'",
         "`result != 'null'", "`param[0] == 'negative'",
         "param[0] != 'null'", "param[1] != 'null'", "param[2] != 'null'",
         "param[3] == 'null' => param[3] == 'ISOChronology in default zone'",
         "`param[3] == 'null'",
         "param[0] is 'valid values defined by the chronology'",
         "param[1] is 'valid values defined by the chronology'",
         "param[2] is 'valid values defined by the chronology'",
         "param[0] is 'the year'", "param[1] is 'the month of the year'",
         "param[2] is 'the day of the month'",
         "param[3] is 'the chronology'")
     tree = Parser.parse("\n".join(raw_code))
     compiler = DfsCompiler()
     tokens = compiler.accept(tree)
     Decompiler.dfs(tokens)
     Validator().accept(tree)