-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from rdf-ext/path-lint-test
feat: use path groups when required, added path tests, code formating
- Loading branch information
Showing
15 changed files
with
232 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import Node from './Node.js' | ||
import termOrNodeToString from './utils/termOrNodeToString.js' | ||
import termOrNodeToPathString from './utils/termOrNodeToPathString.js' | ||
|
||
class Pattern extends Node { | ||
class AlternativePath extends Node { | ||
constructor (elements) { | ||
super({ type: 'AlternativePath' }) | ||
|
||
this.attr.elements = elements | ||
} | ||
|
||
toStringStart () { | ||
return this.attr.elements.map(element => termOrNodeToString(element)).join('|') | ||
return this.attr.elements.map(element => termOrNodeToPathString(element)).join('|') | ||
} | ||
} | ||
|
||
export default Pattern | ||
export default AlternativePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import Node from './Node.js' | ||
import termOrNodeToString from './utils/termOrNodeToString.js' | ||
import termOrNodeToPathString from './utils/termOrNodeToPathString.js' | ||
|
||
class Pattern extends Node { | ||
class InversePath extends Node { | ||
constructor (element) { | ||
super({ type: 'InversePath' }) | ||
|
||
this.attr.element = element | ||
} | ||
|
||
toStringStart () { | ||
return ['^', termOrNodeToString(this.attr.element)].join('') | ||
return ['^', termOrNodeToPathString(this.attr.element)].join('') | ||
} | ||
} | ||
|
||
export default Pattern | ||
export default InversePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import Node from './Node.js' | ||
import termOrNodeToString from './utils/termOrNodeToString.js' | ||
|
||
class Pattern extends Node { | ||
class NegatedPropertySet extends Node { | ||
constructor (element) { | ||
super({ type: 'NegatedPropertySet' }) | ||
|
||
this.attr.element = element | ||
} | ||
|
||
toStringStart () { | ||
return ['!(', | ||
termOrNodeToString(this.attr.element), | ||
')'].join('') | ||
if (Array.isArray(this.attr.element)) { | ||
return [ | ||
'!(', | ||
this.attr.element.map(element => termOrNodeToString(element)).join('|'), | ||
')' | ||
].join('') | ||
} | ||
|
||
return ['!', termOrNodeToString(this.attr.element)].join('') | ||
} | ||
} | ||
|
||
export default Pattern | ||
export default NegatedPropertySet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import Node from './Node.js' | ||
import termOrNodeToString from './utils/termOrNodeToString.js' | ||
import termOrNodeToPathString from './utils/termOrNodeToPathString.js' | ||
|
||
class Pattern extends Node { | ||
class OneOrMorePath extends Node { | ||
constructor (element) { | ||
super({ type: 'OneOrMorePath' }) | ||
|
||
this.attr.element = element | ||
} | ||
|
||
toStringStart () { | ||
return ['(', | ||
termOrNodeToString(this.attr.element), | ||
')+'].join('') | ||
return [termOrNodeToPathString(this.attr.element), '+'].join('') | ||
} | ||
} | ||
|
||
export default Pattern | ||
export default OneOrMorePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import Node from './Node.js' | ||
import termOrNodeToString from './utils/termOrNodeToString.js' | ||
import termOrNodeToPathString from './utils/termOrNodeToPathString.js' | ||
|
||
class Pattern extends Node { | ||
class ZeroOrMorePath extends Node { | ||
constructor (element) { | ||
super({ type: 'ZeroOrMorePath' }) | ||
|
||
this.attr.element = element | ||
} | ||
|
||
toStringStart () { | ||
return ['(', | ||
termOrNodeToString(this.attr.element), | ||
')*'].join('') | ||
return [termOrNodeToPathString(this.attr.element), '*'].join('') | ||
} | ||
} | ||
|
||
export default Pattern | ||
export default ZeroOrMorePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import Node from './Node.js' | ||
import termOrNodeToString from './utils/termOrNodeToString.js' | ||
import termOrNodeToPathString from './utils/termOrNodeToPathString.js' | ||
|
||
class Pattern extends Node { | ||
class ZeroOrOnePath extends Node { | ||
constructor (element) { | ||
super({ type: 'ZeroOrOnePath' }) | ||
|
||
this.attr.element = element | ||
} | ||
|
||
toStringStart () { | ||
return ['(', | ||
termOrNodeToString(this.attr.element), | ||
')?'].join('') | ||
return [termOrNodeToPathString(this.attr.element), '?'].join('') | ||
} | ||
} | ||
|
||
export default Pattern | ||
export default ZeroOrOnePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import toNT from '@rdfjs/to-ntriples' | ||
|
||
function termOrNodeToPathString (termOrNode) { | ||
return (termOrNode.termType && toNT(termOrNode)) || `(${termOrNode.toString()})` | ||
} | ||
|
||
export default termOrNodeToPathString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { strictEqual } from 'assert' | ||
import { describe, it } from 'mocha' | ||
import AlternativePath from '../lib/AlternativePath.js' | ||
import Path from '../lib/Path.js' | ||
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js' | ||
import ns from './support/namespace.js' | ||
|
||
describe('AlternativePath', () => { | ||
it('should be a constructor', () => { | ||
strictEqual(typeof AlternativePath, 'function') | ||
}) | ||
|
||
it('should create an alternative path', () => { | ||
const path = new AlternativePath([ns.ex.measure, ns.ex.temperature]) | ||
|
||
const expected = '<http://example.org/measure>|<http://example.org/temperature>' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
|
||
it('should create an alternative path with a group', () => { | ||
const path = new AlternativePath([ | ||
ns.ex.temperature, | ||
new Path([ns.ex.measure, ns.ex.temperature]) | ||
]) | ||
|
||
const expected = '<http://example.org/temperature>|(<http://example.org/measure>/<http://example.org/temperature>)' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { strictEqual } from 'assert' | ||
import { describe, it } from 'mocha' | ||
import InversePath from '../lib/InversePath.js' | ||
import Path from '../lib/Path.js' | ||
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js' | ||
import ns from './support/namespace.js' | ||
|
||
describe('InversePath', () => { | ||
it('should be a constructor', () => { | ||
strictEqual(typeof InversePath, 'function') | ||
}) | ||
|
||
it('should create an inverse path', () => { | ||
const path = new InversePath(ns.ex.measure) | ||
|
||
const expected = '^<http://example.org/measure>' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
|
||
it('should create an inverse path with a group', () => { | ||
const path = new InversePath(new Path([ns.ex.measure, ns.ex.temperature])) | ||
|
||
const expected = '^(<http://example.org/measure>/<http://example.org/temperature>)' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { strictEqual } from 'assert' | ||
import { describe, it } from 'mocha' | ||
import InversePath from '../lib/InversePath.js' | ||
import NegatedPropertySet from '../lib/NegatedPropertySet.js' | ||
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js' | ||
import ns from './support/namespace.js' | ||
|
||
describe('NegatedPropertySet', () => { | ||
it('should be a constructor', () => { | ||
strictEqual(typeof NegatedPropertySet, 'function') | ||
}) | ||
|
||
it('should create a negated property set', () => { | ||
const path = new NegatedPropertySet(ns.ex.measure) | ||
|
||
const expected = '!<http://example.org/measure>' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
|
||
it('should create an negated property set multiple paths', () => { | ||
const path = new NegatedPropertySet([ | ||
ns.ex.measure, | ||
new InversePath(ns.ex.temperature) | ||
]) | ||
|
||
const expected = '!(<http://example.org/measure>|^<http://example.org/temperature>)' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { strictEqual } from 'assert' | ||
import { describe, it } from 'mocha' | ||
import OneOrMorePath from '../lib/OneOrMorePath.js' | ||
import Path from '../lib/Path.js' | ||
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js' | ||
import ns from './support/namespace.js' | ||
|
||
describe('OneOrMorePath', () => { | ||
it('should be a constructor', () => { | ||
strictEqual(typeof OneOrMorePath, 'function') | ||
}) | ||
|
||
it('should create a one or more path', () => { | ||
const path = new OneOrMorePath(ns.ex.measure) | ||
|
||
const expected = '<http://example.org/measure>+' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
|
||
it('should create a one or more path with a group', () => { | ||
const path = new OneOrMorePath(new Path([ns.ex.measure, ns.ex.temperature])) | ||
|
||
const expected = '(<http://example.org/measure>/<http://example.org/temperature>)+' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { strictEqual } from 'assert' | ||
import { describe, it } from 'mocha' | ||
import Path from '../lib/Path.js' | ||
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js' | ||
import ns from './support/namespace.js' | ||
|
||
describe('Path', () => { | ||
it('should be a constructor', () => { | ||
strictEqual(typeof Path, 'function') | ||
}) | ||
|
||
it('should create a sequence path', () => { | ||
const path = new Path([ns.ex.measure, ns.ex.temperature]) | ||
|
||
const expected = '<http://example.org/measure>/<http://example.org/temperature>' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { strictEqual } from 'assert' | ||
import { describe, it } from 'mocha' | ||
import Path from '../lib/Path.js' | ||
import ZeroOrMorePath from '../lib/ZeroOrMorePath.js' | ||
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js' | ||
import ns from './support/namespace.js' | ||
|
||
describe('ZeroOrMorePath', () => { | ||
it('should be a constructor', () => { | ||
strictEqual(typeof ZeroOrMorePath, 'function') | ||
}) | ||
|
||
it('should create a zero or more path', () => { | ||
const path = new ZeroOrMorePath(ns.ex.measure) | ||
|
||
const expected = '<http://example.org/measure>*' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
|
||
it('should create a zero or more path with a group', () => { | ||
const path = new ZeroOrMorePath(new Path([ns.ex.measure, ns.ex.temperature])) | ||
|
||
const expected = '(<http://example.org/measure>/<http://example.org/temperature>)*' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { strictEqual } from 'assert' | ||
import { describe, it } from 'mocha' | ||
import Path from '../lib/Path.js' | ||
import ZeroOrOnePath from '../lib/ZeroOrOnePath.js' | ||
import ignoreWhitespaceEqual from './support/ignoreWhitespaceEqual.js' | ||
import ns from './support/namespace.js' | ||
|
||
describe('ZeroOrOnePath', () => { | ||
it('should be a constructor', () => { | ||
strictEqual(typeof ZeroOrOnePath, 'function') | ||
}) | ||
|
||
it('should create a zero or one path', () => { | ||
const path = new ZeroOrOnePath(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])) | ||
|
||
const expected = '(<http://example.org/measure>/<http://example.org/temperature>)?' | ||
|
||
ignoreWhitespaceEqual(path, expected) | ||
}) | ||
}) |