예제 #1
0
 def push(self, scope=None):
     if scope is None:
         scope = Scope()
     if type(scope) is Scope:
         self.table.append(scope)
     else:
         raise TypeError("'scope' is not an instance of Scope.")
예제 #2
0
 def setUp(self):
     self.scope = Scope()
예제 #3
0
 def setUp(self):
     self.scope = Scope()
예제 #4
0
class TestScope(unittest.TestCase):
    def setUp(self):
        self.scope = Scope()

    def tearDown(self):
        self.scope = None

    def test_insert(self):
        self.assertEqual(Scope.INSERT_SUCCESS,
                         self.scope.insert(Symbol('A', 0, 0)))
        self.assertEqual(Scope.INSERT_REDECL,
                         self.scope.insert(Symbol('A', 0, 0)))
        self.assertEqual(Scope.INSERT_SUCCESS,
                         self.scope.insert(Symbol('B', 0, 0)))

    def test_find(self):
        self.scope.insert(Symbol('A', 0, 0))
        found = self.scope.find('A')
        self.assertTrue(found is not None)
        self.assertTrue(found.identifier is 'A')
        self.assertTrue(type(found) is Symbol)

    def test_size(self):
        self.assertEqual(0, self.scope.size())
        self.scope.insert(Symbol('A', 0, 0))
        self.assertEqual(1, self.scope.size())

    def test_clone(self):
        self.scope.insert(Symbol('A', 0, 0))
        self.scope.insert(Symbol('B', 0, 0))

        clone = self.scope.clone()
        self.assertTrue(self.scope.find('A') is not clone.find('A'))
        self.assertTrue(self.scope.find('B') is not clone.find('B'))
예제 #5
0
class TestScope(unittest.TestCase):
    def setUp(self):
        self.scope = Scope()

    def tearDown(self):
        self.scope = None

    def test_insert(self):
        self.assertEqual(Scope.INSERT_SUCCESS, self.scope.insert(Symbol('A', 0, 0)))
        self.assertEqual(Scope.INSERT_REDECL, self.scope.insert(Symbol('A', 0, 0)))
        self.assertEqual(Scope.INSERT_SUCCESS, self.scope.insert(Symbol('B', 0, 0)))

    def test_find(self):
        self.scope.insert(Symbol('A', 0, 0))
        found = self.scope.find('A')
        self.assertTrue(found is not None)
        self.assertTrue(found.identifier is 'A')
        self.assertTrue(type(found) is Symbol)

    def test_size(self):
        self.assertEqual(0, self.scope.size())
        self.scope.insert(Symbol('A', 0, 0))
        self.assertEqual(1, self.scope.size())

    def test_clone(self):
        self.scope.insert(Symbol('A', 0, 0))
        self.scope.insert(Symbol('B', 0, 0))

        clone = self.scope.clone()
        self.assertTrue(self.scope.find('A') is not clone.find('A'))
        self.assertTrue(self.scope.find('B') is not clone.find('B'))