예제 #1
0
 def test_alter_skip(self):
     
     var = Constructor.variable("name")
     var2 = Constructor.variable("name2")
     var_or_text = Constructor.alter(True, var, var2)
     self.assertEqual("", var_or_text.build())
     self.assertEqual("test", var_or_text.build(Context({"name2":"test"})))
예제 #2
0
 def test_alter_noskip(self):
     
     text = Constructor.text("test")
     var = Constructor.variable("name")
     var2 = Constructor.variable("name2")
     var_or_text = Constructor.alter(False, var, var2, text)
     
     res = var_or_text.build()
     self.assertEqual(res, "test")
     
     res = var_or_text.build(Context({"name":"}{}{}{"}))
     self.assertEqual(res, "}{}{}{")
     
     var_or_text = Constructor.alter(False, var, var2)
     self.assertRaises(BuildError, var_or_text.build)
     self.assertEqual("test", var_or_text.build(Context({"name2":"test"})))
예제 #3
0
 def test_value(self):
     
     constr = Constructor.text("test")
     constr2 = Constructor.variable("name")
     add = constr + constr2
     res = add.build(Context({"name":"test"}))
     self.assertEqual(res, "test test")
예제 #4
0
    def test_cycle(self):
        
        ref = (Constructor.variable("var") + Constructor.text("test")).define("refname", "level")
        sep = Constructor.text(";")
        cycle = Constructor.cycle(ref, sep)
        
        level = [
            Context({"var":"test1"}),
            Context({"var":"test2"}),
            Context({"var":"test3"}),
            Context({"var":"test4"}),
            Context({"var":"test5"}),
        ]
        
        res = cycle.build(Context({"level":level}))
        self.assertEqual(res, "test1 test ; test2 test ; test3 test ; test4 test ; test5 test")
        
        level = [
            Context({"var":"test1"}),
            Context(),
        ]

        self.assertRaises(BuildError, cycle.build, Context({"level":level}))