| ... | ... | @@ -706,41 +706,52 @@ fn calcUtf16LeLen(utf8: []const u8) usize { |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | test "utf8ToUtf16LeStringLiteral" { |
| 709 | | // https://github.com/ziglang/zig/issues/5127 |
| 710 | | if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; |
| 711 | | |
| 712 | 709 | { |
| 713 | | const bytes = [_:0]u16{0x41}; |
| 710 | const bytes = [_:0]u16{ |
| 711 | mem.nativeToLittle(u16, 0x41), |
| 712 | }; |
| 714 | 713 | const utf16 = utf8ToUtf16LeStringLiteral("A"); |
| 715 | 714 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 716 | 715 | testing.expect(utf16[1] == 0); |
| 717 | 716 | } |
| 718 | 717 | { |
| 719 | | const bytes = [_:0]u16{ 0xD801, 0xDC37 }; |
| 718 | const bytes = [_:0]u16{ |
| 719 | mem.nativeToLittle(u16, 0xD801), |
| 720 | mem.nativeToLittle(u16, 0xDC37), |
| 721 | }; |
| 720 | 722 | const utf16 = utf8ToUtf16LeStringLiteral("𐐷"); |
| 721 | 723 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 722 | 724 | testing.expect(utf16[2] == 0); |
| 723 | 725 | } |
| 724 | 726 | { |
| 725 | | const bytes = [_:0]u16{0x02FF}; |
| 727 | const bytes = [_:0]u16{ |
| 728 | mem.nativeToLittle(u16, 0x02FF), |
| 729 | }; |
| 726 | 730 | const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}"); |
| 727 | 731 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 728 | 732 | testing.expect(utf16[1] == 0); |
| 729 | 733 | } |
| 730 | 734 | { |
| 731 | | const bytes = [_:0]u16{0x7FF}; |
| 735 | const bytes = [_:0]u16{ |
| 736 | mem.nativeToLittle(u16, 0x7FF), |
| 737 | }; |
| 732 | 738 | const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}"); |
| 733 | 739 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 734 | 740 | testing.expect(utf16[1] == 0); |
| 735 | 741 | } |
| 736 | 742 | { |
| 737 | | const bytes = [_:0]u16{0x801}; |
| 743 | const bytes = [_:0]u16{ |
| 744 | mem.nativeToLittle(u16, 0x801), |
| 745 | }; |
| 738 | 746 | const utf16 = utf8ToUtf16LeStringLiteral("\u{801}"); |
| 739 | 747 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 740 | 748 | testing.expect(utf16[1] == 0); |
| 741 | 749 | } |
| 742 | 750 | { |
| 743 | | const bytes = [_:0]u16{ 0xDBFF, 0xDFFF }; |
| 751 | const bytes = [_:0]u16{ |
| 752 | mem.nativeToLittle(u16, 0xDBFF), |
| 753 | mem.nativeToLittle(u16, 0xDFFF), |
| 754 | }; |
| 744 | 755 | const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}"); |
| 745 | 756 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 746 | 757 | testing.expect(utf16[2] == 0); |