feat(complex-matcher): empty string is supported (#31)
This commit is contained in:
parent
2e945e8349
commit
8532d563de
@ -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]
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import {
|
||||
getPropertyClausesStrings,
|
||||
Null,
|
||||
parse,
|
||||
setPropertyClause,
|
||||
} from './'
|
||||
@ -15,8 +16,14 @@ it('getPropertyClausesStrings', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('parse', () => {
|
||||
expect(parse(pattern)).toEqual(ast)
|
||||
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', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user