| OLD | NEW |
| (Empty) |
| 1 description( | |
| 2 "This page tests invalid character ranges in character classes." | |
| 3 ); | |
| 4 | |
| 5 // These test a basic range / non range. | |
| 6 shouldBe('/[a-c]+/.exec("-acbd");', '["acb"]'); | |
| 7 shouldBe('/[a\\-c]+/.exec("-acbd")', '["-ac"]'); | |
| 8 | |
| 9 // A reverse-range is invalid. | |
| 10 shouldThrow('/[c-a]+/.exec("-acbd");'); | |
| 11 | |
| 12 // A character-class in a range is invalid, according to ECMA-262, but we allow
it. | |
| 13 shouldBe('/[\\d-x]+/.exec("1-3xy");', '["1-3x"]'); | |
| 14 shouldBe('/[x-\\d]+/.exec("1-3xy");', '["1-3x"]'); | |
| 15 shouldBe('/[\\d-\\d]+/.exec("1-3xy");', '["1-3"]'); | |
| 16 | |
| 17 // Whilst we break with ECMA-262's definition of CharacterRange, we do comply wi
th | |
| 18 // the grammar, and as such in the following regex a-z cannot be matched as a ra
nge. | |
| 19 shouldBe('/[\\d-a-z]+/.exec("az1-3y");', '["az1-3"]'); | |
| 20 | |
| 21 // An escaped hypen should not be confused for an invalid range. | |
| 22 shouldBe('/[\\d\\-x]+/.exec("1-3xy");', '["1-3x"]'); | |
| 23 shouldBe('/[x\\-\\d]+/.exec("1-3xy");', '["1-3x"]'); | |
| 24 shouldBe('/[\\d\\-\\d]+/.exec("1-3xy");', '["1-3"]'); | |
| 25 | |
| 26 // A hyphen after a character-class is not invalid. | |
| 27 shouldBe('/[\\d-]+/.exec("1-3xy")', '["1-3"]'); | |
| OLD | NEW |