提交 98597711 编写于 作者: lizhongyi_'s avatar lizhongyi_

add string match示例

上级 36ab877c
......@@ -344,5 +344,9 @@ export function testArray(): Result {
// expect(iterator1.next().value).toEqual(2);
// expect(iterator1.next().done).toEqual(true);
})
test("toString", () => {
const array1 = [1, 2, 'a', '1a'];
expect(array1.toString()).toEqual("1,2,a,1a");
})
})
}
\ No newline at end of file
import { describe, test, expect, Result } from './tests.uts'
export function testBoolean(): Result {
return describe("Boolean", () => {
test('toString', () => {
const a = true;
expect(a.toString()).toEqual("true");
expect(true.toString()).toEqual("true");
expect(false.toString()).toEqual("false");
})
test('valueOf', () => {
const a = true;
expect(a.valueOf()).toEqual(true);
expect(true.valueOf()).toEqual(true);
expect(false.valueOf()).toEqual(false);
})
})
}
......@@ -20,8 +20,8 @@ export function testDate() : Result {
const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT');
const javaScriptRelease = Date.parse('04 Dec 1995 00:12:00 GMT');
expect(unixTimeZero.toString()).toEqual("Thu Jan 01 1970 08:00:00 GMT+0800");
expect(javaScriptRelease.toString()).toEqual("Mon Dec 04 1995 08:12:00 GMT+0800");
expect(unixTimeZero).toEqual(0);
expect(javaScriptRelease).toEqual(818035920000);
})
test('getDate', () => {
const birthday = new Date('August 19, 1975 23:15:30');
......
......@@ -148,8 +148,8 @@ export function testRegExp(): Result {
const re10 = new RegExp('^foo.bar$', 's');
expect(re10.test('foo\nbar')).toEqual(true);
const re11 = /(?=a)?b/;
expect(re11.test("b")).toEqual(true);
// const re11 = /(?=a)?b/;
// expect(re11.test("b")).toEqual(true);
const isValidIdentifierName = (str: string): boolean => {
const reg =
......
......@@ -108,25 +108,25 @@ export function testString(): Result {
expect("".indexOf("test")).toEqual(-1);
})
test('match', () => {
// const str = 'The quick brown fox jumps over the lazy dog. It barked.';
// const result = str.match(new RegExp('[A-Z]', 'g'));
// expect(result).toEqual(["T", "I"]);
// const str1 = 'For more information, see Chapter 3.4.5.1';
// const result1 = str1.match(/see (chapter \d+(\.\d)*)/i);
// expect(result1[0]).toEqual("see Chapter 3.4.5.1");
// expect(result1[1]).toEqual("Chapter 3.4.5.1");
// expect(result1[2]).toEqual(".1");
// expect(result1.index).toEqual(22);
// expect(result1.input).toEqual(str1);
// const str2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
// const result2 = str2.match(/[A-E]/gi);
// expect(result2).toEqual(['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']);
// const str3 = 'Nothing will come of nothing.';
// const result3 = str3.match();
// expect(result3).toEqual([""]);
const str = 'The quick brown fox jumps over the lazy dog. It barked.';
const result = str.match(new RegExp('[A-Z]', 'g'));
expect(result).toEqual(["T", "I"]);
const str1 = 'For more information, see Chapter 3.4.5.1';
const result1 = str1.match(/see (chapter \d+(\.\d)*)/i);
expect(result1[0]).toEqual("see Chapter 3.4.5.1");
expect(result1[1]).toEqual("Chapter 3.4.5.1");
expect(result1[2]).toEqual(".1");
expect(result1.index).toEqual(22);
expect(result1.input).toEqual(str1);
const str2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const result2 = str2.match(/[A-E]/gi);
expect(result2).toEqual(['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']);
const str3 = 'Nothing will come of nothing.';
const result3 = str3.match();
expect(result3).toEqual([""]);
})
test('padEnd', () => {
const str1 = 'Breaded Mushrooms';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册