This commit is contained in:
harttle
2016-10-26 02:50:41 +08:00
parent 34f5cfa34d
commit 377c805230
14 changed files with 418 additions and 337 deletions
+25 -15
View File
@@ -34,22 +34,32 @@ describe('expression', function() {
expect(evalValue('x', scope)).to.equal('XXX');
});
it('should eval simple expression', function() {
expect(evalExp('1<2', scope)).to.equal(true);
expect(evalExp('2<=2', scope)).to.equal(true);
expect(evalExp('one<=two', scope)).to.equal(true);
expect(evalExp('x contains "x"', scope)).to.equal(false);
expect(evalExp('x contains "X"', scope)).to.equal(true);
expect(evalExp('"<=" == "<="', scope)).to.equal(true);
});
describe('.evalExp()', function() {
it('should eval complex expression', function() {
expect(evalExp('1<2 and x contains "x"', scope)).to.equal(false);
expect(evalExp('1<2 or x contains "x"', scope)).to.equal(true);
});
it('should throw when scope undefined', function() {
expect(function() {
evalExp('');
}).to.throw(/scope undefined/);
});
it("should eval range expression", function() {
expect(evalExp('(2..4)', scope)).to.deep.equal([2, 3, 4]);
expect(evalExp('(two..4)', scope)).to.deep.equal([2, 3, 4]);
it('should eval simple expression', function() {
expect(evalExp('1<2', scope)).to.equal(true);
expect(evalExp('2<=2', scope)).to.equal(true);
expect(evalExp('one<=two', scope)).to.equal(true);
expect(evalExp('x contains "x"', scope)).to.equal(false);
expect(evalExp('x contains "X"', scope)).to.equal(true);
expect(evalExp('"<=" == "<="', scope)).to.equal(true);
});
it('should eval complex expression', function() {
expect(evalExp('1<2 and x contains "x"', scope)).to.equal(false);
expect(evalExp('1<2 or x contains "x"', scope)).to.equal(true);
expect(evalExp('false or true', scope)).to.equal(true);
});
it("should eval range expression", function() {
expect(evalExp('(2..4)', scope)).to.deep.equal([2, 3, 4]);
expect(evalExp('(two..4)', scope)).to.deep.equal([2, 3, 4]);
});
});
});