提交 eebbfbf6 编写于 作者: 杜庆泉's avatar 杜庆泉

增加RegExp 构造器测试示例

上级 d5c39959
......@@ -2,6 +2,23 @@ import { describe, test, expect, Result } from './tests.uts'
export function testRegExp(): Result {
return describe("RegExp", () => {
test("constructor", () => {
// #ifdef APP-ANDROID
const str = 'table football';
const regex = new RegExp('foo*');
const globalRegex = new RegExp();
expect(regex.test(str)).toEqual(true);
expect(globalRegex.test(str)).toEqual(true);
let r2 = new RegExp(/ab+c/);
expect(r2.test(str)).toEqual(false);
let r3 = new RegExp(/foo/);
expect(r3.test(str)).toEqual(true);
// #endif
})
test("dotAll", () => {
const regex1 = new RegExp('foo', 's');
expect(regex1.dotAll).toEqual(true);
......
......@@ -56,6 +56,7 @@ export function testString(): Result {
expect(empty.charAt(0)).toEqual("");
})
test('toWellFormed', () => {
// #ifdef APP-ANDROID
expect("ab\uD800".toWellFormed()).toEqual("ab\uFFFD");
expect("ab\uD800c".toWellFormed()).toEqual("ab\uFFFDc");
expect("\uDFFFab".toWellFormed()).toEqual("\uFFFDab");
......@@ -64,8 +65,10 @@ export function testString(): Result {
expect("ab\uD83D\uDE04c".toWellFormed()).toEqual("ab\uD83D\uDE04c");
expect("ab\uD83D\uDE04c".toWellFormed()).toEqual("ab\uD83D\uDE04c");
expect("ab\uD83D\uDE04c\uD83D".toWellFormed()).toEqual("ab\uD83D\uDE04c\uFFFD");
// #endif
})
test('isWellFormed', () => {
// #ifdef APP-ANDROID
expect("ab\uD800".isWellFormed()).toEqual(false);
expect("ab\uD800c".isWellFormed()).toEqual(false);
expect("\uDFFFab".isWellFormed()).toEqual(false);
......@@ -74,6 +77,7 @@ export function testString(): Result {
expect("ab\uD83D\uDE04c".isWellFormed()).toEqual(true);
expect("ab\uD83D\uDE04c".isWellFormed()).toEqual(true);
expect("ab\uD83D\uDE04c\uD83D".isWellFormed()).toEqual(false);
// #endif
})
test('charCodeAt', () => {
const sentence = 'The quick brown fox jumps over the lazy dog.';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册