import * as types from 'quickjs:types-in-exports/types';
function as_result(f) {
try {
const result = f();
return { tag: 'ok', val: result };
} catch (error) {
return { tag: 'err', val: error };
}
}
export const test = () => {
console.log(`f1: ${types.f1([0.1, 0.2, 0.3], ["a", "b"], ["c", "d"])}`);
console.log(`f2: ${types.f2("hello world")}`);
console.log(`f3: ${types.f3(true, -8, -16, -32, -64n, 8, 16, 32, 64n, 3.14, 2.718281828459045, 'c', "hello world")}`);
console.log(`f4: ${JSON.stringify(as_result(() => types.f4({tag: 'ok', val: 42})))}`);
console.log(`f5: ${JSON.stringify(as_result(() => types.f5({tag: 'err', val: 'error message'})))}`);
console.log(`f6: ${JSON.stringify(as_result(() => types.f6({tag: 'ok', val: 'success'})))}`);
console.log(`f7: ${JSON.stringify(as_result(() => types.f7({tag: 'ok'})))}`);
console.log(`f8: ${types.f8(['example', 123, 4.56])}`);
const f9 = types.f9({
a: "test",
b: 42,
c: 3.14,
d: {x: 1, y: 2},
e: undefined,
f: {tag: 'ok', val: 100},
g: [],
h: ['one', 'two'],
i: ['tuple', 1, 2.5]
});
console.log(`f9: ${JSON.stringify(f9)}`);
const f10 = types.f10({
tag: 'specific',
val: 'example'
});
console.log(`f10: ${JSON.stringify(f10)}`);
const f11 = types.f11('blue');
console.log(`f11: ${f11}`);
const f12 = types.f12('green');
console.log(`f12: ${JSON.stringify(f12)}`);
const f13 = types.f13({read: true, write: false, execute: true});
console.log(`f13: ${JSON.stringify(f13)}`);
const f14 = types.f14(1234567890n);
console.log(`f14: ${f14}`);
const f15 = types.f15(new Uint8Array([1, 2, 3, 4, 5]));
console.log(`f15: ${f15}`);
if (f15 instanceof Uint8Array) {
console.log(`f15 is a Uint8Array with length: ${f15.length}`);
}
};