Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
06a2f8ea
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
06a2f8ea
编写于
9月 07, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[regexp]去除文档中手动生成的代码,添加注释
上级
d63f4912
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
401 addition
and
273 deletion
+401
-273
uni_modules/uts-tests/utssdk/RegExp.uts
uni_modules/uts-tests/utssdk/RegExp.uts
+401
-273
未找到文件。
uni_modules/uts-tests/utssdk/RegExp.uts
浏览文件 @
06a2f8ea
import { describe, test, expect, Result } from './tests.uts'
export function testRegExp(): Result {
export function testRegExp()
: Result {
return describe("RegExp", () => {
test("constructor", () => {
// #ifdef APP-ANDROID
...
...
@@ -20,85 +20,189 @@ export function testRegExp(): Result {
})
test("dotAll", () => {
// #TEST RegExp.dotAll
const regex1 = new RegExp('foo', 's');
expect(regex1.dotAll).toEqual(true);
console.log(regex1.dotAll);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.dotAll);
// expected output: false
// #END
expect(regex1.dotAll).toEqual(true);
expect(regex2.dotAll).toEqual(false);
})
});
test("flags", () => {
// #TEST RegExp.flags
const regex1 = new RegExp('foo', 'ig');
expect(regex1.flags).toEqual("gi");
console.log(regex1.flags);
// expected output: "gi"
const regex2 = new RegExp('bar', 'myu');
expect(regex2.flags).toEqual("muy");
console.log(regex2.flags);
// expected output: "muy"
const regex3 = new RegExp('bar');
console.log(regex3.flags);
// expected output: ""
// #END
expect(regex1.flags).toEqual("gi");
expect(regex2.flags).toEqual("muy");
expect(regex3.flags).toEqual("");
})
});
test("global", () => {
// #TEST RegExp.global
const regex1 = new RegExp('foo', 'g');
expect(regex1.global).toEqual(true);
console.log(regex1.global);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.global);
// expected output: false
// #END
expect(regex1.global).toEqual(true);
expect(regex2.global).toEqual(false);
})
});
test("hasIndices", () => {
// #TEST RegExp.hasIndices
const regex1 = new RegExp('foo', 'd');
expect(regex1.hasIndices).toEqual(true);
console.log(regex1.hasIndices);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.hasIndices);
// expected output: false
// #END
expect(regex1.hasIndices).toEqual(true);
expect(regex2.hasIndices).toEqual(false);
})
});
test("ignoreCase", () => {
// #TEST RegExp.ignoreCase
const regex1 = new RegExp('foo', 'i');
expect(regex1.ignoreCase).toEqual(true);
console.log(regex1.ignoreCase);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.ignoreCase);
// expected output: false
// #END
expect(regex1.ignoreCase).toEqual(true);
expect(regex2.ignoreCase).toEqual(false);
})
});
test("RegExpExecArray", () => {
// #ifdef APP-ANDROID
const regex1 = RegExp('foo*', 'g');
const str1 = 'table football, foosball';
let array1:
RegExpExecArray = regex1.exec(str1)!;
let array1 :
RegExpExecArray = regex1.exec(str1)!;
console.log(array1[0] == 'foo')
expect(array1[0] == 'foo').toEqual(true);
// #endif
})
test("lastIndex", () => {
// #TEST RegExp.lastIndex
const regex = /ab/g;
const str = 'ab ab ab';
const result1 = regex.exec(str)!;
console.log(result1.index);
console.log(regex.lastIndex);
// expected output:
// result1.index: 0
// regex.lastIndex: 2
const result2 = regex.exec(str)!;
console.log(result2.index);
console.log(regex.lastIndex);
// expected output:
// result2.index: 3
// regex.lastIndex: 5
const result3 = regex.exec(str)!;
console.log(result3.index);
console.log(regex.lastIndex);
// expected output:
// result3.index: 6
// regex.lastIndex: 8
// #END
expect(result1.index).toEqual(0);
expect(regex.lastIndex).toEqual(2);
const result2 = regex.exec(str)!;
expect(result2.index).toEqual(3);
expect(regex.lastIndex).toEqual(5);
const result3 = regex.exec(str)!;
expect(result3.index).toEqual(6);
expect(regex.lastIndex).toEqual(8);
})
});
test("multiline", () => {
// #TEST RegExp.multiline
const regex1 = new RegExp('foo', 'm');
expect(regex1.multiline).toEqual(true);
console.log(regex1.multiline);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.multiline);
// expected output: false
// #END
expect(regex1.multiline).toEqual(true);
expect(regex2.multiline).toEqual(false);
})
});
test("source", () => {
// #TEST RegExp.source
const regex1 = new RegExp('foo', 'ig');
expect(regex1.source).toEqual("foo");
console.log(regex1.source);
// expected output: "foo"
const regex2 = new RegExp('bar');
expect(regex2.source).toEqual("bar");
console.log(regex2.source);
// expected output: "bar"
const regex3 = /\w+/gi;
console.log(regex3.source);
// expected output: "\\w+"
const regex4 = new RegExp('\\d+', 'ig');
console.log(regex4.source);
// expected output: "\\d+"
// #END
expect(regex1.source).toEqual("foo");
expect(regex2.source).toEqual("bar");
expect(regex3.source).toEqual("\\w+");
const regex4 = new RegExp('\\d+', 'ig');;
expect(regex4.source).toEqual("\\d+");
})
});
test("sticky", () => {
// #TEST RegExp.sticky
const str1 = 'table football';
const regex1 = new RegExp('foo', 'y');
regex1.lastIndex = 6;
console.log(regex1.sticky);
// expected output: true
console.log(regex1.test(str1));
// expected output: true (the match starts at index 6)
// Reset the lastIndex to test non-match
regex1.lastIndex = 0;
console.log(regex1.test(str1));
// expected output: false (subsequent tests should fail since the lastIndex is at 0)
// #END
expect(regex1.sticky).toEqual(true);
expect(regex1.test(str1)).toEqual(true);
expect(regex1.test(str1)).toEqual(false);
})
});
// android 暂时不支持 unicode
// test("unicode", () => {
// const regex1 = new RegExp('foo', 'u');
...
...
@@ -108,9 +212,28 @@ export function testRegExp(): Result {
// })
test('test', () => {
// #TEST RegExp.test
const str = 'table football';
const regex = new RegExp('foo*');
const globalRegex = new RegExp('foo*', 'g');
console.log(regex.test(str));
// expected output: true
console.log(globalRegex.lastIndex);
// expected output: 0
console.log(globalRegex.test(str));
// expected output: true
console.log(globalRegex.lastIndex);
// expected output: 9
console.log(globalRegex.test(str));
// expected output: false
// #END
expect(regex.test(str)).toEqual(true);
expect(globalRegex.lastIndex).toEqual(0);
expect(globalRegex.test(str)).toEqual(true);
...
...
@@ -178,7 +301,7 @@ export function testRegExp(): Result {
// const re11 = /(?=a)?b/;
// expect(re11.test("b")).toEqual(true);
const isValidIdentifierName = (str: string)
: boolean => {
const isValidIdentifierName = (str : string)
: boolean => {
const reg =
/^(?!(?:break|case|catch)$)[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
return reg.test(str);
...
...
@@ -187,7 +310,7 @@ export function testRegExp(): Result {
expect(isValidIdentifierName("foo")).toEqual(true);
expect(isValidIdentifierName("cases")).toEqual(true);
const isASCIIIDPart = (char: string)
: boolean => {
const isASCIIIDPart = (char : string)
: boolean => {
return /^(?=\p{ASCII}$)\p{ID_Start}$/u.test(char);
}
expect(isASCIIIDPart("a")).toEqual(true);
...
...
@@ -199,8 +322,13 @@ export function testRegExp(): Result {
const result = pattern.exec('hi there');
expect(result).toEqual(null);
// #TEST RegExp.exec
const pattern1 = new RegExp('hello');
const result1 = pattern1.exec('hello world')!;
console.log(result1[0]) //'hello'
console.log(result1.index) //0
// #END
expect(result1[0]).toEqual('hello');
expect(result1.index).toEqual(0);
expect(result1.input).toEqual("hello world");
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录