コード例 #1
0
ファイル: testparser.py プロジェクト: hermetique/dao
 def testoptionalcut(self):
     x, s = Var('x'), Var('s')
     ruleList = [(s, function(((x, ), and_p(-char('a'), cut, char(x)))))]
     eq_(eval(let(ruleList, parse_text(s(x), 'aa'), x)), 'a')
     eq_(eval(let(ruleList, parse_text(s(x), 'b'), x)), 'b')
     assert_raises(NoSolution, eval, let(ruleList, parse_text(s(x), 'a'),
                                         x))
コード例 #2
0
 def test2(self):
     x = Var('x')
     Lx = LogicVar('x')
     eq_(eval(unify(1, 1)), True)
     eq_(eval(begin(unify(1, 1), unify(2, 2))), True)
     eq_(eval(begin(unify(Lx, 1), unify(Lx, 1))), True)
     eq_(eval(let([(x, 1)], unify(x, 1))), True)
コード例 #3
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testLoopWhen(self):
     eq_(
         eval(
             tag_loop_label(
                 let([(i, 3)],
                     LoopWhenForm((set(i, sub(i, 1)), prin(i)),
                                  gt(i, 0))))), None)
コード例 #4
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testLoopUntil(self):
     eq_(
         eval(
             tag_loop_label(
                 let([(i, 3)],
                     LoopUntilForm((set(i, sub(i, 1)), prin(i)),
                                   eq(i, 0))))), None)
コード例 #5
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test2(self):
   x = Var('x')
   Lx = LogicVar('x')
   eq_(eval(unify(1, 1)), True)
   eq_(eval(begin(unify(1, 1), unify(2, 2))), True)
   eq_(eval(begin(unify(Lx, 1), unify(Lx,1))), True)
   eq_(eval(let([(x,1)], unify(x,1))), True)
コード例 #6
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def test_unwind_protect_loop(self):
   from util import a, i
   eq_(eval(let([(i,3)], 
                block(a, assign(i, sub(i, 1)), 
                         if_(eq(i, 0), 
                           exit_block(a, 1),
                           unwind_protect(continue_block(a), prin(i)))), i)), 0)
コード例 #7
0
 def test_findall_template_func(self):
     x, y, z = LogicVar('x'), LogicVar('y'), LogicVar('z')
     f = Var('f')
     eq_(
         eval(
             let([(f, rules(((), 2), ((), 3)))], findall(is_(x, f()), x, y),
                 getvalue(y))), [2, 3])
コード例 #8
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testLoopTimes(self):
     eq_(
         eval(
             tag_loop_label(
                 let([(i, 3)],
                     LoopTimesForm(3, (set(i, sub(i, 1)), prin(i)))))),
         None)
コード例 #9
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def testloop(self):
   from util import a, i
   eq_(eval(let([(i,3)], 
                block(a, assign(i, sub(i, 1)), 
                         if_(eq(i, 0), 
                             exit_block(a, 1), 
                             continue_block(a))), 
                i)), 0)
コード例 #10
0
 def test_open_read2(self):
     file1 = Var('file1')
     x = Var('x')
     eq_(
         eval(
             let([(file1, open_file('test.txt'))], readline(file1),
                 assign(x, readlines(file1)), close_file(file1), x)),
         ['hello'])
コード例 #11
0
ファイル: testparser.py プロジェクト: hermetique/dao
 def test_kleene2(self):
     f, kleene = MacroVar('f'), MacroVar('kleene')
     _ = DummyVar('_')
     item = Var('item')
     fun = macro((item, ),
                 letrec([(f, macrorules(((), item, f()), ((), nullword)))],
                        f()))
     eq_(eval(let([(kleene, fun)], set_text('ab'), kleene(char(_)))), True)
コード例 #12
0
ファイル: testparser.py プロジェクト: hermetique/dao
 def test_chars(self):
     x, cs, chars = LogicVar('x'), Var('cs'), MacroVar('chars')
     x1 = Var('x')
     eq_(
         eval(
             let([(chars, lamda(
                 (x1, cs), begin(char(x1), contain(cs, x1))))],
                 parse_text(chars(x, 'a'), 'a'), getvalue(x))), 'a')
コード例 #13
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testloop(self):
     from util import a, i
     eq_(
         eval(
             let([(i, 3)],
                 block(a, assign(i, sub(i, 1)),
                       if_(eq(i, 0), exit_block(a, 1), continue_block(a))),
                 i)), 0)
コード例 #14
0
ファイル: testparser.py プロジェクト: chaosim/dao
 def test_kleene1(self):
   f, kleene = MacroVar('f'), MacroVar('kleene')
   item = Var('item')
   fun = macro((item,),  
           letrec([(f, macrorules(
             ((), item, f()),
             ((), nullword)))], 
                f()))
   eq_(eval(let([(kleene, fun)], set_text('aa'), kleene(char('a')))), True)
コード例 #15
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test_open_read2(self):
   file1 = Var('file1')
   x = Var('x')
   eq_(eval(let([(file1, open_file('test.txt'))], 
                readline(file1), 
                assign(x, readlines(file1)), 
                close_file(file1), 
                x)), 
       ['hello'])
コード例 #16
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testblock(self):
     f = Var('f')
     foo = Var('foo')
     eq_(
         eval(
             block(
                 foo,
                 let([(f, lamda((), exit_block(foo, 1)))],
                     mul(2, block(foo, f()))))), 1)
コード例 #17
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test_unwind_protect_loop(self):
     from util import a, i
     eq_(
         eval(
             let([(i, 3)],
                 block(
                     a, assign(i, sub(i, 1)),
                     if_(eq(i, 0), exit_block(a, 1),
                         unwind_protect(continue_block(a), prin(i)))), i)),
         0)
コード例 #18
0
ファイル: testparser.py プロジェクト: chaosim/dao
 def test_chars(self):
   x, cs, chars = LogicVar('x'), Var('cs'), MacroVar('chars')
   x1 = Var('x')
   eq_(eval(let([(chars, lamda((x1, cs), begin(char(x1), contain(cs, x1))))],
                           parse_text(chars(x, 'a'), 'a'), getvalue(x))), 'a')
コード例 #19
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def testeval3(self):
   x = Const('x')
   eq_(eval(let([(x, quote(1))], eval_(x))), 1)
コード例 #20
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testeval3(self):
     x = Const('x')
     eq_(eval(let([(x, quote(1))], eval_(x))), 1)
コード例 #21
0
ファイル: testparser.py プロジェクト: chaosim/dao
 def test_nongreedy_optional(self):
   x, s = Var('x'), Var('s')
   ruleList =[(s, function( ((x,), and_p(-char('a'),char(x)))))]
   eq_(eval(let(ruleList, parse_text(s(x), 'a'), x)), 'a')
   eq_(eval(let(ruleList, parse_text(s(x),  'aa'), x)), 'a')         
   eq_(eval(let(ruleList, parse_text(s(x),  'b'), x)), 'b')
コード例 #22
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test_embeded_module(self):
     a, m1, m2 = Var('a'), Var('m1'), Var('m2')
     eq_(
         eval(
             let([(m1, module(define(a, 1), define(m2, module(define(
                 a, 2)))))], from_(from_(m1, m2), a))), 2)
コード例 #23
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test_let_assign_const(self):
     a = Const('a')
     assert_raises(MultiAssignToConstError, eval, let([(a, 2)],
                                                      assign(a, 3)))
コード例 #24
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test_replace(self):
   from dao.builtins.rule import replace
   eq_(eval(let([(f,function(([1], 1), ([2], 2)))], 
              replace(f, [2], [3]), f(2))), 3)
コード例 #25
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def test_closure2(self):
   x, f = Const('x'), Const('f')
   eq_(eval(let([(f, macrorules([[x], x])),
                 (x, 1)],
            f(add(x,x)))), 2)
コード例 #26
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testletdouble1(self):
     x, f = Var('x'), MacroVar('f')
     eq_(eval(let([(f, macro([x], add(x, x)))], f(1))), 2)
コード例 #27
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testletdouble2(self):
     x, f = Const('x'), ConstMacroVar('f')
     eq_(eval(let([(f, macro([x], add(x, x)))], f(1))), 2)
コード例 #28
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test_macro5(self):
     x, y, f = Const('x'), Const('y'), MacroVar('f')
     eq_(eval(let([(f, macro((x, y), y, x, 1))], f(println(1), prin(2)))),
         1)
コード例 #29
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def test_let_in_module(self):
   a, m1, m2 = Var('a'), Var('m1'), Var('m2')
   eq_(eval(let([(m1,module(define(a,1), let([(a,2)], define(a,3))))], 
              from_(m1,a))), 1) 
コード例 #30
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def test_let_assign_const(self):
   a = Const('a')
   assert_raises(MultiAssignToConstError, eval, 
                 let([(a,2)], assign(a, 3)))
コード例 #31
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test_findall_template_func(self):
   x, y, z = LogicVar('x'), LogicVar('y'), LogicVar('z')
   f = Var('f')
   eq_(eval(let([(f, rules(((), 2), ((), 3)))], 
              findall(is_(x, f()), x, y), getvalue(y))), [2, 3])
コード例 #32
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test_closure3(self):
     x, y, f = Const('x'), Const('y'), Const('f')
     eq_(
         eval(
             let([(f, macrorules([[x, y], begin(x, y)])), (x, 1)],
                 f(prin(x), prin(add(x, x))))), None)
コード例 #33
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test_fail(self):
   x = Var('x')
   x1 = LogicVar('x')
   eq_(eval(let([(f,rules([[1], fail], [[x], succeed]))], f(x1))), True)
コード例 #34
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def testeval4(self):
   x = Const('x')
   eq_(eval(let([(x, quote(add(1,1)))], eval_(x))), 2)
コード例 #35
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def testfrom(self):
   a, m = Var('a'), Var('m')
   eq_(eval(let([(m,module(define(a,1)))], from_(m,a))), 1)
コード例 #36
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def test_embeded_module(self):
   a, m1, m2 = Var('a'), Var('m1'), Var('m2')
   eq_(eval(let([(m1,module(define(a,1),define(m2, module(define(a,2)))))], 
              from_(from_(m1,m2),a))), 2) 
コード例 #37
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testfrom(self):
     a, m = Var('a'), Var('m')
     eq_(eval(let([(m, module(define(a, 1)))], from_(m, a))), 1)
コード例 #38
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testdouble4(self):
     f = Var('f')
     x = Var('x')
     eq_(eval(let([(f, rules([[x], add(x, x)]))], f(f(1)))), 4)
コード例 #39
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test_let_in_module(self):
     a, m1, m2 = Var('a'), Var('m1'), Var('m2')
     eq_(
         eval(
             let([(m1, module(define(a, 1), let([(a, 2)], define(a, 3))))],
                 from_(m1, a))), 1)
コード例 #40
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testdouble5(self):
     f = Var('f')
     x = Var('x')
     assert_raises(TypeError, eval,
                   let([(f, rules([[x], add(x, x)]))], f(1, 2)))  # passed
コード例 #41
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testeval2(self):
     x = Const('x')
     eq_(eval(let([(x, 1)], eval_(quote(x)))), 1)
コード例 #42
0
ファイル: testcpsconvert.py プロジェクト: chaosim/dao
 def test_let(self):
   x, y, k = il.Var('x'), il.Var('y'), il.Var('k')
   result = cps(let(((x,1),), x))
   expect = il.Clamda(x, done()(x))(1)
   eq_(result, expect)
コード例 #43
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def testeval4(self):
     x = Const('x')
     eq_(eval(let([(x, quote(add(1, 1)))], eval_(x))), 2)
コード例 #44
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test_open_read(self):
   file1 = Var('file1')
   eq_(eval(let([(file1, open_file('test.txt'))], 
                assign(x, read(file1)), 
                close_file(file1),
                x)), 'hello\nhello')
コード例 #45
0
ファイル: testparser.py プロジェクト: chaosim/dao
 def testoptionalcut(self):
   x, s = Var('x'), Var('s')
   ruleList = [(s, function( ((x,), and_p(-char('a'), cut, char(x)))))]
   eq_(eval(let(ruleList, parse_text(s(x),  'aa'), x)), 'a')         
   eq_(eval(let(ruleList, parse_text(s(x),  'b'), x)), 'b') 
   assert_raises(NoSolution, eval, let(ruleList, parse_text(s(x), 'a'), x))
コード例 #46
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test_write(self):
   file1 = Var('file1')
   eq_(eval(let([(file1, open_file('test2.txt', 'w'))], 
                write(file1, 'test'), close_file(file1))), None)
コード例 #47
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test_let_embed_var2(self):
     e, f = LogicVar('e'), Var('f')
     eq_(eval(let([(f, rules([[1], 1]))], f(e), getvalue(e))), 1)
コード例 #48
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def testeval2(self):
   x = Const('x')
   eq_(eval(let([(x,1)], eval_(quote(x)))), 1)
コード例 #49
0
ファイル: testcpsconvert.py プロジェクト: hermetique/dao
 def test_let(self):
     x, y, k = il.Var('x'), il.Var('y'), il.Var('k')
     result = cps(let(((x, 1), ), x))
     expect = il.Clamda(x, done()(x))(1)
     eq_(result, expect)
コード例 #50
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def test_closure1(self):
   x, f = Const('x'), Const('f')
   eq_(eval(let([(f, macrorules([[x], prin(x)])),
                 (x, 1)],
            f(add(x,x)))), None) 
コード例 #51
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def test5(self):
   x = Var('x')
   y = Var('y')
   eq_(eval(let([(y, 1)], macrorules([[x], prin(x)])(add(y, 1)))), None) 
コード例 #52
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def testLoopUntil(self):
   eq_(eval(tag_loop_label(let([(i,3)], LoopUntilForm((set(i, sub(i, 1)), prin(i)), 
                                    eq(i,0))))), None)
コード例 #53
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def testLoopWhen(self):
   eq_(eval(tag_loop_label(let([(i,3)], LoopWhenForm((set(i, sub(i, 1)), prin(i)), 
                                    gt(i,0))))), None)
コード例 #54
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test5(self):
     x = Var('x')
     y = Var('y')
     eq_(eval(let([(y, 1)], macrorules([[x], prin(x)])(add(y, 1)))), None)
コード例 #55
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test_abolish(self):
   from dao.builtins.rule import abolish
   eq_(eval(let([(f,function([[1], 1]))], abolish(f, 1))), {})
コード例 #56
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test_closure1(self):
     x, f = Const('x'), Const('f')
     eq_(eval(let([(f, macrorules([[x], prin(x)])), (x, 1)], f(add(x, x)))),
         None)
コード例 #57
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test_asserta(self):
   from dao.builtins.rule import asserta
   eq_(eval(let([(f,function(([1], 1)))], 
              asserta(f, [2], [2]), f(2))), 2)
コード例 #58
0
ファイル: testeval.py プロジェクト: hermetique/dao
 def test_closure2(self):
     x, f = Const('x'), Const('f')
     eq_(eval(let([(f, macrorules([[x], x])), (x, 1)], f(add(x, x)))), 2)
コード例 #59
0
ファイル: testbuiltin.py プロジェクト: chaosim/dao
 def test_succeed(self):
   x = LogicVar('x')
   eq_(eval(let([(f,rules([[1], succeed]))], f(x))), True)
コード例 #60
0
ファイル: testeval.py プロジェクト: chaosim/dao
 def test_closure3(self):
   x, y, f = Const('x'), Const('y'), Const('f')
   eq_(eval(let([(f, macrorules([[x, y], begin(x, y)])),
                 (x, 1)],
            f(prin(x), prin(add(x,x))))), None)