regress-219.js 4.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Tests handling of flags for regexps.

// We should now allow duplicates of flags.
// (See http://code.google.com/p/v8/issues/detail?id=219)

33 34 35 36
// This has been reversed by issue 1628, since other browsers have also
// tightened their syntax.
// (See http://code.google.com/p/v8/issues/detail?id=1628)

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
// Base tests: we recognize the basic flags

function assertFlags(re, global, multiline, ignoreCase) {
  var name = re + " flag: ";
  (global ? assertTrue : assertFalse)(re.global, name + "g");
  (multiline ? assertTrue : assertFalse)(re.multiline, name + "m");
  (ignoreCase ? assertTrue : assertFalse)(re.ignoreCase, name + "i");
}

var re = /a/;
assertFlags(re, false, false, false)

re = /a/gim;
assertFlags(re, true, true, true)

re = RegExp("a","");
assertFlags(re, false, false, false)

re = RegExp("a", "gim");
assertFlags(re, true, true, true)

// Double i's

60
assertThrows("/a/ii");
61

62
assertThrows("/a/gii");
63

64
assertThrows("/a/igi");
65

66
assertThrows("/a/iig");
67

68
assertThrows("/a/gimi");
69

70
assertThrows("/a/giim");
71

72
assertThrows("/a/igim");
73

74
assertThrows(function(){ return RegExp("a", "ii"); })
75

76
assertThrows(function(){ return RegExp("a", "gii"); })
77

78
assertThrows(function(){ return RegExp("a", "igi"); })
79

80
assertThrows(function(){ return RegExp("a", "iig"); })
81

82
assertThrows(function(){ return RegExp("a", "gimi"); })
83

84
assertThrows(function(){ return RegExp("a", "giim"); })
85

86
assertThrows(function(){ return RegExp("a", "igim"); })
87 88 89

// Tripple i's

90
assertThrows("/a/iii");
91

92
assertThrows("/a/giii");
93

94
assertThrows("/a/igii");
95

96
assertThrows("/a/iigi");
97

98
assertThrows("/a/iiig");
99

100
assertThrows("/a/miiig");
101

102
assertThrows(function(){ return RegExp("a", "iii"); })
103

104
assertThrows(function(){ return RegExp("a", "giii"); })
105

106
assertThrows(function(){ return RegExp("a", "igii"); })
107

108
assertThrows(function(){ return RegExp("a", "iigi"); })
109

110
assertThrows(function(){ return RegExp("a", "iiig"); })
111

112
assertThrows(function(){ return RegExp("a", "miiig"); })
113

114
// Illegal flags - valid flags late in string.
115

116
assertThrows("/a/arglebargleglopglyf");
117

118
assertThrows("/a/arglebargleglopglif");
119

120
assertThrows("/a/arglebargleglopglym");
121

122
assertThrows("/a/arglebargleglopglim");
123 124 125

// Case of flags still matters.

126
var re = /a/gmi;
127 128
assertFlags(re, true, true, true)

129
assertThrows("/a/Gmi");
130

131
assertThrows("/a/gMi");
132

133
assertThrows("/a/gmI");
134

135
assertThrows("/a/GMi");
136

137
assertThrows("/a/GmI");
138

139
assertThrows("/a/gMI");
140

141 142 143 144 145 146 147 148
assertThrows("/a/GMI");

// Unicode escape sequences are not interpreted.

assertThrows("/a/\\u0067");
assertThrows("/a/\\u0069");
assertThrows("/a/\\u006d");
assertThrows("/a/\\u006D");