feat(complex-matcher): number are matched recursively

This commit is contained in:
Julien Fontanet 2018-01-26 15:17:46 +01:00
parent 5e8e1968e1
commit 971c039086
2 changed files with 17 additions and 2 deletions

View File

@ -146,10 +146,18 @@ export class NumberNode extends Node {
super()
this.value = value
// should not be enumerable for the tests
Object.defineProperty(this, 'match', {
value: this.match.bind(this),
})
}
match (value) {
return value === this.value
return (
value === this.value ||
(value !== null && typeof value === 'object' && some(value, this.match))
)
}
toString () {

View File

@ -1,12 +1,13 @@
/* eslint-env jest */
import { ast, pattern } from './index.fixtures'
import {
getPropertyClausesStrings,
Null,
NumberNode,
parse,
setPropertyClause,
} from './'
import { ast, pattern } from './index.fixtures'
it('getPropertyClausesStrings', () => {
const tmp = getPropertyClausesStrings(parse('foo bar:baz baz:|(foo bar)'))
@ -40,6 +41,12 @@ describe('parse', () => {
})
})
describe('Number', () => {
it('match a number recursively', () => {
expect(new NumberNode(3).match([{ foo: 3 }])).toBe(true)
})
})
describe('setPropertyClause', () => {
it('creates a node if none passed', () => {
expect(setPropertyClause(undefined, 'foo', 'bar').toString()).toBe('foo:bar')