forked from noolsjs/nools
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 2 commits.
# The first commit's message is: Implement no-loop rule attribute Fixes issue with using grave marks for dsl strings in test file: noloop.test.js Implements extends functionality in the dsl These files address noolsjs#162 , the extends keyword, which allows you to reference other types in either external or other defines as a base type. Revert "Implements extends functionality in the dsl" This reverts commit 1259c3d. removed gitattributs/gitignore from branch # This is the 2nd commit message: Fixes issue with using grave marks for dsl strings in test file: noloop.test.js
- Loading branch information
1 parent
61d427f
commit a2429b3
Showing
6 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"use strict"; | ||
var it = require("it"), | ||
assert = require("assert"), | ||
nools = require("../../"); | ||
|
||
it.describe("no-loop", function (it) { | ||
/*jshint indent*/ | ||
function Message(name) { | ||
this.name = name; | ||
} | ||
var cnt = 0; | ||
|
||
var flow1 = nools.flow("noLoop1", function () { | ||
|
||
this.rule("Hello2", { noLoop: true }, [Message, "m", "m.name =~ /Hello/"], function (facts) { | ||
var m = facts.m; | ||
m.name = 'Hello World'; | ||
this.modify(m); | ||
}); | ||
}), | ||
|
||
flow2 = nools.flow("noLoop2", function () { | ||
|
||
this.rule("Hello1", [Message, "m", "m.name =~ /Hello/"], function (facts) { | ||
var m = facts.m; | ||
if (cnt++ < 2) { | ||
m.name = 'Hello World'; | ||
this.modify(m); | ||
} | ||
}); | ||
}); | ||
|
||
var noolsSource = "rule 'Hello3' { no-loop: true; when {m: Message m.name =~/Hello/;}then {modify(m, function () { this.name = 'Hello World'; });}}"; | ||
|
||
var flow3 = nools.compile(noolsSource, { | ||
name: 'testDsl' | ||
,define: { | ||
Message: Message | ||
} | ||
}); | ||
|
||
it.should("not loop with option on and loop otherwise", function () { | ||
var fired1 = [], fired2 = [], fired3 = []; | ||
var session1 = flow1.getSession(new Message("Hello")).on("fire", function (name) { | ||
fired1.push(name); | ||
}), | ||
session2 = flow2.getSession(new Message("Hello")).on("fire", function (name) { | ||
fired2.push(name); | ||
}), | ||
session3 = flow3.getSession(new Message("Hello")).on("fire", function (name) { | ||
fired3.push(name); | ||
}); | ||
return session1.match() | ||
.then(function () { | ||
return session2.match().then(function () { | ||
return session3.match().then(function () { | ||
}) | ||
}) | ||
}) | ||
.then(function () { | ||
assert.deepEqual(fired1, ["Hello2"]); | ||
assert.deepEqual(fired2, ["Hello1", "Hello1", "Hello1"]); | ||
assert.deepEqual(fired3, ["Hello3"]); | ||
}); | ||
}); | ||
|
||
}); |