aboutsummaryrefslogtreecommitdiff
path: root/Tests/NorgKitTests/Helpers/ASCIIByteSetTests.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/NorgKitTests/Helpers/ASCIIByteSetTests.swift')
-rw-r--r--Tests/NorgKitTests/Helpers/ASCIIByteSetTests.swift42
1 files changed, 42 insertions, 0 deletions
diff --git a/Tests/NorgKitTests/Helpers/ASCIIByteSetTests.swift b/Tests/NorgKitTests/Helpers/ASCIIByteSetTests.swift
new file mode 100644
index 0000000..eb29ecb
--- /dev/null
+++ b/Tests/NorgKitTests/Helpers/ASCIIByteSetTests.swift
@@ -0,0 +1,42 @@
+import Testing
+
+@testable import NorgKit
+
+struct ASCIIByteSetTests {
+
+ @Test func containsLowBytes() {
+ // `*` (0x2A) and `-` (0x2D) live in the low 64-bit word.
+ let set = ASCIIByteSet("*-")
+ #expect(set.contains(UInt8(ascii: "*")))
+ #expect(set.contains(UInt8(ascii: "-")))
+ #expect(!set.contains(UInt8(ascii: "/")))
+ }
+
+ @Test func containsHighBytes() {
+ // `~` (0x7E) and `_` (0x5F) live in the high 64-bit word.
+ let set = ASCIIByteSet("~_")
+ #expect(set.contains(UInt8(ascii: "~")))
+ #expect(set.contains(UInt8(ascii: "_")))
+ #expect(!set.contains(UInt8(ascii: "x")))
+ }
+
+ @Test func spansBothWords() {
+ let set = ASCIIByteSet("*~")
+ #expect(set.contains(UInt8(ascii: "*")))
+ #expect(set.contains(UInt8(ascii: "~")))
+ }
+
+ @Test func rejectsNonAsciiAndOutOfSetBytes() {
+ let set = ASCIIByteSet("*")
+ #expect(!set.contains(0)) // NUL, low word, unset
+ #expect(!set.contains(200)) // beyond ASCII, never stored
+ #expect(!set.contains(127)) // high word, unset
+ }
+
+ @Test func emptySetContainsNothing() {
+ let set = ASCIIByteSet("")
+ #expect(!set.contains(UInt8(ascii: "*")))
+ #expect(!set.contains(0))
+ #expect(!set.contains(127))
+ }
+}