From b9587262d4e854dff9f35e5520317ca21c8eb9d9 Mon Sep 17 00:00:00 2001
From: Mike Pennisi <mike@mikepennisi.com>
Date: Tue, 28 Jun 2016 19:05:08 -0400
Subject: [PATCH] Add tests for return value: 'get RegExp.p.source'

---
 .../RegExp/prototype/source/value-empty.js    | 25 +++++++++++++
 .../prototype/source/value-line-terminator.js | 29 +++++++++++++++
 .../RegExp/prototype/source/value-u.js        | 33 +++++++++++++++++
 .../RegExp/prototype/source/value.js          | 35 +++++++++++++++++++
 4 files changed, 122 insertions(+)
 create mode 100644 test/built-ins/RegExp/prototype/source/value-empty.js
 create mode 100644 test/built-ins/RegExp/prototype/source/value-line-terminator.js
 create mode 100644 test/built-ins/RegExp/prototype/source/value-u.js
 create mode 100644 test/built-ins/RegExp/prototype/source/value.js

diff --git a/test/built-ins/RegExp/prototype/source/value-empty.js b/test/built-ins/RegExp/prototype/source/value-empty.js
new file mode 100644
index 0000000000..c657bf2b93
--- /dev/null
+++ b/test/built-ins/RegExp/prototype/source/value-empty.js
@@ -0,0 +1,25 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-get-regexp.prototype.source
+es6id: 21.2.5.10
+description: >
+  Return value can be used to create an equivalent RegExp when the
+  [[OriginalSource]] internal slot is the empty string
+
+  21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern
+
+  [...] the internal procedure that would result from evaluating S as a
+  Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the
+  internal procedure given by the constructed object's [[RegExpMatcher]]
+  internal slot.
+info: |
+  [...]
+  5. Let src be R.[[OriginalSource]].
+  6. Let flags be R.[[OriginalFlags]].
+  7. Return EscapeRegExpPattern(src, flags).
+---*/
+
+var re = eval('/' + new RegExp('').source + '/');
+
+assert.sameValue(re.test(''), true);
diff --git a/test/built-ins/RegExp/prototype/source/value-line-terminator.js b/test/built-ins/RegExp/prototype/source/value-line-terminator.js
new file mode 100644
index 0000000000..6df7665e96
--- /dev/null
+++ b/test/built-ins/RegExp/prototype/source/value-line-terminator.js
@@ -0,0 +1,29 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-get-regexp.prototype.source
+es6id: 21.2.5.10
+description: >
+  Return value can be used to create an equivalent RegExp when the
+  [[OriginalSource]] internal slot contains a LineTerminator
+info: |
+  [...]
+  5. Let src be R.[[OriginalSource]].
+  6. Let flags be R.[[OriginalFlags]].
+  7. Return EscapeRegExpPattern(src, flags).
+
+  21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern
+
+  [...] the internal procedure that would result from evaluating S as a
+  Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the
+  internal procedure given by the constructed object's [[RegExpMatcher]]
+  internal slot.
+---*/
+
+var re = eval('/' + new RegExp('\n').source + '/');
+
+assert.sameValue(re.test('\n'), true, 'input: "\\n"');
+assert.sameValue(re.test('_\n_'), true, 'input: "_\\n_"');
+assert.sameValue(re.test('\\n'), false, 'input: "\\\\n"');
+assert.sameValue(re.test('\r'), false, 'input: "\\r"');
+assert.sameValue(re.test('n'), false, 'input: "n"');
diff --git a/test/built-ins/RegExp/prototype/source/value-u.js b/test/built-ins/RegExp/prototype/source/value-u.js
new file mode 100644
index 0000000000..221b3ca299
--- /dev/null
+++ b/test/built-ins/RegExp/prototype/source/value-u.js
@@ -0,0 +1,33 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-get-regexp.prototype.source
+es6id: 21.2.5.10
+description: >
+  Return value can be used to create an equivalent RegExp when the
+  [[OriginalFlags]] internal slot contains the `u` flag
+info: |
+  [...]
+  5. Let src be R.[[OriginalSource]].
+  6. Let flags be R.[[OriginalFlags]].
+  7. Return EscapeRegExpPattern(src, flags).
+
+  21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern
+
+  [...] the internal procedure that would result from evaluating S as a
+  Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the
+  internal procedure given by the constructed object's [[RegExpMatcher]]
+  internal slot.
+---*/
+
+var re;
+
+re = eval('/' + /\ud834\udf06/u.source + '/u');
+
+assert.sameValue(re.test('\ud834\udf06'), true);
+assert.sameValue(re.test('𝌆'), true);
+
+re = eval('/' + /\u{1d306}/u.source + '/u');
+
+assert.sameValue(re.test('\ud834\udf06'), true);
+assert.sameValue(re.test('𝌆'), true);
diff --git a/test/built-ins/RegExp/prototype/source/value.js b/test/built-ins/RegExp/prototype/source/value.js
new file mode 100644
index 0000000000..ee1718047d
--- /dev/null
+++ b/test/built-ins/RegExp/prototype/source/value.js
@@ -0,0 +1,35 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-get-regexp.prototype.source
+es6id: 21.2.5.10
+description: Return value can be used to create an equivalent RegExp
+info: |
+  [...]
+  5. Let src be R.[[OriginalSource]].
+  6. Let flags be R.[[OriginalFlags]].
+  7. Return EscapeRegExpPattern(src, flags).
+
+  21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern
+
+  [...] the internal procedure that would result from evaluating S as a
+  Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the
+  internal procedure given by the constructed object's [[RegExpMatcher]]
+  internal slot.
+---*/
+
+var re = eval('/' + /ab{2,4}c$/.source + '/');
+
+assert(re.test('abbc'), 'input: abbc');
+assert(re.test('abbbc'), 'input: abbbc');
+assert(re.test('abbbbc'), 'input: abbbbc');
+assert(re.test('xabbc'), 'input: xabbc');
+assert(re.test('xabbbc'), 'input: xabbbc');
+assert(re.test('xabbbbc'), 'input: xabbbbc');
+
+assert.sameValue(re.test('ac'), false, 'input: ac');
+assert.sameValue(re.test('abc'), false, 'input: abc');
+assert.sameValue(re.test('abbcx'), false, 'input: abbcx');
+assert.sameValue(re.test('bbc'), false, 'input: bbc');
+assert.sameValue(re.test('abb'), false, 'input: abb');
+assert.sameValue(re.test('abbbbbc'), false, 'input: abbbbbc');
-- 
GitLab