feat(complex-matcher): empty string is supported (#31)

This commit is contained in:
Julien Fontanet 2017-12-27 16:38:42 +01:00 committed by GitHub
parent 2e945e8349
commit 8532d563de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -74,6 +74,16 @@ class Node {
}
}
export class Null extends Node {
match () {
return true
}
toString () {
return ''
}
}
const formatTerms = terms => terms.map(term => term.toString(true)).join(' ')
export class And extends Node {
@ -202,7 +212,8 @@ export class TruthyProperty extends Node {
// -------------------------------------------------------------------
// terms = term+
// terms = null || term+
// *null = /$/
// term = ws (and | or | not | property | truthyProperty | string) ws
// ws = ' '*
// *and = "(" terms ")"
@ -234,7 +245,7 @@ export const parse = invoke(() => {
const parseTerms = Node => {
let term = parseTerm()
if (!term) {
return
return new Null()
}
const terms = [term]

View File

@ -2,6 +2,7 @@
import {
getPropertyClausesStrings,
Null,
parse,
setPropertyClause,
} from './'
@ -15,10 +16,16 @@ it('getPropertyClausesStrings', () => {
})
})
it('parse', () => {
describe('parse', () => {
it('analyses a string and returns a node/tree', () => {
expect(parse(pattern)).toEqual(ast)
})
it('supports an empty string', () => {
expect(parse('')).toEqual(new Null())
})
})
describe('setPropertyClause', () => {
it('creates a node if none passed', () => {
expect(setPropertyClause(undefined, 'foo', 'bar').toString()).toBe('foo:bar')