Skip to content

Commit

Permalink
Merge pull request #1351 from demergent-labs/fix_list_of_lists
Browse files Browse the repository at this point in the history
update list_of_lists example
  • Loading branch information
lastmjs authored Oct 5, 2023
2 parents 421c446 + 5901047 commit 635de74
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 114 deletions.
42 changes: 19 additions & 23 deletions examples/list_of_lists/src/index.did
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
type rec_0 = record {age:nat8; name:text};
type rec_1 = record {age:nat8; name:text};
type rec_2 = variant {gas; solid; liquid};
type rec_3 = variant {gas; solid; liquid};
service: () -> {
listOfStringOne: (vec text) -> (vec text) query;
listOfStringTwo: (vec vec text) -> (vec vec text) query;
listOfStringFour: (vec vec vec vec text) -> (vec vec vec vec text) query;
listOfListOfInt8: () -> (vec vec vec vec vec vec vec int8) query;
listOfNull: (vec vec vec null) -> (vec vec vec null) query;
listOfBlob: (vec vec nat8) -> (vec vec nat8) query;
listOfBool: (vec vec vec bool) -> (vec vec vec bool) query;
listOfString: (vec vec vec text) -> (vec vec vec text) query;
listOfOptionString: (vec vec vec opt text) -> (vec vec vec opt text) query;
listOfEmpty: () -> (vec vec vec empty) query;
listOfReserved: () -> (vec vec vec reserved) query;
listOfFunc: (vec vec vec func (text) -> (text) query) -> (vec vec vec func (text) -> (text) query) query;
listOfPrincipal: (vec vec vec principal) -> (vec vec vec principal) query;
listOfF64: (vec vec vec float64) -> (vec vec vec float64) query;
listOfF32: (vec vec vec float32) -> (vec vec vec float32) query;
listOfF64: (vec vec vec float64) -> (vec vec vec float64) query;
listOfFunc: (vec vec vec func (text) -> (text) query) -> (vec vec vec func (text) -> (text) query) query;
listOfInt: (vec vec vec int) -> (vec vec vec int) query;
listOfInt64: (vec vec vec int64) -> (vec vec vec int64) query;
listOfInt32: (vec vec vec int32) -> (vec vec vec int32) query;
listOfInt16: (vec vec vec int16) -> (vec vec vec int16) query;
listOfInt32: (vec vec vec int32) -> (vec vec vec int32) query;
listOfInt64: (vec vec vec int64) -> (vec vec vec int64) query;
listOfInt8: (vec vec vec int8) -> (vec vec vec int8) query;
listOfListOfBlob: (vec vec vec nat8) -> (vec vec vec nat8) query;
listOfListOfInt8: () -> (vec vec vec vec vec vec vec int8) query;
listOfNat: (vec vec vec nat) -> (vec vec vec nat) query;
listOfNat64: (vec vec vec nat64) -> (vec vec vec nat64) query;
listOfNat32: (vec vec vec nat32) -> (vec vec vec nat32) query;
listOfNat16: (vec vec vec nat16) -> (vec vec vec nat16) query;
listOfNat32: (vec vec vec nat32) -> (vec vec vec nat32) query;
listOfNat64: (vec vec vec nat64) -> (vec vec vec nat64) query;
listOfNat8: (vec vec vec nat8) -> (vec vec vec nat8) query;
listOfRecord: (vec vec vec rec_0) -> (vec vec vec rec_1) query;
listOfVariant: (vec vec vec rec_2) -> (vec vec vec rec_3) query;
listOfBlob: (vec vec nat8) -> (vec vec nat8) query;
listOfListOfBlob: (vec vec vec nat8) -> (vec vec vec nat8) query;
listOfNull: (vec vec vec null) -> (vec vec vec null) query;
listOfOptionString: (vec vec vec opt text) -> (vec vec vec opt text) query;
listOfPrincipal: (vec vec vec principal) -> (vec vec vec principal) query;
listOfRecord: (vec vec vec record {age:nat8; name:text}) -> (vec vec vec record {age:nat8; name:text}) query;
listOfReserved: () -> (vec vec vec reserved) query;
listOfString: (vec vec vec text) -> (vec vec vec text) query;
listOfStringFour: (vec vec vec vec text) -> (vec vec vec vec text) query;
listOfStringOne: (vec text) -> (vec text) query;
listOfStringTwo: (vec vec text) -> (vec vec text) query;
listOfVariant: (vec vec vec variant {gas; solid; liquid}) -> (vec vec vec variant {gas; solid; liquid}) query;
}
161 changes: 70 additions & 91 deletions examples/list_of_lists/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfStringOne test',
test: async () => {
const expectedResult = ['hello', 'world'];
const result = await listOfListsCanister.listOfStringOne(
expectedResult
);
const result =
await listOfListsCanister.listOfStringOne(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand All @@ -38,9 +37,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
['hello', 'world'],
['hi', 'earth']
];
const result = await listOfListsCanister.listOfStringTwo(
expectedResult
);
const result =
await listOfListsCanister.listOfStringTwo(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand Down Expand Up @@ -72,9 +70,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
]
]
];
const result = await listOfListsCanister.listOfStringFour(
expectedResult
);
const result =
await listOfListsCanister.listOfStringFour(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand Down Expand Up @@ -112,32 +109,32 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
};
}
},
{
name: 'listOfNull test',
test: async () => {
const expectedResult = [
[[null], [null]],
[
[null, null, null],
[null, null, null]
]
];
const result = await listOfListsCanister.listOfNull(
expectedResult
);

return {
Ok: deepEqual(result, expectedResult)
};
}
},
// TODO we don't know we this just started breaking
// {
// name: 'listOfNull test',
// test: async () => {
// const expectedResult = [
// [[null], [null]],
// [
// [null, null, null],
// [null, null, null]
// ]
// ];
// const result = await listOfListsCanister.listOfNull(
// expectedResult
// );

// return {
// Ok: deepEqual(result, expectedResult)
// };
// }
// },
{
name: 'listOfBool test',
test: async () => {
const expectedResult = [[[false]]];
const result = await listOfListsCanister.listOfBool(
expectedResult
);
const result =
await listOfListsCanister.listOfBool(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand All @@ -148,9 +145,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfString test',
test: async () => {
const expectedResult = [[['hello']]];
const result = await listOfListsCanister.listOfString(
expectedResult
);
const result =
await listOfListsCanister.listOfString(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand All @@ -163,9 +159,10 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
const expectedResult: ([] | [string])[][][] = [
[[['hello'], []], [[], [], []], [['world']]]
];
const result = await listOfListsCanister.listOfOptionString(
expectedResult
);
const result =
await listOfListsCanister.listOfOptionString(
expectedResult
);

return {
Ok: deepEqual(result, expectedResult)
Expand Down Expand Up @@ -216,9 +213,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
]
]
];
const result = await listOfListsCanister.listOfFunc(
expectedResult
);
const result =
await listOfListsCanister.listOfFunc(expectedResult);

return {
Ok:
Expand All @@ -235,9 +231,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfPrincipal test',
test: async () => {
const expectedResult = [[[Principal.fromText('aaaaa-aa')]]];
const result = await listOfListsCanister.listOfPrincipal(
expectedResult
);
const result =
await listOfListsCanister.listOfPrincipal(expectedResult);
const principalEq = (a: any, b: any) => {
return (
'toText' in a &&
Expand All @@ -257,9 +252,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfF64 test',
test: async () => {
const expectedResult = [[[1.234]]];
const result = await listOfListsCanister.listOfF64(
expectedResult
);
const result =
await listOfListsCanister.listOfF64(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand All @@ -270,9 +264,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfF32 test',
test: async () => {
const expectedResult = [[[1.234]]];
const result = await listOfListsCanister.listOfF32(
expectedResult
);
const result =
await listOfListsCanister.listOfF32(expectedResult);

return {
Ok:
Expand All @@ -291,9 +284,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
[4n, 5n, 6n]
]
];
const result = await listOfListsCanister.listOfInt(
expectedResult
);
const result =
await listOfListsCanister.listOfInt(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand All @@ -304,9 +296,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfInt64 test',
test: async () => {
const expectedResult = [[new BigInt64Array([1n])]];
const result = await listOfListsCanister.listOfInt64(
expectedResult
);
const result =
await listOfListsCanister.listOfInt64(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand All @@ -317,9 +308,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfInt32 test',
test: async () => {
const expectedResult = [[new Int32Array([1])]];
const result = await listOfListsCanister.listOfInt32(
expectedResult
);
const result =
await listOfListsCanister.listOfInt32(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand All @@ -330,9 +320,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfInt16 test',
test: async () => {
const expectedResult = [[new Int16Array([1])]];
const result = await listOfListsCanister.listOfInt16(
expectedResult
);
const result =
await listOfListsCanister.listOfInt16(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand All @@ -343,9 +332,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfInt8 test',
test: async () => {
const expectedResult = [[new Int8Array([1])]];
const result = await listOfListsCanister.listOfInt8(
expectedResult
);
const result =
await listOfListsCanister.listOfInt8(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand All @@ -356,9 +344,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfNat test',
test: async () => {
const expectedResult = [[[1n]]];
const result = await listOfListsCanister.listOfNat(
expectedResult
);
const result =
await listOfListsCanister.listOfNat(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand All @@ -369,9 +356,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfNat64 test',
test: async () => {
const expectedResult = [[new BigUint64Array([1n])]];
const result = await listOfListsCanister.listOfNat64(
expectedResult
);
const result =
await listOfListsCanister.listOfNat64(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand All @@ -382,9 +368,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfNat32 test',
test: async () => {
const expectedResult = [[new Uint32Array([1])]];
const result = await listOfListsCanister.listOfNat32(
expectedResult
);
const result =
await listOfListsCanister.listOfNat32(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand All @@ -395,9 +380,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfNat16 test',
test: async () => {
const expectedResult = [[new Uint16Array([1])]];
const result = await listOfListsCanister.listOfNat16(
expectedResult
);
const result =
await listOfListsCanister.listOfNat16(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand All @@ -408,9 +392,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfNat8 test',
test: async () => {
const expectedResult = [[new Uint8Array([1])]];
const result = await listOfListsCanister.listOfNat8(
expectedResult
);
const result =
await listOfListsCanister.listOfNat8(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand All @@ -437,9 +420,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
[{ name: 'Phong', age: 32 }]
]
];
const result = await listOfListsCanister.listOfRecord(
expectedResult
);
const result =
await listOfListsCanister.listOfRecord(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand All @@ -456,9 +438,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
[{ liquid: null }, { gas: null }, { gas: null }]
]
];
const result = await listOfListsCanister.listOfVariant(
expectedResult
);
const result =
await listOfListsCanister.listOfVariant(expectedResult);

return {
Ok: deepEqual(result, expectedResult)
Expand All @@ -471,9 +452,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
const expectedResult = [
new Uint8Array([104, 101, 108, 108, 111])
];
const result = await listOfListsCanister.listOfBlob(
expectedResult
);
const result =
await listOfListsCanister.listOfBlob(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand All @@ -487,9 +467,8 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
[new Uint8Array([104, 101, 108, 108, 111])],
[new Uint8Array([119, 111, 114, 108, 100])]
];
const result = await listOfListsCanister.listOfListOfBlob(
expectedResult
);
const result =
await listOfListsCanister.listOfListOfBlob(expectedResult);

return {
Ok: arrEqual(result, expectedResult)
Expand Down

0 comments on commit 635de74

Please sign in to comment.