Skip to content

Commit

Permalink
feat(int): Support basic int() type
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvdm authored and Justin van der Merwe committed Apr 22, 2020
1 parent 2370265 commit a9e2c1f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 194 deletions.
1 change: 1 addition & 0 deletions index.js
@@ -0,0 +1 @@
exports.int = require('./int')
7 changes: 7 additions & 0 deletions int.js
@@ -0,0 +1,7 @@
var hash = require('string-hash')
var stringify = require('fast-json-stable-stringify')

module.exports = function int (inputs) {
// todo: cache `inputs` using a WeakMap
return hash(stringify(inputs))
}
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -26,5 +26,9 @@
},
"devDependencies": {
"@oftherivier/tools": "^0.1.27"
},
"dependencies": {
"fast-json-stable-stringify": "^2.1.0",
"string-hash": "^1.1.3"
}
}
12 changes: 12 additions & 0 deletions tap-snapshots/tests-fictional.test.js-TAP.test.js
@@ -0,0 +1,12 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`tests/fictional.test.js TAP generated values > must match snapshot 1`] = `
Object {
"int": 5859428,
}
`
33 changes: 32 additions & 1 deletion tests/fictional.test.js
@@ -1,3 +1,34 @@
const fictional = require('..')
const tap = require('tap')

tap.equal(true, true)
const types = getTypes()

tap.test('generated values', t => {
t.matchSnapshot(callTypes(23))
t.end()
})

tap.test('consistency', t => {
let i = -1
const firstResult = callTypes(23)

while (++i < 100) {
t.deepEquals(callTypes(23), firstResult)
}

t.end()
})

function callTypes(input) {
const result = {}

for (const name of Object.keys(types)) {
result[name] = types[name](input)
}

return result
}

function getTypes() {
return fictional
}

0 comments on commit a9e2c1f

Please sign in to comment.