Skip to content

Commit

Permalink
test datatype inference with strange, random values (#1559)
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomociti authored Nov 26, 2024
1 parent f0f22a9 commit dd7b1c1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"alcaeus": "^2",
"chai": "^4.3.4",
"mocha": "^10",
"mocha-chai-rdf": "^0.1.5"
"mocha-chai-rdf": "^0.1.5",
"fast-check": "^3.3.0"
}
}
16 changes: 16 additions & 0 deletions packages/model/test/lib/datatypeInference.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import { describe, it } from 'mocha'
import { expect } from 'chai'
import { xsd } from '@tpluscode/rdf-ns-builders'
import * as fc from 'fast-check'
import { inferDatatype } from '../../lib/datatypeInference'

describe('datatypeInference for strange values', () => {
it('recognize strange values', () => {
expect(inferDatatype(['4^2'])).to.eq(xsd.string)
expect(inferDatatype(['4.2.1'])).to.eq(xsd.string)
expect(inferDatatype(['*&^%'])).to.eq(xsd.string)
expect(inferDatatype(['4%2'])).to.eq(xsd.string)
})

it('recognize random values', () => {
fc.assert(fc.property(fc.string(), value => {
expect(inferDatatype([value])).to.have.property('termType', 'NamedNode')
}))
})
})

describe('@cube-creator/model/DatatypeChecker', () => {
it('recognize xsd:integer', () => {
expect(inferDatatype(['42'])).to.eq(xsd.integer)
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8399,6 +8399,13 @@ extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.1.tgz#8d172c064867f235c0c84a596806d279bf4bcc07"
integrity sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA==

fast-check@^3.3.0:
version "3.23.1"
resolved "https://registry.yarnpkg.com/fast-check/-/fast-check-3.23.1.tgz#a25f5c0f6a58f92f2a68cb7dfe1476054329ea3f"
integrity sha512-u/MudsoQEgBUZgR5N1v87vEgybeVYus9VnDVaIkxkkGP2jt54naghQ3PCQHJiogS8U/GavZCUPFfx3Xkp+NaHw==
dependencies:
pure-rand "^6.1.0"

fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
Expand Down Expand Up @@ -12824,6 +12831,11 @@ punycode@^2.1.0, punycode@^2.1.1:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==

pure-rand@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/pure-rand/-/pure-rand-6.1.0.tgz#d173cf23258231976ccbdb05247c9787957604f2"
integrity sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==

qr-creator@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/qr-creator/-/qr-creator-1.0.0.tgz#f350a8f0b5be02bd1fc1ef133a038a06ef8bc5ef"
Expand Down

0 comments on commit dd7b1c1

Please sign in to comment.