Skip to content

Commit

Permalink
Merge pull request #33 from rdf-ext/quantity-path-tests
Browse files Browse the repository at this point in the history
chore: merged quantity paths into single class, added tests, tests cleanup
  • Loading branch information
bergos authored Sep 29, 2024
2 parents f9e988e + 4a057f2 commit f202b0f
Show file tree
Hide file tree
Showing 24 changed files with 614 additions and 139 deletions.
20 changes: 9 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import Insert from './lib/Insert.js'
import InsertData from './lib/InsertData.js'
import InversePath from './lib/InversePath.js'
import NegatedPropertySet from './lib/NegatedPropertySet.js'
import OneOrMorePath from './lib/OneOrMorePath.js'
import Optional from './lib/Optional.js'
import Path from './lib/Path.js'
import QuantityPath from './lib/QuantityPath.js'
import Select from './lib/Select.js'
import SubQuery from './lib/SubQuery.js'
import Union from './lib/Union.js'
import smartAddPatterns from './lib/utils/smartAddPatterns.js'
import ZeroOrMorePath from './lib/ZeroOrMorePath.js'
import ZeroOrOnePath from './lib/ZeroOrOnePath.js'

const eq = (a, b) => new CompareFilter('=', a, b)
const ne = (a, b) => new CompareFilter('!=', a, b)
Expand Down Expand Up @@ -59,13 +57,13 @@ const graph = (graph, children) => smartAddPatterns(new Graph(graph), children)
const optional = patterns => smartAddPatterns(new Optional(), patterns)
const union = queries => new Union(queries.map(query => smartAddPatterns(new SubQuery(), query)))

const alternative = elements => new AlternativePath(elements)
const inverse = element => new InversePath(element)
const not = element => new NegatedPropertySet(element)
const oneOrMore = element => new OneOrMorePath(element)
const or = elements => new AlternativePath(elements)
const negated = element => new NegatedPropertySet(element)
const oneOrMore = element => new QuantityPath('+', element)
const sequence = elements => new Path(elements)
const zeroOrMore = element => new ZeroOrMorePath(element)
const zeroOrOne = element => new ZeroOrOnePath(element)
const zeroOrMore = element => new QuantityPath('*', element)
const zeroOrOne = element => new QuantityPath('?', element)

export {
eq,
Expand All @@ -92,9 +90,9 @@ export {
construct,
deleteQuery as delete,
deleteData,
describe,
insert,
insertData,
describe,
select,

bind,
Expand All @@ -103,10 +101,10 @@ export {
optional,
union,

alternative,
inverse,
not,
negated,
oneOrMore,
or,
sequence,
zeroOrMore,
zeroOrOne
Expand Down
16 changes: 0 additions & 16 deletions lib/OneOrMorePath.js

This file was deleted.

16 changes: 16 additions & 0 deletions lib/QuantityPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Node from './Node.js'
import termOrNodeToPathString from './utils/termOrNodeToPathString.js'

class QuantityPath extends Node {
constructor (quantifier, element) {
super({ type: 'QuantityPath' })

this.attr = { element, quantifier }
}

toStringStart () {
return [termOrNodeToPathString(this.attr.element), this.attr.quantifier].join('')
}
}

export default QuantityPath
16 changes: 0 additions & 16 deletions lib/ZeroOrMorePath.js

This file was deleted.

16 changes: 0 additions & 16 deletions lib/ZeroOrOnePath.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/AlternativePath.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import { describe, it } from 'mocha'
import AlternativePath from '../lib/AlternativePath.js'
import Path from '../lib/Path.js'
Expand Down
2 changes: 1 addition & 1 deletion test/Construct.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import rdf from '@rdfjs/data-model'
import { describe, it } from 'mocha'
import Construct from '../lib/Construct.js'
Expand Down
2 changes: 1 addition & 1 deletion test/Delete.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import rdf from '@rdfjs/data-model'
import { describe, it } from 'mocha'
import Delete from '../lib/Delete.js'
Expand Down
2 changes: 1 addition & 1 deletion test/DeleteData.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import rdf from '@rdfjs/data-model'
import { describe, it } from 'mocha'
import DeleteData from '../lib/DeleteData.js'
Expand Down
2 changes: 1 addition & 1 deletion test/Describe.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import { describe, it } from 'mocha'
import Describe from '../lib/Describe.js'
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js'
Expand Down
2 changes: 1 addition & 1 deletion test/Graph.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import rdf from '@rdfjs/data-model'
import { describe, it } from 'mocha'
import Graph from '../lib/Graph.js'
Expand Down
2 changes: 1 addition & 1 deletion test/Insert.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import rdf from '@rdfjs/data-model'
import { describe, it } from 'mocha'
import Insert from '../lib/Insert.js'
Expand Down
2 changes: 1 addition & 1 deletion test/InsertData.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import rdf from '@rdfjs/data-model'
import { describe, it } from 'mocha'
import InsertData from '../lib/InsertData.js'
Expand Down
2 changes: 1 addition & 1 deletion test/InversePath.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import { describe, it } from 'mocha'
import InversePath from '../lib/InversePath.js'
import Path from '../lib/Path.js'
Expand Down
2 changes: 1 addition & 1 deletion test/NegatedPropertySet.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import { describe, it } from 'mocha'
import InversePath from '../lib/InversePath.js'
import NegatedPropertySet from '../lib/NegatedPropertySet.js'
Expand Down
28 changes: 0 additions & 28 deletions test/OneOrMorePath.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/Path.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import { describe, it } from 'mocha'
import Path from '../lib/Path.js'
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js'
Expand Down
2 changes: 1 addition & 1 deletion test/Patterns.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import rdf from '@rdfjs/data-model'
import { describe, it } from 'mocha'
import GraphPattern from '../lib/GraphPattern.js'
Expand Down
16 changes: 8 additions & 8 deletions test/ZeroOrOnePath.test.js → test/QuantityPath.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import { describe, it } from 'mocha'
import Path from '../lib/Path.js'
import ZeroOrOnePath from '../lib/ZeroOrOnePath.js'
import QuantityPath from '../lib/QuantityPath.js'
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js'
import ns from './support/namespace.js'

describe('ZeroOrOnePath', () => {
describe('QuantityPath', () => {
it('should be a constructor', () => {
strictEqual(typeof ZeroOrOnePath, 'function')
strictEqual(typeof QuantityPath, 'function')
})

it('should create a zero or one path', () => {
const path = new ZeroOrOnePath(ns.ex.measure)
it('should create a quantity path', () => {
const path = new QuantityPath('?', ns.ex.measure)

const expected = '<http://example.org/measure>?'

ignoreWhitespaceEqual(path, expected)
})

it('should create a zero or one path with a group', () => {
const path = new ZeroOrOnePath(new Path([ns.ex.measure, ns.ex.temperature]))
it('should create a quantity path with a group', () => {
const path = new QuantityPath('?', new Path([ns.ex.measure, ns.ex.temperature]))

const expected = '(<http://example.org/measure>/<http://example.org/temperature>)?'

Expand Down
2 changes: 1 addition & 1 deletion test/Select.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import rdf from '@rdfjs/data-model'
import { describe, it } from 'mocha'
import Aggregate from '../lib/Aggregate.js'
Expand Down
28 changes: 0 additions & 28 deletions test/ZeroOrMorePath.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/smartAddPatterns.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'
import rdf from '@rdfjs/data-model'
import { describe, it } from 'mocha'
import Patterns from '../lib/Patterns.js'
Expand Down
2 changes: 1 addition & 1 deletion test/support/ignoreWhitespaceEqual.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert'
import { strictEqual } from 'node:assert'

function removeWhitespace (str) {
return str.toString().replace(/[\t\n\r ]+/g, ' ').trim()
Expand Down
Loading

0 comments on commit f202b0f

Please sign in to comment.