Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
c06198e1
wa
项目概览
wa-lang
/
wa
9 个月 前同步成功
通知
68
Star
655
Fork
45
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
wa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c06198e1
编写于
8月 25, 2023
作者:
chai2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bytes 包补充测试
上级
ee0c4c71
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
13 deletion
+57
-13
waroot/src/bytes/bytes.wa
waroot/src/bytes/bytes.wa
+6
-6
waroot/src/bytes/bytes_test.wa
waroot/src/bytes/bytes_test.wa
+51
-7
未找到文件。
waroot/src/bytes/bytes.wa
浏览文件 @
c06198e1
...
...
@@ -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
}
waroot/src/bytes/bytes_test.wa
浏览文件 @
c06198e1
...
...
@@ -1110,18 +1110,62 @@ global containsTests = []struct {
{[]byte("hello"), []byte("hel"), true},
{[]byte("汉语拼音"), []byte("汉语"), true},
{[]byte("hello"), []byte("Hello, world"), false},
{[]byte("武汉"), []byte("武汉"),
fals
e},
{[]byte("武汉"), []byte("武汉"),
tru
e},
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录