mirror of https://github.com/tc39/test262.git
Improve RegExp.prototype.flags coverage (#1149)
This commit is contained in:
parent
ccaf340d85
commit
d91044c788
|
@ -0,0 +1,61 @@
|
|||
// Copyright (C) 2017 Aleksey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-regexp.prototype.flags
|
||||
description: Boolean coercion of properties
|
||||
info: >
|
||||
get RegExp.prototype.flags
|
||||
|
||||
[...]
|
||||
4. Let global be ToBoolean(? Get(R, "global")).
|
||||
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
|
||||
8. Let multiline be ToBoolean(? Get(R, "multiline")).
|
||||
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
|
||||
12. Let unicode be ToBoolean(? Get(R, "unicode")).
|
||||
14. Let sticky be ToBoolean(? Get(R, "sticky")).
|
||||
features: [Symbol, regexp-dotall]
|
||||
---*/
|
||||
|
||||
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
|
||||
var flags = [
|
||||
['g', 'global'],
|
||||
['i', 'ignoreCase'],
|
||||
['m', 'multiline'],
|
||||
['s', 'dotAll'],
|
||||
['u', 'unicode'],
|
||||
['y', 'sticky'],
|
||||
];
|
||||
|
||||
flags.forEach(function(flag) {
|
||||
var res = flag[0];
|
||||
var key = flag[1];
|
||||
var r = {};
|
||||
|
||||
r[key] = undefined;
|
||||
assert.sameValue(get.call(r), '', key + ' = undefined');
|
||||
|
||||
r[key] = null;
|
||||
assert.sameValue(get.call(r), '', key + ' = null');
|
||||
|
||||
r[key] = NaN;
|
||||
assert.sameValue(get.call(r), '', key + ' = NaN');
|
||||
|
||||
r[key] = '';
|
||||
assert.sameValue(get.call(r), '', key + ' = ""');
|
||||
|
||||
r[key] = 'string';
|
||||
assert.sameValue(get.call(r), res, key + ' = "string"');
|
||||
|
||||
r[key] = 86;
|
||||
assert.sameValue(get.call(r), res, key + ' = 86');
|
||||
|
||||
r[key] = Symbol();
|
||||
assert.sameValue(get.call(r), res, key + ' = Symbol()');
|
||||
|
||||
r[key] = [];
|
||||
assert.sameValue(get.call(r), res, key + ' = []');
|
||||
|
||||
r[key] = {};
|
||||
assert.sameValue(get.call(r), res, key + ' = {}');
|
||||
});
|
|
@ -2,6 +2,7 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-regexp.prototype.flags
|
||||
es6id: 21.2.5.3
|
||||
description: >
|
||||
get RegExp.prototype.flags.length is 0.
|
||||
|
@ -22,10 +23,11 @@ info: >
|
|||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags");
|
||||
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
|
||||
|
||||
assert.sameValue(desc.get.length, 0);
|
||||
|
||||
verifyNotEnumerable(desc.get, "length");
|
||||
verifyNotWritable(desc.get, "length");
|
||||
verifyConfigurable(desc.get, "length");
|
||||
verifyProperty(get, 'length', {
|
||||
value: 0,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
// Copyright (C) 2015 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.flags
|
||||
es6id: 21.2.5.3
|
||||
description: >
|
||||
RegExp.prototype.flags name
|
||||
get RegExp.prototype.flags.name is "get flags".
|
||||
info: >
|
||||
get RegExp.prototype.flags
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
Functions that are specified as get or set accessor functions of built-in
|
||||
properties have "get " or "set " prepended to the property name string.
|
||||
|
||||
Unless otherwise specified, the name property of a built-in function object,
|
||||
if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||
[[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags');
|
||||
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
|
||||
|
||||
assert.sameValue(
|
||||
descriptor.get.name,
|
||||
'get flags'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(descriptor.get, 'name');
|
||||
verifyNotWritable(descriptor.get, 'name');
|
||||
verifyConfigurable(descriptor.get, 'name');
|
||||
verifyProperty(get, 'name', {
|
||||
value: 'get flags',
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2017 Aleksey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-regexp.prototype.flags
|
||||
description: Gets are performed in specified order
|
||||
info: >
|
||||
get RegExp.prototype.flags
|
||||
|
||||
[...]
|
||||
4. Let global be ToBoolean(? Get(R, "global")).
|
||||
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
|
||||
8. Let multiline be ToBoolean(? Get(R, "multiline")).
|
||||
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
|
||||
12. Let unicode be ToBoolean(? Get(R, "unicode")).
|
||||
14. Let sticky be ToBoolean(? Get(R, "sticky")).
|
||||
features: [regexp-dotall]
|
||||
---*/
|
||||
|
||||
var calls = '';
|
||||
var re = {
|
||||
get global() {
|
||||
calls += 'g';
|
||||
},
|
||||
get ignoreCase() {
|
||||
calls += 'i';
|
||||
},
|
||||
get multiline() {
|
||||
calls += 'm';
|
||||
},
|
||||
get dotAll() {
|
||||
calls += 's';
|
||||
},
|
||||
get unicode() {
|
||||
calls += 'u';
|
||||
},
|
||||
get sticky() {
|
||||
calls += 'y';
|
||||
},
|
||||
};
|
||||
|
||||
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
|
||||
|
||||
assert.sameValue(get.call(re), '');
|
||||
assert.sameValue(calls, 'gimsuy');
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2017 Aleksey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-regexp.prototype.flags
|
||||
description: >
|
||||
get RegExp.prototype.flags property descriptor
|
||||
info: >
|
||||
get RegExp.prototype.flags
|
||||
|
||||
RegExp.prototype.flags is an accessor property whose set accessor
|
||||
function is undefined
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var d = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags');
|
||||
|
||||
assert.sameValue(typeof d.get, 'function', 'typeof d.get');
|
||||
assert.sameValue(d.set, undefined, 'd.set');
|
||||
|
||||
verifyProperty(RegExp.prototype, 'flags', {
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright (C) 2017 Aleksey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-regexp.prototype.flags
|
||||
description: Rethrows exceptions raised in property gets
|
||||
info: >
|
||||
get RegExp.prototype.flags
|
||||
|
||||
[...]
|
||||
4. Let global be ToBoolean(? Get(R, "global")).
|
||||
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
|
||||
8. Let multiline be ToBoolean(? Get(R, "multiline")).
|
||||
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
|
||||
12. Let unicode be ToBoolean(? Get(R, "unicode")).
|
||||
14. Let sticky be ToBoolean(? Get(R, "sticky")).
|
||||
features: [regexp-dotall]
|
||||
---*/
|
||||
|
||||
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
get.call({
|
||||
get global() {
|
||||
throw new Test262Error();
|
||||
},
|
||||
});
|
||||
}, 'global');
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
get.call({
|
||||
get ignoreCase() {
|
||||
throw new Test262Error();
|
||||
},
|
||||
});
|
||||
}, 'ignoreCase');
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
get.call({
|
||||
get multiline() {
|
||||
throw new Test262Error();
|
||||
},
|
||||
});
|
||||
}, 'multiline');
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
get.call({
|
||||
get dotAll() {
|
||||
throw new Test262Error();
|
||||
},
|
||||
});
|
||||
}, 'dotAll');
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
get.call({
|
||||
get unicode() {
|
||||
throw new Test262Error();
|
||||
},
|
||||
});
|
||||
}, 'unicode');
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
get.call({
|
||||
get sticky() {
|
||||
throw new Test262Error();
|
||||
},
|
||||
});
|
||||
}, 'sticky');
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
's' entry's presence is determined by `s` flag
|
||||
esid: sec-get-regexp.prototype.flags
|
||||
info: >
|
||||
21.2.5.3 get RegExp.prototype.flags
|
||||
|
||||
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
|
||||
11. If dotAll is true, append "s" as the last code unit of result.
|
||||
features: [regexp-dotall]
|
||||
---*/
|
||||
|
||||
var flags;
|
||||
|
||||
flags = /./s.flags;
|
||||
assert.sameValue(flags, 's');
|
||||
|
||||
let re = /./;
|
||||
Object.defineProperty(re, 'dotAll', {value: true});
|
||||
assert.sameValue(re.flags, 's');
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2017 Aleksey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-regexp.prototype.flags
|
||||
description: A TypeError is thrown when the `this` value is not an Object
|
||||
info: |
|
||||
1. Let R be the this value.
|
||||
2. If Type(R) is not Object, throw a TypeError exception.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
get.call(undefined);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
get.call(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
get.call(4);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
get.call('string');
|
||||
}, 'string');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
get.call(false);
|
||||
}, 'boolean');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
get.call(Symbol());
|
||||
}, 'symbol');
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2016 Aleksey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-regexp.prototype.flags
|
||||
description: >
|
||||
Return "" when the `this` value is the RegExp.prototype object
|
||||
info: |
|
||||
1. Let R be the this value.
|
||||
2. If Type(R) is not Object, throw a TypeError exception.
|
||||
3. Let result be the empty String.
|
||||
---*/
|
||||
|
||||
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
|
||||
|
||||
assert.sameValue(get.call(RegExp.prototype), '');
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Aleksey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-get-regexp.prototype.flags
|
||||
description: >
|
||||
RegExp.prototype.flags returns RegExp flags as a string
|
||||
info: |
|
||||
1. Let R be the this value.
|
||||
2. If Type(R) is not Object, throw a TypeError exception.
|
||||
features: [regexp-dotall]
|
||||
---*/
|
||||
|
||||
assert.sameValue(/./.flags, '', 'no flags');
|
||||
assert.sameValue(/./g.flags, 'g', 'global');
|
||||
assert.sameValue(/./i.flags, 'i', 'ignoreCase');
|
||||
assert.sameValue(/./m.flags, 'm', 'multiline');
|
||||
assert.sameValue(/./s.flags, 's', 'dotAll');
|
||||
assert.sameValue(/./u.flags, 'u', 'unicode');
|
||||
assert.sameValue(/./y.flags, 'y', 'sticky');
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Errors thrown when retrieving attribute
|
||||
es6id: 21.2.5.3
|
||||
info: >
|
||||
21.2.5.3 get RegExp.prototype.flags
|
||||
|
||||
[...]
|
||||
13. Let unicode be ToBoolean(Get(R, "unicode")).
|
||||
14. ReturnIfAbrupt(unicode).
|
||||
---*/
|
||||
|
||||
var re = /./;
|
||||
|
||||
Object.defineProperty(re, 'unicode', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
re.flags;
|
||||
});
|
|
@ -1,55 +0,0 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Boolean coercion of `unicode` property
|
||||
es6id: 21.2.5.3
|
||||
info: >
|
||||
21.2.5.3 get RegExp.prototype.flags
|
||||
|
||||
[...]
|
||||
13. Let unicode be ToBoolean(Get(R, "unicode")).
|
||||
14. ReturnIfAbrupt(unicode).
|
||||
15. If unicode is true, append "u" as the last code unit of result.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
var flags;
|
||||
Object.defineProperty(r, 'unicode', { writable: true });
|
||||
|
||||
r.unicode = undefined;
|
||||
flags = r.flags;
|
||||
assert.sameValue(flags.length, 0);
|
||||
|
||||
r.unicode = null;
|
||||
flags = r.flags;
|
||||
assert.sameValue(flags.length, 0);
|
||||
|
||||
r.unicode = NaN;
|
||||
flags = r.flags;
|
||||
assert.sameValue(flags.length, 0);
|
||||
|
||||
r.unicode = 86;
|
||||
flags = r.flags;
|
||||
assert.sameValue(flags.length, 1);
|
||||
assert.sameValue(flags[0], 'u');
|
||||
|
||||
r.unicode = '';
|
||||
flags = r.flags;
|
||||
assert.sameValue(flags.length, 0);
|
||||
|
||||
r.unicode = 'string';
|
||||
flags = r.flags;
|
||||
assert.sameValue(flags.length, 1);
|
||||
assert.sameValue(flags[0], 'u');
|
||||
|
||||
r.unicode = Symbol();
|
||||
flags = r.flags;
|
||||
assert.sameValue(flags.length, 1);
|
||||
assert.sameValue(flags[0], 'u');
|
||||
|
||||
r.unicode = {};
|
||||
flags = r.flags;
|
||||
assert.sameValue(flags.length, 1);
|
||||
assert.sameValue(flags[0], 'u');
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
'u' entry's presence is determined by `u` flag
|
||||
es6id: 21.2.5.3
|
||||
info: >
|
||||
21.2.5.3 get RegExp.prototype.flags
|
||||
|
||||
[...]
|
||||
13. Let unicode be ToBoolean(Get(R, "unicode")).
|
||||
14. ReturnIfAbrupt(unicode).
|
||||
15. If unicode is true, append "u" as the last code unit of result.
|
||||
---*/
|
||||
|
||||
var flags;
|
||||
|
||||
flags = /./.flags;
|
||||
assert.sameValue(flags.length, 0);
|
||||
|
||||
flags = /./u.flags;
|
||||
assert.sameValue(flags.length, 1);
|
||||
assert.sameValue(flags[0], 'u');
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior if error is thrown when retrieving `sticky` attribute
|
||||
es6id: 21.2.5.3
|
||||
info: >
|
||||
21.2.5.3 get RegExp.prototype.flags
|
||||
|
||||
16. Let sticky be ToBoolean(Get(R, "sticky")).
|
||||
17. ReturnIfAbrupt(sticky).
|
||||
---*/
|
||||
|
||||
var re = /./;
|
||||
|
||||
Object.defineProperty(re, 'sticky', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
re.flags;
|
||||
});
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
'y' entry's presence is determined by `y` flag
|
||||
es6id: 21.2.5.3
|
||||
info: >
|
||||
21.2.5.3 get RegExp.prototype.flags
|
||||
|
||||
16. Let sticky be ToBoolean(Get(R, "sticky")).
|
||||
17. ReturnIfAbrupt(sticky).
|
||||
18. If sticky is true, append "y" as the last code unit of result.
|
||||
---*/
|
||||
|
||||
var flags;
|
||||
|
||||
flags = /./.flags;
|
||||
assert.sameValue(flags.length, 0);
|
||||
|
||||
flags = /./y.flags;
|
||||
assert.sameValue(flags.length, 1);
|
||||
assert.sameValue(flags[0], 'y');
|
Loading…
Reference in New Issue