test(complex-matcher): from Jest to test (#6535)

This commit is contained in:
Gabriel Gunullu 2022-11-16 23:24:32 +01:00 committed by GitHub
parent 9560cc4e33
commit b2ccb07a95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 23 deletions

View File

@ -1,7 +1,8 @@
/* eslint-env jest */
'use strict'
const { describe, it } = require('test')
const assert = require('assert').strict
const { ast, pattern } = require('./index.fixtures')
const {
getPropertyClausesStrings,
@ -17,7 +18,7 @@ const {
it('getPropertyClausesStrings', () => {
const tmp = getPropertyClausesStrings(parse('foo bar:baz baz:|(foo bar /^boo$/ /^far$/) foo:/^bar$/'))
expect(tmp).toEqual({
assert.deepEqual(tmp, {
bar: ['baz'],
baz: ['foo', 'bar', 'boo', 'far'],
foo: ['bar'],
@ -26,72 +27,72 @@ it('getPropertyClausesStrings', () => {
describe('parse', () => {
it('analyses a string and returns a node/tree', () => {
expect(parse(pattern)).toEqual(ast)
assert.deepEqual(parse(pattern), ast)
})
it('supports an empty string', () => {
expect(parse('')).toEqual(new Null())
assert.deepEqual(parse(''), new Null())
})
it('differentiate between numbers and numbers in strings', () => {
let node
node = parse('32')
expect(node.match(32)).toBe(true)
expect(node.match('32')).toBe(true)
expect(node.toString()).toBe('32')
assert.equal(node.match(32), true)
assert.equal(node.match('32'), true)
assert.equal(node.toString(), '32')
node = parse('"32"')
expect(node.match(32)).toBe(false)
expect(node.match('32')).toBe(true)
expect(node.toString()).toBe('"32"')
assert.equal(node.match(32), false)
assert.equal(node.match('32'), true)
assert.equal(node.toString(), '"32"')
})
it('supports non-ASCII letters in raw strings', () => {
expect(parse('åäöé:ÅÄÖÉ')).toStrictEqual(new Property('åäöé', new StringNode('ÅÄÖÉ')))
assert.deepEqual(parse('åäöé:ÅÄÖÉ'), new Property('åäöé', new StringNode('ÅÄÖÉ')))
})
})
describe('GlobPattern', () => {
it('matches a glob pattern recursively', () => {
expect(new GlobPattern('b*r').match({ foo: 'bar' })).toBe(true)
assert.equal(new GlobPattern('b*r').match({ foo: 'bar' }), true)
})
})
describe('Number', () => {
it('match a number recursively', () => {
expect(new NumberNode(3).match([{ foo: 3 }])).toBe(true)
assert.equal(new NumberNode(3).match([{ foo: 3 }]), true)
})
})
describe('NumberOrStringNode', () => {
it('match a string', () => {
expect(new NumberOrStringNode('123').match([{ foo: '123' }])).toBe(true)
assert.equal(new NumberOrStringNode('123').match([{ foo: '123' }]), true)
})
})
describe('setPropertyClause', () => {
it('creates a node if none passed', () => {
expect(setPropertyClause(undefined, 'foo', 'bar').toString()).toBe('foo:bar')
assert.equal(setPropertyClause(undefined, 'foo', 'bar').toString(), 'foo:bar')
})
it('adds a property clause if there was none', () => {
expect(setPropertyClause(parse('baz'), 'foo', 'bar').toString()).toBe('baz foo:bar')
assert.equal(setPropertyClause(parse('baz'), 'foo', 'bar').toString(), 'baz foo:bar')
})
it('replaces the property clause if there was one', () => {
expect(setPropertyClause(parse('plip foo:baz plop'), 'foo', 'bar').toString()).toBe('plip plop foo:bar')
assert.equal(setPropertyClause(parse('plip foo:baz plop'), 'foo', 'bar').toString(), 'plip plop foo:bar')
expect(setPropertyClause(parse('foo:|(baz plop)'), 'foo', 'bar').toString()).toBe('foo:bar')
assert.equal(setPropertyClause(parse('foo:|(baz plop)'), 'foo', 'bar').toString(), 'foo:bar')
})
it('removes the property clause if no chid is passed', () => {
expect(setPropertyClause(parse('foo bar:baz qux'), 'bar', undefined).toString()).toBe('foo qux')
assert.equal(setPropertyClause(parse('foo bar:baz qux'), 'bar', undefined).toString(), 'foo qux')
expect(setPropertyClause(parse('foo bar:baz qux'), 'baz', undefined).toString()).toBe('foo bar:baz qux')
assert.equal(setPropertyClause(parse('foo bar:baz qux'), 'baz', undefined).toString(), 'foo bar:baz qux')
})
})
it('toString', () => {
expect(ast.toString()).toBe(pattern)
assert.equal(ast.toString(), pattern)
})

View File

@ -26,6 +26,10 @@
"lodash": "^4.17.4"
},
"scripts": {
"postversion": "npm publish"
"postversion": "npm publish",
"test": "node--test"
},
"devDependencies": {
"test": "^3.2.1"
}
}