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() super()
this.value = value this.value = value
// should not be enumerable for the tests
Object.defineProperty(this, 'match', {
value: this.match.bind(this),
})
} }
match (value) { match (value) {
return value === this.value return (
value === this.value ||
(value !== null && typeof value === 'object' && some(value, this.match))
)
} }
toString () { toString () {

View File

@ -1,12 +1,13 @@
/* eslint-env jest */ /* eslint-env jest */
import { ast, pattern } from './index.fixtures'
import { import {
getPropertyClausesStrings, getPropertyClausesStrings,
Null, Null,
NumberNode,
parse, parse,
setPropertyClause, setPropertyClause,
} from './' } from './'
import { ast, pattern } from './index.fixtures'
it('getPropertyClausesStrings', () => { it('getPropertyClausesStrings', () => {
const tmp = getPropertyClausesStrings(parse('foo bar:baz baz:|(foo bar)')) 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', () => { describe('setPropertyClause', () => {
it('creates a node if none passed', () => { it('creates a node if none passed', () => {
expect(setPropertyClause(undefined, 'foo', 'bar').toString()).toBe('foo:bar') expect(setPropertyClause(undefined, 'foo', 'bar').toString()).toBe('foo:bar')