Skip to content

Commit

Permalink
array type unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PgBiel committed Jan 5, 2025
1 parent d4e29d8 commit 421f33a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/unit/types/combinators/array/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# added by typst-test
Binary file added test/unit/types/combinators/array/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions test/unit/types/combinators/array/test.typ
Original file line number Diff line number Diff line change
@@ -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, ()))

0 comments on commit 421f33a

Please sign in to comment.