浏览代码

ncd: tests: add depend_scope.ncd, multidepend.ncd

ambrop7 13 年之前
父节点
当前提交
ba3248f0cb
共有 2 个文件被更改,包括 61 次插入0 次删除
  1. 31 0
      ncd/tests/depend_scope.ncd
  2. 30 0
      ncd/tests/multidepend.ncd

+ 31 - 0
ncd/tests/depend_scope.ncd

@@ -0,0 +1,31 @@
+process main {
+    depend_scope() scope;
+    var("0") x;
+    process_manager() mgr;
+    
+    var("false") backtrack_check;
+    backtrack_point() point;
+    If (backtrack_check) {
+        val_equal(x, "2") a; # must not have rebound temporarily to A during backtracking
+        assert(a);
+        exit("0");
+    };
+    
+    scope->provide("A");
+    mgr->start("t1", "t1", {});
+    val_equal(x, "1") a; # must have bound to A immediately
+    assert(a);
+    
+    scope->provide("B") mgr;
+    val_equal(x, "2") a; # must have rebound to B immediately
+    assert(a);
+    
+    backtrack_check->set("true");
+    point->go();
+}
+
+template t1 {
+    _caller.scope->depend({"B", "A"}) dep;
+    num_add(dep.x, "1") new_x;
+    dep.x->set(new_x);
+}

+ 30 - 0
ncd/tests/multidepend.ncd

@@ -0,0 +1,30 @@
+process main {
+    var("0") x;
+    process_manager() mgr;
+    
+    var("false") backtrack_check;
+    backtrack_point() point;
+    If (backtrack_check) {
+        val_equal(x, "2") a; # must not have rebound temporarily to A during backtracking
+        assert(a);
+        exit("0");
+    };
+    
+    multiprovide("A");
+    mgr->start("t1", "t1", {});
+    val_equal(x, "1") a; # must have bound to A immediately
+    assert(a);
+    
+    multiprovide("B") mgr;
+    val_equal(x, "2") a; # must have rebound to B immediately
+    assert(a);
+    
+    backtrack_check->set("true");
+    point->go();
+}
+
+template t1 {
+    multidepend({"B", "A"}) dep;
+    num_add(dep.x, "1") new_x;
+    dep.x->set(new_x);
+}