haikuwebkit/LayoutTests/js/regexp-named-capture-groups...

89 lines
6.2 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Test for of RegExp named capture groups
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS re1.toString() is "\/(?<month>\\d{2})\\/(?<day>\\d{2})\\/(?<year>\\d{4})\/"
PASS execResult1[0] is "01/02/2001"
PASS execResult1.groups.month is "01"
PASS execResult1.groups.day is "02"
PASS execResult1.groups.year is "2001"
PASS Object.getOwnPropertyNames(execResult1).sort() is ["0","1","2","3","groups","index","input","length"]
PASS Object.getOwnPropertyNames(execResult1.groups).sort() is ["day","month","year"]
PASS matchResult1[0] is "01/02/2001"
PASS matchResult1.groups.month is "01"
PASS matchResult1.groups.day is "02"
PASS matchResult1.groups.year is "2001"
PASS matchResult1.indices.groups.month is [0,2]
PASS matchResult1.indices.groups.day is [3,5]
PASS matchResult1.indices.groups.year is [6,10]
PASS Object.getOwnPropertyNames(matchResult1).sort() is ["0","1","2","3","groups","index","indices","input","length"]
PASS Object.getOwnPropertyNames(matchResult1.groups).sort() is ["day","month","year"]
PASS Object.getOwnPropertyNames(matchResult1.indices.groups).sort() is ["day","month","year"]
PASS matchResult2a[0] is "John W. Smith"
PASS matchResult2a[1] is "John"
PASS matchResult2a[2] is "W."
PASS matchResult2a[3] is "Smith"
PASS matchResult2a.indices[1] is [0,4]
PASS matchResult2a.indices[2] is [5,7]
PASS matchResult2a.indices[3] is [8,13]
PASS matchResult2a[1] is matchResult2a.groups.first_name
PASS matchResult2a[2] is matchResult2a.groups.middle_initial
PASS matchResult2a[3] is matchResult2a.groups.last_name
PASS Object.getOwnPropertyNames(matchResult1).sort() is ["0","1","2","3","groups","index","indices","input","length"]
PASS matchResult2b[0] is "Sally Brown"
PASS matchResult2b[1] is "Sally"
PASS matchResult2b[2] is undefined.
PASS matchResult2b[3] is "Brown"
PASS matchResult2b.indices[1] is [0,5]
PASS matchResult2b.indices[2] is undefined.
PASS matchResult2b.indices[3] is [6,11]
PASS matchResult2b[1] is matchResult2b.groups.first_name
PASS matchResult2b[2] is matchResult2b.groups.middle_initial
PASS matchResult2b[3] is matchResult2b.groups.last_name
PASS Object.getOwnPropertyNames(matchResult1).sort() is ["0","1","2","3","groups","index","indices","input","length"]
PASS re3.toString() is "\/^(?<part1>.*):(?<part2>.*):\\k<part2>:\\k<part1>$\/"
PASS re3.test("a:b:b:a") is true
PASS re3.test("a:a:a:a") is true
PASS re3.test("a:b:c:a") is false
PASS first is "1"
PASS second is "2"
PASS result4 is "14.02.2010"
PASS "third edition".match(/(?<auf\u200clage>\w+) edition/).groups.auf\u200clage is "third"
PASS "fourth edition".match(/(?<auf\u200dlage>\w+) edition/).groups.auf\u200dlage is "fourth"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$<month>-$<year>") is "20-10-1930"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$2-$<month>-$<year>") is "20-10-1930"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$1-$<year>") is "20-10-1930"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$<month>-$3") is "20-10-1930"
PASS "Replace just THIS in this string".replace(/THIS/, "$<THAT>") is "Replace just $<THAT> in this string"
PASS "Give me a \'k\'!".match(/Give me a \'\k\'/)[0] is "Give me a \'k\'"
PASS "Give me \'k2\'!".match(/Give me \'\k2\'/)[0] is "Give me \'k2\'"
PASS "Give me a \'kat\'!".match(/Give me a \'\kat\'/)[0] is "Give me a \'kat\'"
PASS "Give me a \'k\'!".match(/Give me a \'\k\'/u)[0] threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern.
PASS "Give me \'k2\'!".match(/Give me \'\k2\'/u)[0] threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern.
PASS "Give me a \'kat\'!".match(/Give me a \'\kat\'/u)[0] threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern.
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$<mouth>-$<year>") is "20--1930"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$<month>-$<year") is "20-10-$<year"
PASS let r = new RegExp("/(?<groupName1>abc)|(?<groupName1>def)/") threw exception SyntaxError: Invalid regular expression: duplicate group specifier name.
PASS let r = new RegExp("/(?< groupName1>abc)/") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<g=oupName1>abc)/") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<𐆐groupName1>abc)/u") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<g𐆛oupName1>abc)/u") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<groupName1>abc)/u") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<groupName1>abc)/u") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS /(?<\u>.)/u threw exception SyntaxError: Invalid regular expression: invalid Unicode \u escape.
PASS /\k<\uzzz>/u threw exception SyntaxError: Invalid regular expression: invalid Unicode \u escape.
PASS /(?<\u{>.)/u threw exception SyntaxError: Invalid regular expression: invalid Unicode code point \u{} escape.
PASS /\k<\u{0>/u threw exception SyntaxError: Invalid regular expression: invalid Unicode code point \u{} escape.
PASS "XzzXzz".match(/\k<z>X(?<z>z*)X\k<z>/) is ["XzzXzz", "zz"]
PASS "XzzXzz".match(/\k<z>X(?<z>z*)X\k<z>/u) is ["XzzXzz", "zz"]
PASS "1122332211".match(/\k<ones>\k<twos>\k<threes>(?<ones>1*)(?<twos>2*)(?<threes>3*)\k<threes>\k<twos>\k<ones>/) is ["1122332211", "11", "22", "3"]
PASS "1122332211".match(/\k<ones>\k<twos>\k<threes>(?<ones>1*)(?<twos>2*)(?<threes>3*)\k<threes>\k<twos>\k<ones>/u) is ["1122332211", "11", "22", "3"]
PASS "\k<z>XzzX".match(/\k<z>X(z*)X/) is ["k<z>XzzX", "zz"]
PASS "\k<z>XzzX".match(/\k<z>X(z*)X/u) threw exception SyntaxError: Invalid regular expression: invalid \k<> named backreference.
PASS /\k<xxx(?<a>y)(/ threw exception SyntaxError: Invalid regular expression: invalid \k<> named backreference.
PASS successfullyParsed is true
TEST COMPLETE