89 lines
3.2 KiB
JavaScript
89 lines
3.2 KiB
JavaScript
import { describe, it } from 'node:test'
|
|
import assert from '../assert.js'
|
|
import { node, edge, properties, statement } from '../../src/query/match.js'
|
|
import { makeEdge, makeNode } from '../utils.js'
|
|
|
|
describe('node', () => {
|
|
it('should match a label with an empty name', () => {
|
|
assert.parseOk(node, '(:Node)', actual => {
|
|
const expected = makeNode(undefined, 'Node')
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
|
|
it('should match a name and label', () => {
|
|
assert.parseOk(node, '(node:Node)', actual => {
|
|
const expected = makeNode('node', 'Node')
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
|
|
it('should match a node with properties and no name', () => {
|
|
assert.parseOk(node, '(:Label { name: "Rowan", gay: true })', actual => {
|
|
const expected = makeNode(undefined, 'Label', [['name', 'Rowan'], ['gay', true]])
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
|
|
it('should match a node with properties and a name', () => {
|
|
assert.parseOk(node, '(name:Label { name: "Rowan", gay: true })', actual => {
|
|
const expected = makeNode('name', 'Label', [['name', 'Rowan'], ['gay', true]])
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
|
|
it('should handle whitespace', () => {
|
|
assert.parseOk(node, '( name : Label { name : "Rowan" , gay : true } )', actual => {
|
|
const expected = makeNode('name', 'Label', [['name', 'Rowan'], ['gay', true]])
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
})
|
|
|
|
|
|
describe('edge', () => {
|
|
it('should match a relationship with a name and label', () => {
|
|
assert.parseOk(edge, '[name:Label]', actual => {
|
|
const expected = makeEdge('name', 'Label', [])
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
|
|
it('should match a relationship with no name', () => {
|
|
assert.parseOk(edge, '[:Label]', actual => {
|
|
const expected = makeEdge(undefined, 'Label', [])
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
|
|
it('should match a relationship with a name and properties', () => {
|
|
assert.parseOk(edge, '[gay:Queer { binary: "-∞" }]', actual => {
|
|
const expected = makeEdge('gay', 'Queer', [['binary', '-∞']])
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
|
|
it('should match a relationship with properties and no name', () => {
|
|
assert.parseOk(edge, '[:Queer { binary: "-∞" }]', actual => {
|
|
const expected = makeEdge(undefined, 'Queer', [['binary', '-∞']])
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
|
|
it('should handle whitespace', () => {
|
|
assert.parseOk(edge, '[ : Queer { binary : "-∞" } ]', actual => {
|
|
const expected = makeEdge(undefined, 'Queer', [['binary', '-∞']])
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('match', () => {
|
|
it('should match nodes', () => {
|
|
assert.parseOk(statement, '(node:Label)', actual => {
|
|
const expected = makeNode('node', 'Label')
|
|
assert.deepEqual(actual, expected)
|
|
})
|
|
})
|
|
})
|
|
|