@@ -256,3 +256,26 @@ Base.codepoint(c::ASCIIChar) = reinterpret(UInt8, c)
256
256
@test_throws MethodError write (IOBuffer (), ASCIIChar (' x' ))
257
257
@test_throws MethodError read (IOBuffer (' x' ), ASCIIChar)
258
258
end
259
+
260
+ @testset " ncodeunits(::Char)" begin
261
+ # valid encodings
262
+ @test ncodeunits (' \0 ' ) == 1
263
+ @test ncodeunits (' \x 1' ) == 1
264
+ @test ncodeunits (' \x 7f' ) == 1
265
+ @test ncodeunits (' \u 80' ) == 2
266
+ @test ncodeunits (' \u ff' ) == 2
267
+ @test ncodeunits (' \u 7ff' ) == 2
268
+ @test ncodeunits (' \u 800' ) == 3
269
+ @test ncodeunits (' \u ffff' ) == 3
270
+ @test ncodeunits (' \U 10000' ) == 4
271
+ @test ncodeunits (' \U 10ffff' ) == 4
272
+ # invalid encodings
273
+ @test ncodeunits (reinterpret (Char, 0x80_00_00_00 )) == 1
274
+ @test ncodeunits (reinterpret (Char, 0x81_00_00_00 )) == 1
275
+ @test ncodeunits (reinterpret (Char, 0x80_80_00_00 )) == 2
276
+ @test ncodeunits (reinterpret (Char, 0x80_01_00_00 )) == 2
277
+ @test ncodeunits (reinterpret (Char, 0x80_00_80_00 )) == 3
278
+ @test ncodeunits (reinterpret (Char, 0x80_00_01_00 )) == 3
279
+ @test ncodeunits (reinterpret (Char, 0x80_00_00_80 )) == 4
280
+ @test ncodeunits (reinterpret (Char, 0x80_00_00_01 )) == 4
281
+ end
0 commit comments