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(' ') const formatTerms = terms => terms.map(term => term.toString(true)).join(' ')
export class And extends Node { 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 // term = ws (and | or | not | property | truthyProperty | string) ws
// ws = ' '* // ws = ' '*
// *and = "(" terms ")" // *and = "(" terms ")"
@ -234,7 +245,7 @@ export const parse = invoke(() => {
const parseTerms = Node => { const parseTerms = Node => {
let term = parseTerm() let term = parseTerm()
if (!term) { if (!term) {
return return new Null()
} }
const terms = [term] const terms = [term]

View File

@ -2,6 +2,7 @@
import { import {
getPropertyClausesStrings, getPropertyClausesStrings,
Null,
parse, parse,
setPropertyClause, setPropertyClause,
} from './' } from './'
@ -15,8 +16,14 @@ it('getPropertyClausesStrings', () => {
}) })
}) })
it('parse', () => { describe('parse', () => {
expect(parse(pattern)).toEqual(ast) 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', () => { describe('setPropertyClause', () => {