LEFT | RIGHT |
(no file at all) | |
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 "io" | 9 "io" |
10 "reflect" | 10 "reflect" |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 | 901 |
902 func TestContains(t *testing.T) { | 902 func TestContains(t *testing.T) { |
903 for _, ct := range ContainsTests { | 903 for _, ct := range ContainsTests { |
904 if Contains(ct.str, ct.substr) != ct.expected { | 904 if Contains(ct.str, ct.substr) != ct.expected { |
905 t.Errorf("Contains(%s, %s) = %v, want %v", | 905 t.Errorf("Contains(%s, %s) = %v, want %v", |
906 ct.str, ct.substr, !ct.expected, ct.expected) | 906 ct.str, ct.substr, !ct.expected, ct.expected) |
907 } | 907 } |
908 } | 908 } |
909 } | 909 } |
910 | 910 |
| 911 var ContainsAnyTests = []struct { |
| 912 str, substr string |
| 913 expected bool |
| 914 }{ |
| 915 {"", "", false}, |
| 916 {"", "a", false}, |
| 917 {"", "abc", false}, |
| 918 {"a", "", false}, |
| 919 {"a", "a", true}, |
| 920 {"aaa", "a", true}, |
| 921 {"abc", "xyz", false}, |
| 922 {"abc", "xcz", true}, |
| 923 {"a☺b☻c☹d", "uvw☻xyz", true}, |
| 924 {"aRegExp*", ".(|)*+?^$[]", true}, |
| 925 {dots + dots + dots, " ", false}, |
| 926 } |
| 927 |
| 928 func TestContainsAny(t *testing.T) { |
| 929 for _, ct := range ContainsAnyTests { |
| 930 if ContainsAny(ct.str, ct.substr) != ct.expected { |
| 931 t.Errorf("ContainsAny(%s, %s) = %v, want %v", |
| 932 ct.str, ct.substr, !ct.expected, ct.expected) |
| 933 } |
| 934 } |
| 935 } |
| 936 |
| 937 var ContainsRuneTests = []struct { |
| 938 str string |
| 939 r rune |
| 940 expected bool |
| 941 }{ |
| 942 {"", 'a', false}, |
| 943 {"a", 'a', true}, |
| 944 {"aaa", 'a', true}, |
| 945 {"abc", 'y', false}, |
| 946 {"abc", 'c', true}, |
| 947 {"a☺b☻c☹d", 'x', false}, |
| 948 {"a☺b☻c☹d", '☻', true}, |
| 949 {"aRegExp*", '*', true}, |
| 950 } |
| 951 |
| 952 func TestContainsRune(t *testing.T) { |
| 953 for _, ct := range ContainsRuneTests { |
| 954 if ContainsRune(ct.str, ct.r) != ct.expected { |
| 955 t.Errorf("ContainsRune(%s, %s) = %v, want %v", |
| 956 ct.str, ct.r, !ct.expected, ct.expected) |
| 957 } |
| 958 } |
| 959 } |
| 960 |
911 var EqualFoldTests = []struct { | 961 var EqualFoldTests = []struct { |
912 s, t string | 962 s, t string |
913 out bool | 963 out bool |
914 }{ | 964 }{ |
915 {"abc", "abc", true}, | 965 {"abc", "abc", true}, |
916 {"ABcd", "ABcd", true}, | 966 {"ABcd", "ABcd", true}, |
917 {"123abc", "123ABC", true}, | 967 {"123abc", "123ABC", true}, |
918 {"αβδ", "ΑΒΔ", true}, | 968 {"αβδ", "ΑΒΔ", true}, |
919 {"abc", "xyz", false}, | 969 {"abc", "xyz", false}, |
920 {"abc", "XYZ", false}, | 970 {"abc", "XYZ", false}, |
921 {"abcdefghijk", "abcdefghijX", false}, | 971 {"abcdefghijk", "abcdefghijX", false}, |
922 {"abcdefghijk", "abcdefghij\u212A", true}, | 972 {"abcdefghijk", "abcdefghij\u212A", true}, |
923 {"abcdefghijK", "abcdefghij\u212A", true}, | 973 {"abcdefghijK", "abcdefghij\u212A", true}, |
924 {"abcdefghijkz", "abcdefghij\u212Ay", false}, | 974 {"abcdefghijkz", "abcdefghij\u212Ay", false}, |
925 {"abcdefghijKz", "abcdefghij\u212Ay", false}, | 975 {"abcdefghijKz", "abcdefghij\u212Ay", false}, |
926 } | 976 } |
927 | 977 |
928 func TestEqualFold(t *testing.T) { | 978 func TestEqualFold(t *testing.T) { |
929 for _, tt := range EqualFoldTests { | 979 for _, tt := range EqualFoldTests { |
930 if out := EqualFold(tt.s, tt.t); out != tt.out { | 980 if out := EqualFold(tt.s, tt.t); out != tt.out { |
931 t.Errorf("EqualFold(%#q, %#q) = %v, want %v", tt.s, tt.t
, out, tt.out) | 981 t.Errorf("EqualFold(%#q, %#q) = %v, want %v", tt.s, tt.t
, out, tt.out) |
932 } | 982 } |
933 if out := EqualFold(tt.t, tt.s); out != tt.out { | 983 if out := EqualFold(tt.t, tt.s); out != tt.out { |
934 t.Errorf("EqualFold(%#q, %#q) = %v, want %v", tt.t, tt.s
, out, tt.out) | 984 t.Errorf("EqualFold(%#q, %#q) = %v, want %v", tt.t, tt.s
, out, tt.out) |
935 } | 985 } |
936 } | 986 } |
937 } | 987 } |
LEFT | RIGHT |