summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/src/benches.rs3
-rw-r--r--tests/src/tests.rs4
-rw-r--r--tests/typ/compiler/bytes.typ21
-rw-r--r--tests/typ/compiler/string.typ3
-rw-r--r--tests/typ/compute/calc.typ4
-rw-r--r--tests/typ/compute/construct.typ2
6 files changed, 28 insertions, 9 deletions
diff --git a/tests/src/benches.rs b/tests/src/benches.rs
index 524fda19..a100e24e 100644
--- a/tests/src/benches.rs
+++ b/tests/src/benches.rs
@@ -1,11 +1,10 @@
use comemo::{Prehashed, Track, Tracked};
use iai::{black_box, main, Iai};
use typst::diag::FileResult;
-use typst::eval::{Datetime, Library, Tracer};
+use typst::eval::{Bytes, Datetime, Library, Tracer};
use typst::font::{Font, FontBook};
use typst::geom::Color;
use typst::syntax::{FileId, Source};
-use typst::util::Bytes;
use typst::World;
use unscanny::Scanner;
diff --git a/tests/src/tests.rs b/tests/src/tests.rs
index f7eceead..51823361 100644
--- a/tests/src/tests.rs
+++ b/tests/src/tests.rs
@@ -22,11 +22,11 @@ use walkdir::WalkDir;
use typst::diag::{bail, FileError, FileResult, Severity, StrResult};
use typst::doc::{Document, Frame, FrameItem, Meta};
-use typst::eval::{eco_format, func, Datetime, Library, NoneValue, Tracer, Value};
+use typst::eval::{eco_format, func, Bytes, Datetime, Library, NoneValue, Tracer, Value};
use typst::font::{Font, FontBook};
use typst::geom::{Abs, Color, RgbaColor, Smart};
use typst::syntax::{FileId, Source, Span, SyntaxNode};
-use typst::util::{Bytes, PathExt};
+use typst::util::PathExt;
use typst::World;
use typst_library::layout::{Margin, PageElem};
use typst_library::text::{TextElem, TextSize};
diff --git a/tests/typ/compiler/bytes.typ b/tests/typ/compiler/bytes.typ
new file mode 100644
index 00000000..32d0d573
--- /dev/null
+++ b/tests/typ/compiler/bytes.typ
@@ -0,0 +1,21 @@
+// Test the bytes type.
+// Ref: false
+
+---
+#let data = read("/files/rhino.png", encoding: none)
+#test(data.len(), 232243)
+#test(data.slice(0, count: 5), bytes((137, 80, 78, 71, 13)))
+#test(str(data.slice(1, 4)), "PNG")
+#test(repr(data), "bytes(232243)")
+
+---
+#test(str(bytes(range(0x41, 0x50))), "ABCDEFGHIJKLMNO")
+#test(array(bytes("Hello")), (0x48, 0x65, 0x6C, 0x6C, 0x6F))
+
+---
+// Error: 8-14 expected string, array, or bytes, found dictionary
+#bytes((a: 1))
+
+---
+// Error: 8-15 expected bytes or array, found string
+#array("hello")
diff --git a/tests/typ/compiler/string.typ b/tests/typ/compiler/string.typ
index c4c1669e..4241361a 100644
--- a/tests/typ/compiler/string.typ
+++ b/tests/typ/compiler/string.typ
@@ -41,8 +41,7 @@
#"Hello".at(5)
---
-// Error: 25-32 expected string, found dictionary
-#"Hello".at(5, default: (a: 10))
+#test("Hello".at(5, default: (a: 10)), (a: 10))
---
// Test the `slice` method.
diff --git a/tests/typ/compute/calc.typ b/tests/typ/compute/calc.typ
index cd97dfab..bdaf28a7 100644
--- a/tests/typ/compute/calc.typ
+++ b/tests/typ/compute/calc.typ
@@ -18,11 +18,11 @@
#test(calc.round(calc.pi, digits: 2), 3.14)
---
-// Error: 6-10 expected boolean, integer, float, or string, found length
+// Error: 6-10 expected boolean, float, string, or integer, found length
#int(10pt)
---
-// Error: 8-13 expected boolean, integer, float, ratio, or string, found function
+// Error: 8-13 expected boolean, integer, ratio, string, or float, found function
#float(float)
---
diff --git a/tests/typ/compute/construct.typ b/tests/typ/compute/construct.typ
index ddd4c591..ea9d2816 100644
--- a/tests/typ/compute/construct.typ
+++ b/tests/typ/compute/construct.typ
@@ -103,7 +103,7 @@
#test(str(10 / 3).len() > 10, true)
---
-// Error: 6-8 expected integer, float, label, or string, found content
+// Error: 6-8 expected integer, float, label, bytes, or string, found content
#str([])
---