blob: eb29ecb95437b340807f3d415fd048143eac7403 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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))
}
}
|