Skip to content

Commit

Permalink
TypeScript: add definition tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Sep 12, 2024
1 parent 0ff54cb commit d8e8f70
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
30 changes: 30 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import farmhash from '.';

const testString: string = 'test';
const testBuffer: Buffer = Buffer.from(testString);
const testSeed1: number = 1;
const testSeed2: number = 2;

const f32s: number = farmhash.fingerprint32(testString);
const f32b: number = farmhash.fingerprint32(testBuffer);

const f64s: bigint = farmhash.fingerprint64(testString);
const f64b: bigint = farmhash.fingerprint64(testBuffer);

const f64ss: bigint = farmhash.fingerprint64signed(testString);
const f64sb: bigint = farmhash.fingerprint64signed(testBuffer);

const h32s: number = farmhash.hash32(testString);
const h32b: number = farmhash.hash32(testBuffer);

const h32ss: number = farmhash.hash32WithSeed(testString, testSeed1);
const h32sb: number = farmhash.hash32WithSeed(testBuffer, testSeed1);

const h64s: bigint = farmhash.hash64(testString);
const h64b: bigint = farmhash.hash64(testBuffer);

const h64ss: bigint = farmhash.hash64WithSeed(testString, testSeed1);
const h64sb: bigint = farmhash.hash64WithSeed(testBuffer, testSeed1);

const h64sss: bigint = farmhash.hash64WithSeeds(testString, testSeed1, testSeed2);
const h64ssb: bigint = farmhash.hash64WithSeeds(testBuffer, testSeed1, testSeed2);
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"description": "Node.js implementation of FarmHash, Google's family of very fast hash functions",
"scripts": {
"install": "prebuild-install || node-gyp rebuild",
"test": "semistandard && cpplint && node test/unit"
"test": "semistandard && cpplint && node test/unit && tsd"
},
"main": "index.js",
"files": [
Expand All @@ -33,10 +33,12 @@
"prebuild-install": "^7.1.2"
},
"devDependencies": {
"@types/node": "*",
"cc": "^3.0.1",
"node-gyp": "^10.2.0",
"prebuild": "^13.0.1",
"semistandard": "^17.0.0"
"semistandard": "^17.0.0",
"tsd": "^0.31.2"
},
"license": "Apache-2.0",
"engines": {
Expand Down

0 comments on commit d8e8f70

Please sign in to comment.