예제 #1
0
class AhTestContexts(unittest.TestCase):
    ourTests = [ [ "statement", ['\\;|', '\\;'] ], \
                 [ "'foo'",     ['\\;|', '\\;'] ] \
               ]

    def setUp(self):
        global test1file
        self.ah = Autohighlight(StringIO(test1file))
        self.ah.parse()

    def checkContext(self,number):
        sym = self.ourTests[number][0]
        res = self.ourTests[number][1:]
        context = self.ah.GlobalSymbolDict[sym].get_context(self.ah.GlobalSymbolDict)
        self.assertEqual(res, context, "Contexts for %s are not as expected:\n%s\n%s" % (sym,res,context))

    def test0(self):
        self.checkContext(0)
    def test1(self):
        self.checkContext(1)
예제 #2
0
 def setUp(self):
     global test1file
     self.ah = Autohighlight(StringIO(test1file))
     self.ah.parse()
예제 #3
0
 def setUp(self):
     global test1file
     self.ah = Autohighlight(StringIO(test1file))
     self.ah.parse()
     self.gsd=self.ah.GlobalSymbolDict
예제 #4
0
class AhTestContexts(unittest.TestCase):
    ourTests = [ [ "idUse", ['\\;|%^', '\\='], ['\\=', '\\;'], ['Print', '\\;'] ],\
                 [ "':'", ['[A-Za-z][-A-Za-z0-9_]*', '[A-Za-z][-A-Za-z0-9_]*'] ],\
                 [ "int", ['\\=', '\\;'], ['Print', '\\;'] ],\
                 [ "idDef", ['var', '\\:'] ],\
                 [ "typeUse", ['\\:', '\\;'] ],\
                 [ "expr", ['\\=', '\\;'], ['Print', '\\;'] ],\
                 [ "';'", ['[A-Za-z][-A-Za-z0-9_]*|[0-9]+|[A-Za-z][-A-Za-z0-9_]*|[A-Za-z][-A-Za-z0-9_]*|[0-9]+', '[A-Za-z][-A-Za-z0-9_]*|var|Print|%$'] ],\
                 [ "'Print'", ['\\;|%^', '[A-Za-z][-A-Za-z0-9_]*|[0-9]+'] ],\
                 [ "'='", ['[A-Za-z][-A-Za-z0-9_]*', '[A-Za-z][-A-Za-z0-9_]*|[0-9]+'] ],\
                 [ "id", ['\\;|%^', '\\='], ['\\=', '\\;'], ['Print', '\\;'], ['var', '\\:'], ['\\:', '\\;'] ],\
                 [ "'var'", ['\\;|%^', '[A-Za-z][-A-Za-z0-9_]*'] ] ]

    def setUp(self):
        global test1file
        self.ah = Autohighlight(StringIO(test1file))
        self.ah.parse()
        self.gsd=self.ah.GlobalSymbolDict

    def checkContext(self,number):
        sym = self.ourTests[number][0]
        expected = []
        for context in self.ourTests[number][1:]:
            setted_context = []
            for regex in context:
                setted_context += [ Set(regex.split("|")) ]
            expected += [setted_context]
        contexts = self.ah.GlobalSymbolDict[sym].get_contexts(self.ah.GlobalSymbolDict)
        res = [ [context.getLeftRegexes(), context.getRightRegexes()] for context in contexts ]
        self.assertEqual(res, expected, "Contexts for %s are not as expected:\n%s\n%s" % (sym,res,expected))

    def test0(self):
        self.checkContext(0)
    def test1(self):
        self.checkContext(1)
    def test2(self):
        self.checkContext(2)
    def test3(self):
        self.checkContext(3)
    def test4(self):
        self.checkContext(4)
    def test5(self):
        self.checkContext(5)
    def test6(self):
        self.checkContext(6)
    def test7(self):
        self.checkContext(7)
    def test8(self):
        self.checkContext(8)
    def test9(self):
        self.checkContext(9)
    def test10(self):
        self.checkContext(10)

    def testContextOfSemicolon(self):
        sym = self.gsd["';'"]
        res = sym.get_contexts(self.ah.GlobalSymbolDict)
        expected = [Context(Set(self.gsd["statement"]), sym, Set(self.gsd["statement"],self.gsd['%$']) )]
        self.assertEqual(res, expected, "Contexts for %s are not as expected:\n%s\n%s" % (sym,res,expected))

    def testIsRoot(self):
        roots = []
        for symbol in self.gsd.values():
            if symbol.isRoot():
                roots += [symbol]
        self.assertEqual(len(roots),1,"Multiple roots found: %s"%roots)