Esempio n. 1
0
    def test_insert_before(self):
        a   = self.node_from_expr("a = 1")
        b   = self.node_from_expr("b = 2")
        c   = self.node_from_expr("c = 3")
        
        # empty
        nlst= NodeList.empty()
        nlst.insert_before(iter(nlst), a)
        self.assertEqual(1, len(nlst))
        self.assertEqual(a, nlst[0])
        
        # filled
        it = iter(nlst)
        it.__next__()
        nlst.insert_before(it, b)
        self.assertEqual(2, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(b, nlst[1])

        # in the middle
        it = iter(nlst)
        it.__next__()
        nlst.insert_before(it, c)
        self.assertEqual(3, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(c, nlst[1])
        self.assertEqual(b, nlst[2])
Esempio n. 2
0
    def test_insert_before(self):
        a   = self.node_from_expr("a = 1")
        b   = self.node_from_expr("b = 2")
        c   = self.node_from_expr("c = 3")
        
        # empty
        nlst= NodeList.empty()
        nlst.insert_before(iter(nlst), a)
        self.assertEqual(1, len(nlst))
        self.assertEqual(a, nlst[0])
        
        # filled
        it = iter(nlst)
        it.__next__()
        nlst.insert_before(it, b)
        self.assertEqual(2, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(b, nlst[1])

        # in the middle
        it = iter(nlst)
        it.__next__()
        nlst.insert_before(it, c)
        self.assertEqual(3, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(c, nlst[1])
        self.assertEqual(b, nlst[2])
Esempio n. 3
0
 def test_insert_after(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     
     # empty
     nlst= NodeList.empty()
     with self.assertRaises(ValueError):
         nlst.insert_after(iter(nlst), a)
     
     # filled
     nlst.append(a)
     it = iter(nlst)
     nlst.insert_after(it, b)
     self.assertEqual(2, len(nlst))
     self.assertEqual(a, nlst[0])
     self.assertEqual(b, nlst[1])
     
     # at end
     it = iter(nlst)
     it.__next__()
     nlst.insert_after(it, c)
     self.assertEqual(3, len(nlst))
     self.assertEqual(a, nlst[0])
     self.assertEqual(b, nlst[1])
     self.assertEqual(c, nlst[2])
Esempio n. 4
0
 def test_insert_after(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     
     # empty
     nlst= NodeList.empty()
     with self.assertRaises(ValueError):
         nlst.insert_after(iter(nlst), a)
     
     # filled
     nlst.append(a)
     it = iter(nlst)
     nlst.insert_after(it, b)
     self.assertEqual(2, len(nlst))
     self.assertEqual(a, nlst[0])
     self.assertEqual(b, nlst[1])
     
     # at end
     it = iter(nlst)
     it.__next__()
     nlst.insert_after(it, c)
     self.assertEqual(3, len(nlst))
     self.assertEqual(a, nlst[0])
     self.assertEqual(b, nlst[1])
     self.assertEqual(c, nlst[2])
Esempio n. 5
0
 def test_length(self):
     nlst= NodeList.empty()
     self.assertEqual(0, len(nlst))
      
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, b, c])
     self.assertEqual(3, len(nlst))
Esempio n. 6
0
 def test_length(self):
     nlst= NodeList.empty()
     self.assertEqual(0, len(nlst))
      
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, b, c])
     self.assertEqual(3, len(nlst))
Esempio n. 7
0
 def test_getitem(self):
     a   = self.node_from_expr("a = 1")
     lst = NodeList.empty()
     try: 
         lst[0]
     except KeyError:
         self.assertTrue(True)
           
     lst.append(a)
     self.assertEqual(a, lst[0])
Esempio n. 8
0
 def test_getitem(self):
     a   = self.node_from_expr("a = 1")
     lst = NodeList.empty()
     try: 
         lst[0]
     except KeyError:
         self.assertTrue(True)
           
     lst.append(a)
     self.assertEqual(a, lst[0])
Esempio n. 9
0
 def test_iter_string(self):
     nlst = NodeList.empty()
     a = self.node_from_expr("a = 1")
     b = self.node_from_expr("b = 2")
     c = self.node_from_expr("c = 3")
     nlst.append(a)
     nlst.append(b)
     nlst.append(c) 
     
     it = iter(nlst)
     self.assertEqual(str(it), "NodeListIter[a = 1, b = 2, c = 3]")
Esempio n. 10
0
 def test_copy(self):
     a = self.node_from_expr("a = 12")
     
     nlst= NodeList.empty()
     cpy = nlst.copy()
     
     self.assertTrue(a not in cpy)
     
     nlst.append(a)
     cpy = nlst.copy()
     
     self.assertTrue(a in cpy)
Esempio n. 11
0
 def test_copy(self):
     a = self.node_from_expr("a = 12")
     
     nlst= NodeList.empty()
     cpy = nlst.copy()
     
     self.assertTrue(a not in cpy)
     
     nlst.append(a)
     cpy = nlst.copy()
     
     self.assertTrue(a in cpy)
Esempio n. 12
0
 def test_iter(self):    
     nlst= NodeList.empty()
     a = self.node_from_expr("a = 1")
     b = self.node_from_expr("b = 2")
     c = self.node_from_expr("c = 3")
     nlst.append(a)
     nlst.append(b)
     nlst.append(c) 
     
     lst = [a,b,c]
     out = []
     for v in nlst:
         out.append(v)
         
     self.assertListEqual(out, lst)
Esempio n. 13
0
 def test_iter(self):
     nlst= NodeList.empty()
     a = self.node_from_expr("a = 1")
     b = self.node_from_expr("b = 2")
     c = self.node_from_expr("c = 3")
     nlst.append(a)
     nlst.append(b)
     nlst.append(c) 
     
     lst = [a,b,c]
     out = []
     for v in nlst:
         out.append(v)
         
     self.assertListEqual(out, lst)
Esempio n. 14
0
 def test_append(self):
     nlst= NodeList.empty()
      
     # append on empty works
     a = self.node_from_expr("a = 12")
     self.assertTrue(a not in nlst)
     nlst.append(a)
     self.assertTrue(a in nlst)
     self.assertEqual(a, nlst[0])
      
     # append on non empty works
     b = self.node_from_expr("b = 23")
     self.assertTrue(b not in nlst)
     nlst.append(b)
     self.assertTrue(b in nlst)
     self.assertEqual(b, nlst[1])
Esempio n. 15
0
 def test_append(self):
     nlst= NodeList.empty()
      
     # append on empty works
     a = self.node_from_expr("a = 12")
     self.assertTrue(a not in nlst)
     nlst.append(a)
     self.assertTrue(a in nlst)
     self.assertEqual(a, nlst[0])
      
     # append on non empty works
     b = self.node_from_expr("b = 23")
     self.assertTrue(b not in nlst)
     nlst.append(b)
     self.assertTrue(b in nlst)
     self.assertEqual(b, nlst[1])
Esempio n. 16
0
    def test_insert_at(self):
        a   = self.node_from_expr("a = 1")
        b   = self.node_from_expr("b = 2")
        c   = self.node_from_expr("c = 3")
        
        # empty
        nlst= NodeList.empty()
        nlst.insert_at(0, a)
        self.assertEqual(1, len(nlst))
        self.assertEqual(a, nlst[0])
        
        # filled
        nlst.insert_at(1, b)
        self.assertEqual(2, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(b, nlst[1])

        # in the middle
        nlst.insert_at(1, c)
        self.assertEqual(3, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(c, nlst[1])
        self.assertEqual(b, nlst[2])
Esempio n. 17
0
    def test_insert_at(self):
        a   = self.node_from_expr("a = 1")
        b   = self.node_from_expr("b = 2")
        c   = self.node_from_expr("c = 3")
        
        # empty
        nlst= NodeList.empty()
        nlst.insert_at(0, a)
        self.assertEqual(1, len(nlst))
        self.assertEqual(a, nlst[0])
        
        # filled
        nlst.insert_at(1, b)
        self.assertEqual(2, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(b, nlst[1])

        # in the middle
        nlst.insert_at(1, c)
        self.assertEqual(3, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(c, nlst[1])
        self.assertEqual(b, nlst[2])
Esempio n. 18
0
 def test_empty(self):
     lst = NodeList.empty()
     self.assertEqual(len(lst), 0, "lst should be empty")
Esempio n. 19
0
 def test_empty(self):
     lst = NodeList.empty()
     self.assertEqual(len(lst), 0, "lst should be empty")
Esempio n. 20
0
 def test_contains(self):
     a   = self.node_from_expr("a = 1")
     nlst= NodeList.empty()
     self.assertTrue(a not in nlst)
     nlst.append(a)
     self.assertTrue(a in nlst)
Esempio n. 21
0
 def test_contains(self):
     a   = self.node_from_expr("a = 1")
     nlst= NodeList.empty()
     self.assertTrue(a not in nlst)
     nlst.append(a)
     self.assertTrue(a in nlst)