@@ -42,4 +42,37 @@ let trailerLen = 2 * blocksize
4242 func testOctal11( input: Int , expected: String ) async throws {
4343 #expect( octal11 ( input) == expected)
4444 }
45+
46+ @Test func testUInt8writeString( ) async throws {
47+ // Fill the buffer with 0xFF to show null termination
48+ var hdr = [ UInt8] ( repeating: 255 , count: 21 )
49+
50+ // The typechecker timed out when these test cases were passed as arguments, in the style of the octal tests
51+ hdr. writeString ( " abc " , inField: 0 ..< 5 , withTermination: . none)
52+ #expect(
53+ hdr == [
54+ 97 , 98 , 99 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
55+ ]
56+ )
57+
58+ hdr. writeString ( " def " , inField: 3 ..< 7 , withTermination: . null)
59+ #expect(
60+ hdr == [ 97 , 98 , 99 , 100 , 101 , 102 , 0 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ]
61+ )
62+
63+ hdr. writeString ( " ghi " , inField: 7 ..< 11 , withTermination: . space)
64+ #expect(
65+ hdr == [ 97 , 98 , 99 , 100 , 101 , 102 , 0 , 103 , 104 , 105 , 32 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ]
66+ )
67+
68+ hdr. writeString ( " jkl " , inField: 11 ..< 16 , withTermination: . nullAndSpace)
69+ #expect(
70+ hdr == [ 97 , 98 , 99 , 100 , 101 , 102 , 0 , 103 , 104 , 105 , 32 , 106 , 107 , 108 , 0 , 32 , 255 , 255 , 255 , 255 , 255 ]
71+ )
72+
73+ hdr. writeString ( " mno " , inField: 16 ..< 21 , withTermination: . spaceAndNull)
74+ #expect(
75+ hdr == [ 97 , 98 , 99 , 100 , 101 , 102 , 0 , 103 , 104 , 105 , 32 , 106 , 107 , 108 , 0 , 32 , 109 , 110 , 111 , 32 , 0 ]
76+ )
77+ }
4578}
0 commit comments