@@ -528,6 +528,7 @@ var upperTests = []StringTest{
528
528
{"longStrinGwitHmixofsmaLLandcAps" , "LONGSTRINGWITHMIXOFSMALLANDCAPS" },
529
529
{"long\u0250 string\u0250 with\u0250 nonascii\u2C6F chars" , "LONG\u2C6F STRING\u2C6F WITH\u2C6F NONASCII\u2C6F CHARS" },
530
530
{"\u0250 \u0250 \u0250 \u0250 \u0250 " , "\u2C6F \u2C6F \u2C6F \u2C6F \u2C6F " }, // grows one byte per char
531
+ {"a\u0080 \U0010FFFF " , "A\u0080 \U0010FFFF " }, // test utf8.RuneSelf and utf8.MaxRune
531
532
}
532
533
533
534
var lowerTests = []StringTest {
@@ -538,6 +539,7 @@ var lowerTests = []StringTest{
538
539
{"longStrinGwitHmixofsmaLLandcAps" , "longstringwithmixofsmallandcaps" },
539
540
{"LONG\u2C6F STRING\u2C6F WITH\u2C6F NONASCII\u2C6F CHARS" , "long\u0250 string\u0250 with\u0250 nonascii\u0250 chars" },
540
541
{"\u2C6D \u2C6D \u2C6D \u2C6D \u2C6D " , "\u0251 \u0251 \u0251 \u0251 \u0251 " }, // shrinks one byte per char
542
+ {"A\u0080 \U0010FFFF " , "a\u0080 \U0010FFFF " }, // test utf8.RuneSelf and utf8.MaxRune
541
543
}
542
544
543
545
const space = "\t \v \r \f \n \u0085 \u00a0 \u2000 \u3000 "
@@ -650,6 +652,27 @@ func TestMap(t *testing.T) {
650
652
if m != expect {
651
653
t .Errorf ("replace invalid sequence: expected %q got %q" , expect , m )
652
654
}
655
+
656
+ // 8. Check utf8.RuneSelf and utf8.MaxRune encoding
657
+ encode := func (r rune ) rune {
658
+ switch r {
659
+ case utf8 .RuneSelf :
660
+ return unicode .MaxRune
661
+ case unicode .MaxRune :
662
+ return utf8 .RuneSelf
663
+ }
664
+ return r
665
+ }
666
+ s := string (utf8 .RuneSelf ) + string (utf8 .MaxRune )
667
+ r := string (utf8 .MaxRune ) + string (utf8 .RuneSelf ) // reverse of s
668
+ m = Map (encode , s )
669
+ if m != r {
670
+ t .Errorf ("encoding not handled correctly: expected %q got %q" , r , m )
671
+ }
672
+ m = Map (encode , r )
673
+ if m != s {
674
+ t .Errorf ("encoding not handled correctly: expected %q got %q" , s , m )
675
+ }
653
676
}
654
677
655
678
func TestToUpper (t * testing.T ) { runStringTests (t , ToUpper , "ToUpper" , upperTests ) }
0 commit comments