fix tests
This commit is contained in:
parent
3aaa48aa59
commit
5411742372
5 changed files with 67 additions and 51 deletions
|
@ -1,11 +1,10 @@
|
||||||
import assert from 'node:assert'
|
import assert from 'node:assert'
|
||||||
import { curry } from '../src/fn.js'
|
import { curry } from '../src/fn.js'
|
||||||
import { parse } from 'node:path'
|
import { parse } from '../src/parser.js'
|
||||||
|
|
||||||
const isOk = curry((fn, result) => {
|
const isOk = curry((fn, result) => {
|
||||||
assert.doesNotThrow(() => {
|
assert.doesNotThrow(() => {
|
||||||
const [[actual]] = result.unwrap()
|
fn(result.unwrap()[0])
|
||||||
fn(actual)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,89 +1,107 @@
|
||||||
import { describe, it } from 'node:test'
|
import { describe, it } from 'node:test'
|
||||||
import assert from '../assert.js'
|
import assert from '../assert.js'
|
||||||
import { node, edge, properties, statement } from '../../src/query/match.js'
|
import { node, edge, statement } from '../../src/query/match.js'
|
||||||
import { makeEdge, makeNode } from '../utils.js'
|
import { makeEdge, makeNode } from '../utils.js'
|
||||||
|
|
||||||
describe('node', () => {
|
describe('node', () => {
|
||||||
it('should match a label with an empty name', () => {
|
it('should match a node with a name, label, and properties', () => {
|
||||||
assert.parseOk(node, '(:Node)', actual => {
|
assert.parseOk(node, '(:Node)', ([actual]) => {
|
||||||
const expected = makeNode(undefined, 'Node')
|
const expected = makeNode(undefined, 'Node')
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should match a name and label', () => {
|
assert.parseOk(node, '(node:Node)', ([actual]) => {
|
||||||
assert.parseOk(node, '(node:Node)', actual => {
|
|
||||||
const expected = makeNode('node', 'Node')
|
const expected = makeNode('node', 'Node')
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
it('should match a node with properties and no name', () => {
|
assert.parseOk(node, '(:Label { name: "Rowan", gay: true })', ([actual]) => {
|
||||||
assert.parseOk(node, '(:Label { name: "Rowan", gay: true })', actual => {
|
|
||||||
const expected = makeNode(undefined, 'Label', [['name', 'Rowan'], ['gay', true]])
|
const expected = makeNode(undefined, 'Label', [['name', 'Rowan'], ['gay', true]])
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
it('should match a node with properties and a name', () => {
|
assert.parseOk(node, '(name:Label { name: "Rowan", gay: true })', ([actual]) => {
|
||||||
assert.parseOk(node, '(name:Label { name: "Rowan", gay: true })', actual => {
|
|
||||||
const expected = makeNode('name', 'Label', [['name', 'Rowan'], ['gay', true]])
|
const expected = makeNode('name', 'Label', [['name', 'Rowan'], ['gay', true]])
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle whitespace', () => {
|
it('should handle whitespace', () => {
|
||||||
assert.parseOk(node, '( name : Label { name : "Rowan" , gay : true } )', actual => {
|
assert.parseOk(node, '(name:Label { name: "Rowan", gay: true })', ([actual]) => {
|
||||||
const expected = makeNode('name', 'Label', [['name', 'Rowan'], ['gay', true]])
|
const expected = makeNode('name', 'Label', [['name', 'Rowan'], ['gay', true]])
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
describe('edge', () => {
|
describe('edge', () => {
|
||||||
it('should match a relationship with a name and label', () => {
|
it('should match a relationship with a name, label, properties', () => {
|
||||||
assert.parseOk(edge, '[name:Label]', actual => {
|
assert.parseOk(edge, '[name:Label]', ([actual]) => {
|
||||||
const expected = makeEdge('name', 'Label', [])
|
const expected = makeEdge('name', 'Label', [])
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
it('should match a relationship with no name', () => {
|
assert.parseOk(edge, '[:Label]', ([actual]) => {
|
||||||
assert.parseOk(edge, '[:Label]', actual => {
|
|
||||||
const expected = makeEdge(undefined, 'Label', [])
|
const expected = makeEdge(undefined, 'Label', [])
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
it('should match a relationship with a name and properties', () => {
|
assert.parseOk(edge, '[gay:Queer { binary: "-∞" }]', ([actual]) => {
|
||||||
assert.parseOk(edge, '[gay:Queer { binary: "-∞" }]', actual => {
|
|
||||||
const expected = makeEdge('gay', 'Queer', [['binary', '-∞']])
|
const expected = makeEdge('gay', 'Queer', [['binary', '-∞']])
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
it('should match a relationship with properties and no name', () => {
|
assert.parseOk(edge, '[:Queer { binary: "-∞" }]', ([actual]) => {
|
||||||
assert.parseOk(edge, '[:Queer { binary: "-∞" }]', actual => {
|
|
||||||
const expected = makeEdge(undefined, 'Queer', [['binary', '-∞']])
|
const expected = makeEdge(undefined, 'Queer', [['binary', '-∞']])
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle whitespace', () => {
|
it('should handle whitespace', () => {
|
||||||
assert.parseOk(edge, '[ : Queer { binary : "-∞" } ]', actual => {
|
assert.parseOk(edge, '[ : Queer { binary : "-∞" } ]', ([actual]) => {
|
||||||
const expected = makeEdge(undefined, 'Queer', [['binary', '-∞']])
|
const expected = makeEdge(undefined, 'Queer', [['binary', '-∞']])
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('match', () => {
|
describe('MATCH keyword', () => {
|
||||||
it('should match nodes', () => {
|
it('should match nodes with a relationship to another another node', () => {
|
||||||
assert.parseOk(statement, '(node:Label)', actual => {
|
assert.parseOk(statement, 'MATCH (node:Label)', ([actual]) => {
|
||||||
const expected = makeNode('node', 'Label')
|
const expected = makeNode('node', 'Label')
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
assert.parseOk(statement, 'MATCH (:Node)-[:Edge]->(:Node)', actual => {
|
||||||
|
const expected = [
|
||||||
|
makeNode(undefined, 'Node'),
|
||||||
|
makeEdge(undefined, 'Edge'),
|
||||||
|
makeNode(undefined, 'Node'),
|
||||||
|
]
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.parseOk(statement, 'MATCH (a:Node)-[e:Edge]->(b:Node)', actual => {
|
||||||
|
const expected = [
|
||||||
|
makeNode('a', 'Node'),
|
||||||
|
makeEdge('e', 'Edge'),
|
||||||
|
makeNode('b', 'Node'),
|
||||||
|
]
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.parseOk(statement, 'MATCH (a:Node { db: 0.7 })-[e:Edge]->(b:Node { db: 0.95 })', actual => {
|
||||||
|
const expected = [
|
||||||
|
makeNode('a', 'Node', [['db', 0.7]]),
|
||||||
|
makeEdge('e', 'Edge'),
|
||||||
|
makeNode('b', 'Node', [['db', 0.95]]),
|
||||||
|
]
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ import assert from '../assert.js'
|
||||||
import { statement } from '../../src/query/return.js'
|
import { statement } from '../../src/query/return.js'
|
||||||
import { Alias, Identifier, Literal } from '../../src/query/types.js'
|
import { Alias, Identifier, Literal } from '../../src/query/types.js'
|
||||||
|
|
||||||
describe('return parser', () => {
|
describe('RETURN keyword', () => {
|
||||||
it('should collect a single value for a query to return', () => {
|
it('should collect a single value for a query to return', () => {
|
||||||
assert.parseOk(statement, 'RETURN folklore AS f', actual => {
|
assert.parseOk(statement, 'RETURN folklore AS f', ([actual]) => {
|
||||||
assert.deepEqual(actual, new Alias(new Identifier('folklore'), new Identifier('f')))
|
assert.deepEqual(actual, new Alias(new Identifier('folklore'), new Identifier('f')))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import { describe, it } from 'node:test'
|
import { describe, it } from 'node:test'
|
||||||
import assert from '../assert.js'
|
import assert from '../assert.js'
|
||||||
import { parse } from '../../src/parser.js'
|
|
||||||
import { statement } from '../../src/query/use.js'
|
import { statement } from '../../src/query/use.js'
|
||||||
import { Identifier } from '../../src/query/types.js'
|
import { Identifier } from '../../src/query/types.js'
|
||||||
|
|
||||||
describe('use parser', () => {
|
describe('USE keyword', () => {
|
||||||
it('should select a graph to query', () => {
|
it('should select a graph to query', () => {
|
||||||
assert.parseOk(statement, 'USE default', actual => {
|
assert.parseOk(statement, 'USE default', ([actual]) => {
|
||||||
assert.deepEqual(actual.identifier, new Identifier('default'))
|
assert.deepEqual(actual.identifier, new Identifier('default'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { KeyValuePair, Name, Label, Identifier, Literal, Edge } from '../src/query/types.js'
|
import { KeyValuePair, Name, Label, Identifier, Literal, Edge, Node } from '../src/query/types.js'
|
||||||
|
|
||||||
export const keyValuePair = ([k, v]) => new KeyValuePair(new Name(new Identifier(k)), new Literal(v))
|
export const keyValuePair = ([k, v]) => new KeyValuePair(new Name(new Identifier(k)), new Literal(v))
|
||||||
|
|
||||||
export const graphObject = (name, label, props = [], Type = Node) => new Type(
|
export const graphObject = (name, label, props = [], Type = Node) => new Type(
|
||||||
name && new Name(new Identifier(name)),
|
name && new Name(new Identifier(name)),
|
||||||
new Label(new Identifier(label)),
|
new Label(new Identifier(label)),
|
||||||
props.map(makeKvp)
|
props.map(keyValuePair)
|
||||||
)
|
)
|
||||||
|
|
||||||
export const makeNode = graphObject
|
export const makeNode = graphObject
|
||||||
|
|
Loading…
Reference in a new issue