fix: contains operator does not support Drop, fixes #492

This commit is contained in:
Harttle
2022-04-18 00:43:18 +08:00
parent eec381ec72
commit 9e024ff2bc
3 changed files with 21 additions and 2 deletions
+8
View File
@@ -1,5 +1,6 @@
import { Tokenizer } from '../../../src/parser/tokenizer'
import { expect } from 'chai'
import { Drop } from '../../../src/drop/drop'
import { Context } from '../../../src/context/context'
import { toThenable } from '../../../src/util/async'
import { defaultOperators } from '../../../src/render/operator'
@@ -130,6 +131,13 @@ describe('Expression', function () {
it('should support < or contains', async function () {
expect(await toThenable(create('1 < 2 or x contains "x"').evaluate(ctx, false))).to.equal(true)
})
it('should support Drops for "x contains "x""', async () => {
class TemplateDrop extends Drop {
valueOf () { return 'X' }
}
const ctx = new Context({ x: 'XXX', X: new TemplateDrop() })
expect(await toThenable(create('x contains X').evaluate(ctx, false))).to.equal(true)
})
it('should support value and !=', async function () {
const ctx = new Context({ empty: '' })
expect(await toThenable(create('empty and empty != ""').evaluate(ctx, false))).to.equal(false)