From 501fdce29e4d2c46c4708ad7f44056878e0db3fa Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Tue, 16 Jun 2026 12:08:21 +0200 Subject: Initial extraction from Norganize --- Tests/NorgKitTests/Helpers/ASCIIByteSetTests.swift | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Tests/NorgKitTests/Helpers/ASCIIByteSetTests.swift (limited to 'Tests/NorgKitTests/Helpers/ASCIIByteSetTests.swift') 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)) + } +} -- cgit