Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(53)

Side by Side Diff: src/pkg/strings/strings_test.go

Issue 5143044: code review 5143044: strings: add CaseFoldedEqual (Closed)
Patch Set: diff -r 583b7464b4e3 https://go.googlecode.com/hg/ Created 13 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/strings/strings.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package strings_test 5 package strings_test
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "os" 9 "os"
10 "reflect" 10 "reflect"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 t.Errorf("%s(%q,%q) = %v; want %v", funcName, test.s, te st.sep, actual, test.out) 113 t.Errorf("%s(%q,%q) = %v; want %v", funcName, test.s, te st.sep, actual, test.out)
114 } 114 }
115 } 115 }
116 } 116 }
117 117
118 func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTest s) } 118 func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTest s) }
119 func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", l astIndexTests) } 119 func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", l astIndexTests) }
120 func TestIndexAny(t *testing.T) { runIndexTests(t, IndexAny, "IndexAny", ind exAnyTests) } 120 func TestIndexAny(t *testing.T) { runIndexTests(t, IndexAny, "IndexAny", ind exAnyTests) }
121 func TestLastIndexAny(t *testing.T) { runIndexTests(t, LastIndexAny, "LastIndexA ny", lastIndexAnyTests) } 121 func TestLastIndexAny(t *testing.T) { runIndexTests(t, LastIndexAny, "LastIndexA ny", lastIndexAnyTests) }
122 122
123 type IndexRuneTest struct { 123 var indexRuneTests = []struct {
124 s string 124 s string
125 rune int 125 rune int
126 out int 126 out int
127 } 127 }{
128
129 var indexRuneTests = []IndexRuneTest{
130 {"a A x", 'A', 2}, 128 {"a A x", 'A', 2},
131 {"some_text=some_value", '=', 9}, 129 {"some_text=some_value", '=', 9},
132 {"☺a", 'a', 3}, 130 {"☺a", 'a', 3},
133 {"a☻☺b", '☺', 4}, 131 {"a☻☺b", '☺', 4},
134 } 132 }
135 133
136 func TestIndexRune(t *testing.T) { 134 func TestIndexRune(t *testing.T) {
137 for _, test := range indexRuneTests { 135 for _, test := range indexRuneTests {
138 if actual := IndexRune(test.s, test.rune); actual != test.out { 136 if actual := IndexRune(test.s, test.rune); actual != test.out {
139 t.Errorf("IndexRune(%q,%d)= %v; want %v", test.s, test.r une, actual, test.out) 137 t.Errorf("IndexRune(%q,%d)= %v; want %v", test.s, test.r une, actual, test.out)
(...skipping 23 matching lines...) Expand all
163 161
164 func BenchmarkIndex(b *testing.B) { 162 func BenchmarkIndex(b *testing.B) {
165 if got := Index(benchmarkString, "v"); got != 17 { 163 if got := Index(benchmarkString, "v"); got != 17 {
166 panic("wrong index: got=" + strconv.Itoa(got)) 164 panic("wrong index: got=" + strconv.Itoa(got))
167 } 165 }
168 for i := 0; i < b.N; i++ { 166 for i := 0; i < b.N; i++ {
169 Index(benchmarkString, "v") 167 Index(benchmarkString, "v")
170 } 168 }
171 } 169 }
172 170
173 type ExplodeTest struct { 171 var explodetests = []struct {
174 s string 172 s string
175 n int 173 n int
176 a []string 174 a []string
177 } 175 }{
178
179 var explodetests = []ExplodeTest{
180 {"", -1, []string{}}, 176 {"", -1, []string{}},
181 {abcd, 4, []string{"a", "b", "c", "d"}}, 177 {abcd, 4, []string{"a", "b", "c", "d"}},
182 {faces, 3, []string{"☺", "☻", "☹"}}, 178 {faces, 3, []string{"☺", "☻", "☹"}},
183 {abcd, 2, []string{"a", "bcd"}}, 179 {abcd, 2, []string{"a", "bcd"}},
184 } 180 }
185 181
186 func TestExplode(t *testing.T) { 182 func TestExplode(t *testing.T) {
187 for _, tt := range explodetests { 183 for _, tt := range explodetests {
188 a := SplitN(tt.s, "", tt.n) 184 a := SplitN(tt.s, "", tt.n)
189 if !eq(a, tt.a) { 185 if !eq(a, tt.a) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 func TestFields(t *testing.T) { 297 func TestFields(t *testing.T) {
302 for _, tt := range fieldstests { 298 for _, tt := range fieldstests {
303 a := Fields(tt.s) 299 a := Fields(tt.s)
304 if !eq(a, tt.a) { 300 if !eq(a, tt.a) {
305 t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a) 301 t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a)
306 continue 302 continue
307 } 303 }
308 } 304 }
309 } 305 }
310 306
307 var FieldsFuncTests = []FieldsTest{
308 {"", []string{}},
309 {"XX", []string{}},
310 {"XXhiXXX", []string{"hi"}},
311 {"aXXbXXXcX", []string{"a", "b", "c"}},
312 }
313
311 func TestFieldsFunc(t *testing.T) { 314 func TestFieldsFunc(t *testing.T) {
312 pred := func(c int) bool { return c == 'X' } 315 pred := func(c int) bool { return c == 'X' }
313 » var fieldsFuncTests = []FieldsTest{ 316 » for _, tt := range FieldsFuncTests {
314 » » {"", []string{}},
315 » » {"XX", []string{}},
316 » » {"XXhiXXX", []string{"hi"}},
317 » » {"aXXbXXXcX", []string{"a", "b", "c"}},
318 » }
319 » for _, tt := range fieldsFuncTests {
320 a := FieldsFunc(tt.s, pred) 317 a := FieldsFunc(tt.s, pred)
321 if !eq(a, tt.a) { 318 if !eq(a, tt.a) {
322 t.Errorf("FieldsFunc(%q) = %v, want %v", tt.s, a, tt.a) 319 t.Errorf("FieldsFunc(%q) = %v, want %v", tt.s, a, tt.a)
323 } 320 }
324 } 321 }
325 } 322 }
326 323
327 // Test case for any function which accepts and returns a single string. 324 // Test case for any function which accepts and returns a single string.
328 type StringTest struct { 325 type StringTest struct {
329 in, out string 326 in, out string
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 t.Errorf("Lower(lower) is %s not %s", l, lower) 481 t.Errorf("Lower(lower) is %s not %s", l, lower)
485 } 482 }
486 l = ToLowerSpecial(unicode.TurkishCase, upper) 483 l = ToLowerSpecial(unicode.TurkishCase, upper)
487 if l != lower { 484 if l != lower {
488 t.Errorf("Lower(upper) is %s not %s", l, lower) 485 t.Errorf("Lower(upper) is %s not %s", l, lower)
489 } 486 }
490 } 487 }
491 488
492 func TestTrimSpace(t *testing.T) { runStringTests(t, TrimSpace, "TrimSpace", tri mSpaceTests) } 489 func TestTrimSpace(t *testing.T) { runStringTests(t, TrimSpace, "TrimSpace", tri mSpaceTests) }
493 490
494 type TrimTest struct { 491 var trimTests = []struct {
495 f func(string, string) string 492 f func(string, string) string
496 in, cutset, out string 493 in, cutset, out string
497 } 494 }{
498
499 var trimTests = []TrimTest{
500 {Trim, "abba", "a", "bb"}, 495 {Trim, "abba", "a", "bb"},
501 {Trim, "abba", "ab", ""}, 496 {Trim, "abba", "ab", ""},
502 {TrimLeft, "abba", "ab", ""}, 497 {TrimLeft, "abba", "ab", ""},
503 {TrimRight, "abba", "ab", ""}, 498 {TrimRight, "abba", "ab", ""},
504 {TrimLeft, "abba", "a", "bba"}, 499 {TrimLeft, "abba", "a", "bba"},
505 {TrimRight, "abba", "a", "abb"}, 500 {TrimRight, "abba", "a", "abb"},
506 {Trim, "<tag>", "<>", "tag"}, 501 {Trim, "<tag>", "<>", "tag"},
507 {Trim, "* listitem", " *", "listitem"}, 502 {Trim, "* listitem", " *", "listitem"},
508 {Trim, `"quote"`, `"`, "quote"}, 503 {Trim, `"quote"`, `"`, "quote"},
509 {Trim, "\u2C6F\u2C6F\u0250\u0250\u2C6F\u2C6F", "\u2C6F", "\u0250\u0250"} , 504 {Trim, "\u2C6F\u2C6F\u0250\u0250\u2C6F\u2C6F", "\u2C6F", "\u0250\u0250"} ,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 var isSpace = predicate{unicode.IsSpace, "IsSpace"} 543 var isSpace = predicate{unicode.IsSpace, "IsSpace"}
549 var isDigit = predicate{unicode.IsDigit, "IsDigit"} 544 var isDigit = predicate{unicode.IsDigit, "IsDigit"}
550 var isUpper = predicate{unicode.IsUpper, "IsUpper"} 545 var isUpper = predicate{unicode.IsUpper, "IsUpper"}
551 var isValidRune = predicate{ 546 var isValidRune = predicate{
552 func(r int) bool { 547 func(r int) bool {
553 return r != utf8.RuneError 548 return r != utf8.RuneError
554 }, 549 },
555 "IsValidRune", 550 "IsValidRune",
556 } 551 }
557 552
558 type TrimFuncTest struct {
559 f predicate
560 in, out string
561 }
562
563 func not(p predicate) predicate { 553 func not(p predicate) predicate {
564 return predicate{ 554 return predicate{
565 func(r int) bool { 555 func(r int) bool {
566 return !p.f(r) 556 return !p.f(r)
567 }, 557 },
568 "not " + p.name, 558 "not " + p.name,
569 } 559 }
570 } 560 }
571 561
572 var trimFuncTests = []TrimFuncTest{ 562 var trimFuncTests = []struct {
563 » f predicate
564 » in, out string
565 }{
573 {isSpace, space + " hello " + space, "hello"}, 566 {isSpace, space + " hello " + space, "hello"},
574 {isDigit, "\u0e50\u0e5212hello34\u0e50\u0e51", "hello"}, 567 {isDigit, "\u0e50\u0e5212hello34\u0e50\u0e51", "hello"},
575 {isUpper, "\u2C6F\u2C6F\u2C6F\u2C6FABCDhelloEF\u2C6F\u2C6FGH\u2C6F\u2C6F ", "hello"}, 568 {isUpper, "\u2C6F\u2C6F\u2C6F\u2C6FABCDhelloEF\u2C6F\u2C6FGH\u2C6F\u2C6F ", "hello"},
576 {not(isSpace), "hello" + space + "hello", space}, 569 {not(isSpace), "hello" + space + "hello", space},
577 {not(isDigit), "hello\u0e50\u0e521234\u0e50\u0e51helo", "\u0e50\u0e52123 4\u0e50\u0e51"}, 570 {not(isDigit), "hello\u0e50\u0e521234\u0e50\u0e51helo", "\u0e50\u0e52123 4\u0e50\u0e51"},
578 {isValidRune, "ab\xc0a\xc0cd", "\xc0a\xc0"}, 571 {isValidRune, "ab\xc0a\xc0cd", "\xc0a\xc0"},
579 {not(isValidRune), "\xc0a\xc0", "a"}, 572 {not(isValidRune), "\xc0a\xc0", "a"},
580 } 573 }
581 574
582 func TestTrimFunc(t *testing.T) { 575 func TestTrimFunc(t *testing.T) {
583 for _, tc := range trimFuncTests { 576 for _, tc := range trimFuncTests {
584 actual := TrimFunc(tc.in, tc.f.f) 577 actual := TrimFunc(tc.in, tc.f.f)
585 if actual != tc.out { 578 if actual != tc.out {
586 t.Errorf("TrimFunc(%q, %q) = %q; want %q", tc.in, tc.f.n ame, actual, tc.out) 579 t.Errorf("TrimFunc(%q, %q) = %q; want %q", tc.in, tc.f.n ame, actual, tc.out)
587 } 580 }
588 } 581 }
589 } 582 }
590 583
591 type IndexFuncTest struct { 584 var indexFuncTests = []struct {
592 in string 585 in string
593 f predicate 586 f predicate
594 first, last int 587 first, last int
595 } 588 }{
596
597 var indexFuncTests = []IndexFuncTest{
598 {"", isValidRune, -1, -1}, 589 {"", isValidRune, -1, -1},
599 {"abc", isDigit, -1, -1}, 590 {"abc", isDigit, -1, -1},
600 {"0123", isDigit, 0, 3}, 591 {"0123", isDigit, 0, 3},
601 {"a1b", isDigit, 1, 1}, 592 {"a1b", isDigit, 1, 1},
602 {space, isSpace, 0, len(space) - 3}, // last rune in space is 3 bytes 593 {space, isSpace, 0, len(space) - 3}, // last rune in space is 3 bytes
603 {"\u0e50\u0e5212hello34\u0e50\u0e51", isDigit, 0, 18}, 594 {"\u0e50\u0e5212hello34\u0e50\u0e51", isDigit, 0, 18},
604 {"\u2C6F\u2C6F\u2C6F\u2C6FABCDhelloEF\u2C6F\u2C6FGH\u2C6F\u2C6F", isUppe r, 0, 34}, 595 {"\u2C6F\u2C6F\u2C6F\u2C6FABCDhelloEF\u2C6F\u2C6FGH\u2C6F\u2C6F", isUppe r, 0, 34},
605 {"12\u0e50\u0e52hello34\u0e50\u0e51", not(isDigit), 8, 12}, 596 {"12\u0e50\u0e52hello34\u0e50\u0e51", not(isDigit), 8, 12},
606 597
607 // tests of invalid UTF-8 598 // tests of invalid UTF-8
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 676
686 if !equal("ToUpper(lower)", ToUpper(lower), upper, t) { 677 if !equal("ToUpper(lower)", ToUpper(lower), upper, t) {
687 t.Error("ToUpper(lower) consistency fail"); 678 t.Error("ToUpper(lower) consistency fail");
688 } 679 }
689 if !equal("ToLower(upper)", ToLower(upper), lower, t) { 680 if !equal("ToLower(upper)", ToLower(upper), lower, t) {
690 t.Error("ToLower(upper) consistency fail"); 681 t.Error("ToLower(upper) consistency fail");
691 } 682 }
692 */ 683 */
693 } 684 }
694 685
695 type RepeatTest struct { 686 var RepeatTests = []struct {
696 in, out string 687 in, out string
697 count int 688 count int
698 } 689 }{
699
700 var RepeatTests = []RepeatTest{
701 {"", "", 0}, 690 {"", "", 0},
702 {"", "", 1}, 691 {"", "", 1},
703 {"", "", 2}, 692 {"", "", 2},
704 {"-", "", 0}, 693 {"-", "", 0},
705 {"-", "-", 1}, 694 {"-", "-", 1},
706 {"-", "----------", 10}, 695 {"-", "----------", 10},
707 {"abc ", "abc abc abc ", 3}, 696 {"abc ", "abc abc abc ", 3},
708 } 697 }
709 698
710 func TestRepeat(t *testing.T) { 699 func TestRepeat(t *testing.T) {
(...skipping 11 matching lines...) Expand all
722 return false 711 return false
723 } 712 }
724 for i, r := range a { 713 for i, r := range a {
725 if r != b[i] { 714 if r != b[i] {
726 return false 715 return false
727 } 716 }
728 } 717 }
729 return true 718 return true
730 } 719 }
731 720
732 type RunesTest struct { 721 var RunesTests = []struct {
733 in string 722 in string
734 out []int 723 out []int
735 lossy bool 724 lossy bool
736 } 725 }{
737
738 var RunesTests = []RunesTest{
739 {"", []int{}, false}, 726 {"", []int{}, false},
740 {" ", []int{32}, false}, 727 {" ", []int{32}, false},
741 {"ABC", []int{65, 66, 67}, false}, 728 {"ABC", []int{65, 66, 67}, false},
742 {"abc", []int{97, 98, 99}, false}, 729 {"abc", []int{97, 98, 99}, false},
743 {"\u65e5\u672c\u8a9e", []int{26085, 26412, 35486}, false}, 730 {"\u65e5\u672c\u8a9e", []int{26085, 26412, 35486}, false},
744 {"ab\x80c", []int{97, 98, 0xFFFD, 99}, true}, 731 {"ab\x80c", []int{97, 98, 0xFFFD, 99}, true},
745 {"ab\xc0c", []int{97, 98, 0xFFFD, 99}, true}, 732 {"ab\xc0c", []int{97, 98, 0xFFFD, 99}, true},
746 } 733 }
747 734
748 func TestRunes(t *testing.T) { 735 func TestRunes(t *testing.T) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 t.Errorf("Reading %q after unreading: want size %d, got %d", s, z, z1) 826 t.Errorf("Reading %q after unreading: want size %d, got %d", s, z, z1)
840 break 827 break
841 } 828 }
842 } 829 }
843 if res != s { 830 if res != s {
844 t.Errorf("Reader(%q).ReadRune() produced %q", s, res) 831 t.Errorf("Reader(%q).ReadRune() produced %q", s, res)
845 } 832 }
846 } 833 }
847 } 834 }
848 835
849 type ReplaceTest struct { 836 var ReplaceTests = []struct {
850 in string 837 in string
851 old, new string 838 old, new string
852 n int 839 n int
853 out string 840 out string
854 } 841 }{
855
856 var ReplaceTests = []ReplaceTest{
857 {"hello", "l", "L", 0, "hello"}, 842 {"hello", "l", "L", 0, "hello"},
858 {"hello", "l", "L", -1, "heLLo"}, 843 {"hello", "l", "L", -1, "heLLo"},
859 {"hello", "x", "X", -1, "hello"}, 844 {"hello", "x", "X", -1, "hello"},
860 {"", "x", "X", -1, ""}, 845 {"", "x", "X", -1, ""},
861 {"radar", "r", "<r>", -1, "<r>ada<r>"}, 846 {"radar", "r", "<r>", -1, "<r>ada<r>"},
862 {"", "", "<>", -1, "<>"}, 847 {"", "", "<>", -1, "<>"},
863 {"banana", "a", "<>", -1, "b<>n<>n<>"}, 848 {"banana", "a", "<>", -1, "b<>n<>n<>"},
864 {"banana", "a", "<>", 1, "b<>nana"}, 849 {"banana", "a", "<>", 1, "b<>nana"},
865 {"banana", "a", "<>", 1000, "b<>n<>n<>"}, 850 {"banana", "a", "<>", 1000, "b<>n<>n<>"},
866 {"banana", "an", "<>", -1, "b<><>a"}, 851 {"banana", "an", "<>", -1, "b<><>a"},
867 {"banana", "ana", "<>", -1, "b<>na"}, 852 {"banana", "ana", "<>", -1, "b<>na"},
868 {"banana", "", "<>", -1, "<>b<>a<>n<>a<>n<>a<>"}, 853 {"banana", "", "<>", -1, "<>b<>a<>n<>a<>n<>a<>"},
869 {"banana", "", "<>", 10, "<>b<>a<>n<>a<>n<>a<>"}, 854 {"banana", "", "<>", 10, "<>b<>a<>n<>a<>n<>a<>"},
870 {"banana", "", "<>", 6, "<>b<>a<>n<>a<>n<>a"}, 855 {"banana", "", "<>", 6, "<>b<>a<>n<>a<>n<>a"},
871 {"banana", "", "<>", 5, "<>b<>a<>n<>a<>na"}, 856 {"banana", "", "<>", 5, "<>b<>a<>n<>a<>na"},
872 {"banana", "", "<>", 1, "<>banana"}, 857 {"banana", "", "<>", 1, "<>banana"},
873 {"banana", "a", "a", -1, "banana"}, 858 {"banana", "a", "a", -1, "banana"},
874 {"banana", "a", "a", 1, "banana"}, 859 {"banana", "a", "a", 1, "banana"},
875 {"☺☻☹", "", "<>", -1, "<>☺<>☻<>☹<>"}, 860 {"☺☻☹", "", "<>", -1, "<>☺<>☻<>☹<>"},
876 } 861 }
877 862
878 func TestReplace(t *testing.T) { 863 func TestReplace(t *testing.T) {
879 for _, tt := range ReplaceTests { 864 for _, tt := range ReplaceTests {
880 if s := Replace(tt.in, tt.old, tt.new, tt.n); s != tt.out { 865 if s := Replace(tt.in, tt.old, tt.new, tt.n); s != tt.out {
881 t.Errorf("Replace(%q, %q, %q, %d) = %q, want %q", tt.in, tt.old, tt.new, tt.n, s, tt.out) 866 t.Errorf("Replace(%q, %q, %q, %d) = %q, want %q", tt.in, tt.old, tt.new, tt.n, s, tt.out)
882 } 867 }
883 } 868 }
884 } 869 }
885 870
886 type TitleTest struct { 871 var TitleTests = []struct {
887 in, out string 872 in, out string
888 } 873 }{
889
890 var TitleTests = []TitleTest{
891 {"", ""}, 874 {"", ""},
892 {"a", "A"}, 875 {"a", "A"},
893 {" aaa aaa aaa ", " Aaa Aaa Aaa "}, 876 {" aaa aaa aaa ", " Aaa Aaa Aaa "},
894 {" Aaa Aaa Aaa ", " Aaa Aaa Aaa "}, 877 {" Aaa Aaa Aaa ", " Aaa Aaa Aaa "},
895 {"123a456", "123a456"}, 878 {"123a456", "123a456"},
896 {"double-blind", "Double-Blind"}, 879 {"double-blind", "Double-Blind"},
897 {"ÿøû", "Ÿøû"}, 880 {"ÿøû", "Ÿøû"},
898 } 881 }
899 882
900 func TestTitle(t *testing.T) { 883 func TestTitle(t *testing.T) {
901 for _, tt := range TitleTests { 884 for _, tt := range TitleTests {
902 if s := Title(tt.in); s != tt.out { 885 if s := Title(tt.in); s != tt.out {
903 t.Errorf("Title(%q) = %q, want %q", tt.in, s, tt.out) 886 t.Errorf("Title(%q) = %q, want %q", tt.in, s, tt.out)
904 } 887 }
905 } 888 }
906 } 889 }
907 890
908 type ContainsTest struct { 891 var ContainsTests = []struct {
909 str, substr string 892 str, substr string
910 expected bool 893 expected bool
911 } 894 }{
912
913 var ContainsTests = []ContainsTest{
914 {"abc", "bc", true}, 895 {"abc", "bc", true},
915 {"abc", "bcd", false}, 896 {"abc", "bcd", false},
916 {"abc", "", true}, 897 {"abc", "", true},
917 {"", "a", false}, 898 {"", "a", false},
918 } 899 }
919 900
920 func TestContains(t *testing.T) { 901 func TestContains(t *testing.T) {
921 for _, ct := range ContainsTests { 902 for _, ct := range ContainsTests {
922 if Contains(ct.str, ct.substr) != ct.expected { 903 if Contains(ct.str, ct.substr) != ct.expected {
923 t.Errorf("Contains(%s, %s) = %v, want %v", 904 t.Errorf("Contains(%s, %s) = %v, want %v",
924 ct.str, ct.substr, !ct.expected, ct.expected) 905 ct.str, ct.substr, !ct.expected, ct.expected)
925 } 906 }
926 } 907 }
927 } 908 }
909
910 var EqualFoldTests = []struct {
911 s, t string
912 out bool
913 }{
914 {"abc", "abc", true},
915 {"ABcd", "ABcd", true},
916 {"123abc", "123ABC", true},
917 {"αβδ", "ΑΒΔ", true},
918 {"abc", "xyz", false},
919 {"abc", "XYZ", false},
920 {"abcdefghijk", "abcdefghijX", false},
921 {"abcdefghijk", "abcdefghij\u212A", true},
922 {"abcdefghijK", "abcdefghij\u212A", true},
923 {"abcdefghijkz", "abcdefghij\u212Ay", false},
924 {"abcdefghijKz", "abcdefghij\u212Ay", false},
925 }
926
927 func TestEqualFold(t *testing.T) {
928 for _, tt := range EqualFoldTests {
929 if out := EqualFold(tt.s, tt.t); out != tt.out {
930 t.Errorf("EqualFold(%#q, %#q) = %v, want %v", tt.s, tt.t , out, tt.out)
931 }
932 if out := EqualFold(tt.t, tt.s); out != tt.out {
933 t.Errorf("EqualFold(%#q, %#q) = %v, want %v", tt.t, tt.s , out, tt.out)
934 }
935 }
936 }
OLDNEW
« no previous file with comments | « src/pkg/strings/strings.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b