提交 c06198e1 编写于 作者: chai2010's avatar chai2010

bytes 包补充测试

上级 ee0c4c71
......@@ -950,7 +950,7 @@ func ContainsRune(b: []byte, r: rune) => bool {
// code points in chars. It returns -1 if chars is empty or if there is no code
// point in common.
func IndexAny(s: []byte, chars: string) => int {
/*
if chars == "" {
// Avoid scanning all of s.
return -1
......@@ -1002,10 +1002,11 @@ func IndexAny(s: []byte, chars: string) => int {
if r != utf8.RuneError {
// r is 2 to 4 bytes
if len(chars) == width {
if chars == string(r) {
return i
}
continue
panic("TODO") // 字符串支持
//if chars == string(r) {
// return i
//}
//continue
}
// Use bytealg.IndexString for performance if available.
//if bytealg.MaxLen >= width {
......@@ -1021,6 +1022,5 @@ func IndexAny(s: []byte, chars: string) => int {
// }
//}
}
*/
return -1
}
......@@ -1110,18 +1110,62 @@ global containsTests = []struct {
{[]byte("hello"), []byte("hel"), true},
{[]byte("汉语拼音"), []byte("汉语"), true},
{[]byte("hello"), []byte("Hello, world"), false},
{[]byte("武汉"), []byte("武汉"), false},
{[]byte("武汉"), []byte("武汉"), true},
}
func TestContains {
//for _, tt := range containsTests {
// if got := Contains(tt.b, tt.subslice); got != tt.want {
// assert(false)
// //t.Errorf("Contains(%q, %q) = %v, want %v", tt.b, tt.subslice, got, tt.want)
// }
//}
for _, tt := range containsTests {
if got := Contains(tt.b, tt.subslice); got != tt.want {
println(string(tt.b), string(tt.subslice), got, tt.want)
assert(false)
//t.Errorf("Contains(%q, %q) = %v, want %v", tt.b, tt.subslice, got, tt.want)
}
}
}
global ContainsAnyTests = []struct {
b: []byte
substr: string
expected: bool
}{
{[]byte(""), "", false},
{[]byte(""), "a", false},
{[]byte(""), "abc", false},
{[]byte("a"), "", false},
{[]byte("a"), "a", true},
{[]byte("aaa"), "a", true},
{[]byte("abc"), "xyz", false},
{[]byte("abc"), "xcz", true},
//{[]byte("a☺b☻c☹d"), "uvw☻xyz", true}, // TODO(chai2010)
{[]byte("aRegExp*"), ".(|)*+?^$[]", true},
{[]byte(dots + dots + dots), " ", false},
}
func TestContainsAny {
for _, ct := range ContainsAnyTests {
if ContainsAny(ct.b, ct.substr) != ct.expected {
println(string(ct.b), string(ct.substr))
assert(false)
//t.Errorf("ContainsAny(%s, %s) = %v, want %v",
// ct.b, ct.substr, !ct.expected, ct.expected)
}
}
}
global ContainsRuneTests = []struct {
b []byte
r rune
expected bool
}{
{[]byte(""), 'a', false},
{[]byte("a"), 'a', true},
{[]byte("aaa"), 'a', true},
{[]byte("abc"), 'y', false},
{[]byte("abc"), 'c', true},
{[]byte("a☺b☻c☹d"), 'x', false},
{[]byte("a☺b☻c☹d"), '☻', true},
{[]byte("aRegExp*"), '*', true},
}
func eq(a, b: []string) => bool {
if len(a) != len(b) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册