Skip to content

Commit

Permalink
add test for result details
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomociti committed Apr 11, 2024
1 parent 5257789 commit 3f77cc9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test/data/validation-details/node-constraint-details.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <https://example.org/> .

ex:person1 a ex:Person .
[] a ex:Person .

ex:personShape a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:node [ sh:nodeKind sh:BlankNode ] .
32 changes: 32 additions & 0 deletions test/validation_details_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-env mocha */
import path from 'path'
import assert from 'assert'
import * as url from 'url'
import RDF from '@zazuko/env-node'
import SHACLValidator from '../index.js'
import { loadDataset } from './utils.js'

const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const rootPath = path.join(__dirname, '/data/validation-details')

describe('validation details', () => {
it('creates detail for node constraint', async () => {
const data = await loadDataset(path.join(rootPath, 'node-constraint-details.ttl'))
const shapes = data

const validator = new SHACLValidator(shapes)
const report = validator.validate(data)

assert.equal(1, report.results.length)
const result = report.results[0]
assert.deepStrictEqual(result.sourceConstraintComponent, RDF.ns.sh.NodeConstraintComponent)
assert.deepStrictEqual(result.focusNode, RDF.namedNode('https://example.org/person1'))
assert.deepStrictEqual(result.value, RDF.namedNode('https://example.org/person1'))

assert.equal(1, result.detail.length)
const detail = result.detail[0]
assert.deepStrictEqual(detail.sourceConstraintComponent, RDF.ns.sh.NodeKindConstraintComponent)
assert.deepStrictEqual(detail.focusNode, RDF.namedNode('https://example.org/person1'))
assert.deepStrictEqual(detail.value, RDF.namedNode('https://example.org/person1'))
})
})
2 changes: 1 addition & 1 deletion test/validation_repro.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const rootPath = path.join(__dirname, '/data/validation-repro')

describe('validation repro', () => {
it.only('repro #125', async () => {
it('repro #125', async () => {
const data = await loadDataset(path.join(rootPath, 'repro125-data.ttl'))
const shapes = await loadDataset(path.join(rootPath, 'repro125-shapes.ttl'))

Expand Down

0 comments on commit 3f77cc9

Please sign in to comment.