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

正则表达式相关测试断言调整

上级 1f1082f4
......@@ -236,11 +236,11 @@ export function testRegExp(): Result {
const CHUNK_REGEXP =
/^(\S*)?\s*(\d*\.?\d+(?:ms|s)?)?\s*(\S*)?\s*(\d*\.?\d+(?:ms|s)?)?$/
const match2 = CHUNK_REGEXP.exec('none')
expect(match2!![0]).toEqual("none");
expect(match2!![1]).toEqual("none");
expect(JSON.stringify(match2!![2])).toEqual("null");
expect(JSON.stringify(match2!![3])).toEqual("null");
expect(JSON.stringify(match2!![4])).toEqual("null");
expect(match2![0]).toEqual("none");
expect(match2![1]).toEqual("none");
expect(JSON.stringify(match2![2])).toEqual("null");
expect(JSON.stringify(match2![3])).toEqual("null");
expect(JSON.stringify(match2![4])).toEqual("null");
})
})
......
......@@ -115,27 +115,27 @@ export function testString(): Result {
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!!.length).toEqual(2);
expect(result!![0]).toEqual("T");
expect(result!![1]).toEqual("I");
expect(result!.length).toEqual(2);
expect(result![0]).toEqual("T");
expect(result![1]).toEqual("I");
const result2 = str.match(new RegExp('[A-Z]'));
expect(result2!!.length).toEqual(1);
expect(result2!![0]).toEqual("T");
expect(result2!.length).toEqual(1);
expect(result2![0]).toEqual("T");
const gradientString = 'linear-gradient(to right, rgb(255, 0, 0), #00FF00, hsl(120, 100%, 50%))';
const pattern = /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)|#([a-fA-F0-9]{2}){3}|hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)/g;
const result3 = gradientString.match(pattern);
expect(result3!!.length).toEqual(3);
expect(result3!![0]).toEqual("rgb(255, 0, 0)");
expect(result3!![2]).toEqual("hsl(120, 100%, 50%)");
expect(result3!.length).toEqual(3);
expect(result3![0]).toEqual("rgb(255, 0, 0)");
expect(result3![2]).toEqual("hsl(120, 100%, 50%)");
const pattern2 = /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)|#([a-fA-F0-9]{2}){3}|hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)/;
const result4 = gradientString.match(pattern2);
expect(result4!!.length).toEqual(8);
expect(result4!![0]).toEqual("rgb(255, 0, 0)");
expect(result4!![1]).toEqual("255");
expect(result4!![2]).toEqual("0");
expect(result4!.length).toEqual(8);
expect(result4![0]).toEqual("rgb(255, 0, 0)");
expect(result4![1]).toEqual("255");
expect(result4![2]).toEqual("0");
const url = '';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册