Skip to content

Commit

Permalink
Add property tests for Tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
dansteren committed Oct 31, 2023
1 parent b866e23 commit 1d6a72b
Show file tree
Hide file tree
Showing 8 changed files with 1,396 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ jobs:
"property_tests/tests/principal",
"property_tests/tests/record",
"property_tests/tests/text",
"property_tests/tests/tuple",
"property_tests/tests/variant",
"property_tests/tests/vec"
]
Expand Down
29 changes: 29 additions & 0 deletions property_tests/arbitraries/candid/constructed/tuple_arb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import fc from 'fast-check';

import { Candid, CandidType, CandidTypeArb } from '..';
import { UniqueIdentifierArb } from '../../unique_identifier_arb';

export type Tuple = CandidType[];

export const TupleArb = fc
.tuple(UniqueIdentifierArb('typeDeclaration'), fc.array(CandidTypeArb))
.map(([name, fields]): Candid<Tuple> => {
const innerTypes = fields.map((field) => field.src.candidType);

const typeDeclaration = `const ${name} = Tuple(${innerTypes.join(
', '
)});`;

const imports = new Set([...innerTypes, 'Tuple']);

const value = fields.map((field) => field.value);

return {
src: {
candidType: name,
typeDeclaration,
imports
},
value
};
});
2 changes: 2 additions & 0 deletions property_tests/arbitraries/candid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type Candid<T> = {
};
};

export type CandidType = number | bigint | null;

/**
* An arbitrary representing all possible Candid types.
*
Expand Down
16 changes: 16 additions & 0 deletions property_tests/tests/tuple/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"canisters": {
"canister": {
"type": "custom",
"main": "src/index.ts",
"candid": "src/index.did",
"build": "npx azle canister",
"wasm": ".azle/canister/canister.wasm",
"gzip": true,
"declarations": {
"output": "test/dfx_generated/canister",
"node_compatibility": true
}
}
}
}
Loading

0 comments on commit 1d6a72b

Please sign in to comment.