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'))
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_diff_scope(self): self.sym.insert(Symbol('A', 0, 0)) self.sym.push() self.sym.insert(Symbol('B', 0, 0)) found, in_scope = self.sym.find('A') self.assertTrue(found is not None) self.assertTrue(found.identifier is 'A') self.assertTrue(type(found) is Symbol)
def test_symbol_table_clone(self): self.sym.insert(Symbol('A', 0, 0)) self.sym.push() self.sym.insert(Symbol('B', 0, 0)) clone = self.sym.clone() self.assertTrue(self.sym.size() == clone.size()) self.assertTrue(self.sym.find('A')[0] is not clone.find('A')[0]) self.assertTrue(self.sym.find('B')[0] is not clone.find('B')[0]) self.sym.pop() self.assertTrue(self.sym.size() == clone.size() - 1) self.assertTrue( self.sym.find('B')[0] is None and clone.find('B')[0] is not None)
def test_find_same_scope(self): self.assertTrue( self.sym.insert(Symbol('A', 0, 0))[0] == Scope.INSERT_SUCCESS) found, in_scope = self.sym.find('A') self.assertTrue(found is not None) self.assertTrue(found.identifier is 'A') self.assertTrue(type(found) is Symbol)
def test_insert(self): self.assertTrue( self.sym.insert(Symbol('A', 0, 0))[0] == Scope.INSERT_SUCCESS) self.assertTrue( self.sym.insert(Symbol('B', 0, 0))[0] == Scope.INSERT_SUCCESS) self.sym.push() self.assertTrue( self.sym.insert(Symbol('A', 0, 0))[0] == Scope.INSERT_SHADOWED) self.assertTrue( self.sym.insert(Symbol('B', 0, 0))[0] == Scope.INSERT_SHADOWED) self.assertTrue( self.sym.insert(Symbol('A', 0, 0))[0] == Scope.INSERT_REDECL) self.assertTrue( self.sym.insert(Symbol('B', 0, 0))[0] == Scope.INSERT_REDECL)
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_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)