From 421f33adf08892d26f904cbe39491b5dd11edf31 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sun, 5 Jan 2025 05:22:51 -0300 Subject: [PATCH] array type unit tests --- test/unit/types/combinators/array/.gitignore | 1 + test/unit/types/combinators/array/ref/1.png | Bin 0 -> 70 bytes test/unit/types/combinators/array/test.typ | 17 +++++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 test/unit/types/combinators/array/.gitignore create mode 100644 test/unit/types/combinators/array/ref/1.png create mode 100644 test/unit/types/combinators/array/test.typ diff --git a/test/unit/types/combinators/array/.gitignore b/test/unit/types/combinators/array/.gitignore new file mode 100644 index 0000000..7ecdc7c --- /dev/null +++ b/test/unit/types/combinators/array/.gitignore @@ -0,0 +1 @@ +# added by typst-test diff --git a/test/unit/types/combinators/array/ref/1.png b/test/unit/types/combinators/array/ref/1.png new file mode 100644 index 0000000000000000000000000000000000000000..3690123d4a182de87c57b03c6945469af71fe1dd GIT binary patch literal 70 zcmeAS@N?(olHy`uVBq!ia0vp^j35jm7|ip2ssJfoPZ!6Kid&3K41fPKG%z$VG`@4# Q!UR&_>FVdQ&MBb@0J?n-d;kCd literal 0 HcmV?d00001 diff --git a/test/unit/types/combinators/array/test.typ b/test/unit/types/combinators/array/test.typ new file mode 100644 index 0000000..66084df --- /dev/null +++ b/test/unit/types/combinators/array/test.typ @@ -0,0 +1,17 @@ +#import "/test/unit/base.typ": empty, type-assert-eq, unwrap +#show: empty + +#import "/src/lib.typ": types +#import types: exact, literal, ok, err, native +#import "/src/types/types.typ": cast, validate, default + +#assert.eq(cast((), types.array(int)), ok(())) +#assert.eq(cast((5pt, 6%), types.array(relative)), ok((5pt + 0%, 0pt + 6%))) +#type-assert-eq(unwrap(cast((5pt, 6%), types.array(relative))).at(0), relative) +#assert.eq(cast((5.0, 6.0, "abc"), types.array(float)), err("an element in an array of float did not typecheck\n hint: at position 2: expected float or integer, found string")) +#assert.eq(cast((5,), types.array(float)), ok((5.0,))) +#type-assert-eq(unwrap(cast((5,), types.array(float))).first(), float) +#assert.eq(cast(("abc", "abc", "def"), types.array(types.union("abc", "def"))), ok(("abc", "abc", "def"))) +#assert.eq(cast(("abc", "abc", "defg"), types.array(types.union("abc", "def"))).first(), false) + +#assert.eq(default(types.array(types.union(float, int, color))), (true, ()))