2024-11-10 10:15:43 +01:00
|
|
|
import { describe, it } from 'node:test'
|
2024-11-13 20:24:29 +01:00
|
|
|
import assert from '../assert.js'
|
2024-11-14 00:32:46 +01:00
|
|
|
import { node, edge, statement } from '../../src/query/match.js'
|
2024-11-13 20:24:29 +01:00
|
|
|
import { makeEdge, makeNode } from '../utils.js'
|
2024-11-10 10:15:43 +01:00
|
|
|
|
2024-11-13 20:24:29 +01:00
|
|
|
describe('node', () => {
|
2024-11-14 00:32:46 +01:00
|
|
|
it('should match a node with a name, label, and properties', () => {
|
|
|
|
assert.parseOk(node, '(:Node)', ([actual]) => {
|
2024-11-13 20:24:29 +01:00
|
|
|
const expected = makeNode(undefined, 'Node')
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
|
2024-11-14 00:32:46 +01:00
|
|
|
assert.parseOk(node, '(node:Node)', ([actual]) => {
|
|
|
|
const expected = makeNode('node', 'Node')
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
})
|
2024-11-13 20:24:29 +01:00
|
|
|
|
2024-11-14 00:32:46 +01:00
|
|
|
assert.parseOk(node, '(:Label { name: "Rowan", gay: true })', ([actual]) => {
|
|
|
|
const expected = makeNode(undefined, 'Label', [['name', 'Rowan'], ['gay', true]])
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
})
|
2024-11-13 20:24:29 +01:00
|
|
|
|
2024-11-14 00:32:46 +01:00
|
|
|
assert.parseOk(node, '(name:Label { name: "Rowan", gay: true })', ([actual]) => {
|
|
|
|
const expected = makeNode('name', 'Label', [['name', 'Rowan'], ['gay', true]])
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
})
|
2024-11-13 20:24:29 +01:00
|
|
|
})
|
|
|
|
|
2024-11-14 00:32:46 +01:00
|
|
|
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)
|
|
|
|
})
|
2024-11-13 20:24:29 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
describe('edge', () => {
|
2024-11-14 00:32:46 +01:00
|
|
|
it('should match a relationship with a name, label, properties', () => {
|
|
|
|
assert.parseOk(edge, '[name:Label]', ([actual]) => {
|
2024-11-13 20:24:29 +01:00
|
|
|
const expected = makeEdge('name', 'Label', [])
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
})
|
|
|
|
|
2024-11-14 00:32:46 +01:00
|
|
|
assert.parseOk(edge, '[:Label]', ([actual]) => {
|
2024-11-13 20:24:29 +01:00
|
|
|
const expected = makeEdge(undefined, 'Label', [])
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
})
|
|
|
|
|
2024-11-14 00:32:46 +01:00
|
|
|
assert.parseOk(edge, '[gay:Queer { binary: "-∞" }]', ([actual]) => {
|
2024-11-13 20:24:29 +01:00
|
|
|
const expected = makeEdge('gay', 'Queer', [['binary', '-∞']])
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
})
|
|
|
|
|
2024-11-14 00:32:46 +01:00
|
|
|
assert.parseOk(edge, '[:Queer { binary: "-∞" }]', ([actual]) => {
|
2024-11-13 20:24:29 +01:00
|
|
|
const expected = makeEdge(undefined, 'Queer', [['binary', '-∞']])
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should handle whitespace', () => {
|
2024-11-14 00:32:46 +01:00
|
|
|
assert.parseOk(edge, '[ : Queer { binary : "-∞" } ]', ([actual]) => {
|
2024-11-13 20:24:29 +01:00
|
|
|
const expected = makeEdge(undefined, 'Queer', [['binary', '-∞']])
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2024-11-14 00:32:46 +01:00
|
|
|
describe('MATCH keyword', () => {
|
|
|
|
it('should match nodes with a relationship to another another node', () => {
|
|
|
|
assert.parseOk(statement, 'MATCH (node:Label)', ([actual]) => {
|
2024-11-13 20:24:29 +01:00
|
|
|
const expected = makeNode('node', 'Label')
|
|
|
|
assert.deepEqual(actual, expected)
|
|
|
|
})
|
2024-11-14 00:32:46 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
2024-11-13 20:24:29 +01:00
|
|
|
})
|
|
|
|
})
|
2024-11-10 10:15:43 +01:00
|
|
|
|