Merge branch 'chenos-master'

This commit is contained in:
harttle
2017-03-16 10:40:09 +08:00
2 changed files with 13 additions and 8 deletions
+5 -1
View File
@@ -5,7 +5,11 @@ var operators = {
'<': (l, r) => l < r,
'>=': (l, r) => l >= r,
'<=': (l, r) => l <= r,
'contains': (l, r) => l.indexOf(r) > -1,
'contains': (l, r) => {
if (!l) return false;
if (typeof l.indexOf !== 'function') return false;
return l.indexOf(r) > -1;
},
'and': (l, r) => l && r,
'or': (l, r) => l || r
};
+8 -7
View File
@@ -13,7 +13,9 @@ describe('expression', function() {
scope = Scope.factory({
one: 1,
two: 2,
x: 'XXX'
x: 'XXX',
y: undefined,
z: null
});
});
@@ -22,12 +24,6 @@ describe('expression', function() {
expect(evalValue('"foo"')).to.equal("foo");
});
it('should throw on illegal expression', function() {
expect(function() {
evalExp('1 contains "x"', scope);
}).to.throw();
});
it('should eval variables', function() {
expect(evalValue('23', scope)).to.equal(23);
expect(evalValue('one', scope)).to.equal(1);
@@ -48,6 +44,11 @@ describe('expression', function() {
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('1 contains "x"', scope)).to.equal(false);
expect(evalExp('y contains "x"', scope)).to.equal(false);
expect(evalExp('z contains "x"', scope)).to.equal(false);
expect(evalExp('(1..5) contains 3', scope)).to.equal(true);
expect(evalExp('(1..5) contains 6', scope)).to.equal(false);
expect(evalExp('"<=" == "<="', scope)).to.equal(true);
});