| ... | @@ -706,41 +706,52 @@ fn calcUtf16LeLen(utf8: []const u8) usize { | ... | @@ -706,41 +706,52 @@ fn calcUtf16LeLen(utf8: []const u8) usize { |
| 706 | } | 706 | } |
| 707 | | 707 | |
| 708 | test "utf8ToUtf16LeStringLiteral" { | 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 | const utf16 = utf8ToUtf16LeStringLiteral("A"); | 713 | const utf16 = utf8ToUtf16LeStringLiteral("A"); |
| 715 | testing.expectEqualSlices(u16, &bytes, utf16); | 714 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 716 | testing.expect(utf16[1] == 0); | 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 | const utf16 = utf8ToUtf16LeStringLiteral("𐐷"); | 722 | const utf16 = utf8ToUtf16LeStringLiteral("𐐷"); |
| 721 | testing.expectEqualSlices(u16, &bytes, utf16); | 723 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 722 | testing.expect(utf16[2] == 0); | 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 | const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}"); | 730 | const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}"); |
| 727 | testing.expectEqualSlices(u16, &bytes, utf16); | 731 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 728 | testing.expect(utf16[1] == 0); | 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 | const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}"); | 738 | const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}"); |
| 733 | testing.expectEqualSlices(u16, &bytes, utf16); | 739 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 734 | testing.expect(utf16[1] == 0); | 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 | const utf16 = utf8ToUtf16LeStringLiteral("\u{801}"); | 746 | const utf16 = utf8ToUtf16LeStringLiteral("\u{801}"); |
| 739 | testing.expectEqualSlices(u16, &bytes, utf16); | 747 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 740 | testing.expect(utf16[1] == 0); | 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 | const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}"); | 755 | const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}"); |
| 745 | testing.expectEqualSlices(u16, &bytes, utf16); | 756 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 746 | testing.expect(utf16[2] == 0); | 757 | testing.expect(utf16[2] == 0); |