From 54117423727c132d3924c04ad1c717d4841e3cb4 Mon Sep 17 00:00:00 2001 From: kitsunecafe Date: Wed, 13 Nov 2024 17:32:46 -0600 Subject: [PATCH] fix tests --- tests/assert.js | 5 +- tests/query/match.test.js | 100 ++++++++++++++++++++++--------------- tests/query/return.test.js | 4 +- tests/query/use.test.js | 5 +- tests/utils.js | 4 +- 5 files changed, 67 insertions(+), 51 deletions(-) diff --git a/tests/assert.js b/tests/assert.js index 9bef1db..d6c4c32 100644 --- a/tests/assert.js +++ b/tests/assert.js @@ -1,11 +1,10 @@ import assert from 'node:assert' import { curry } from '../src/fn.js' -import { parse } from 'node:path' +import { parse } from '../src/parser.js' const isOk = curry((fn, result) => { assert.doesNotThrow(() => { - const [[actual]] = result.unwrap() - fn(actual) + fn(result.unwrap()[0]) }) }) diff --git a/tests/query/match.test.js b/tests/query/match.test.js index 9989f28..59366fb 100644 --- a/tests/query/match.test.js +++ b/tests/query/match.test.js @@ -1,89 +1,107 @@ import { describe, it } from 'node:test' 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' describe('node', () => { - it('should match a label with an empty name', () => { - assert.parseOk(node, '(:Node)', actual => { + it('should match a node with a name, label, and properties', () => { + 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) - }) - }) + 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) - }) - }) + 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) + 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) + 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 => { + it('should match a relationship with a name, label, properties', () => { + 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 => { + 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 => { + 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 => { + 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 => { + 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 => { +describe('MATCH keyword', () => { + it('should match nodes with a relationship to another another node', () => { + assert.parseOk(statement, 'MATCH (node:Label)', ([actual]) => { const expected = makeNode('node', 'Label') 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) + }) }) }) diff --git a/tests/query/return.test.js b/tests/query/return.test.js index df77021..21217c6 100644 --- a/tests/query/return.test.js +++ b/tests/query/return.test.js @@ -3,9 +3,9 @@ import assert from '../assert.js' import { statement } from '../../src/query/return.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', () => { - 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'))) }) }) diff --git a/tests/query/use.test.js b/tests/query/use.test.js index 9cad181..0e7b3a8 100644 --- a/tests/query/use.test.js +++ b/tests/query/use.test.js @@ -1,12 +1,11 @@ import { describe, it } from 'node:test' import assert from '../assert.js' -import { parse } from '../../src/parser.js' import { statement } from '../../src/query/use.js' import { Identifier } from '../../src/query/types.js' -describe('use parser', () => { +describe('USE keyword', () => { 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')) }) }) diff --git a/tests/utils.js b/tests/utils.js index 3fc47c5..836c96e 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -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 graphObject = (name, label, props = [], Type = Node) => new Type( name && new Name(new Identifier(name)), new Label(new Identifier(label)), - props.map(makeKvp) + props.map(keyValuePair) ) export const makeNode = graphObject