mirror of https://github.com/tc39/test262.git
String.prototype.normalize
This commit is contained in:
parent
7992be11ed
commit
95349fcb2c
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Throws a RangeError if ToString(form) value is not a valid form name.
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
...
|
||||
7. If f is not one of "NFC", "NFD", "NFKC", or "NFKD", throw a RangeError
|
||||
exception.
|
||||
---*/
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
'foo'.normalize('bar');
|
||||
});
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
'foo'.normalize('NFC1');
|
||||
});
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
'foo'.normalize(null);
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
String.prototype.normalize.length value and descriptor.
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
String.prototype.normalize.length, 0,
|
||||
'The value of `String.prototype.normalize.length` is `0`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(String.prototype.normalize, 'length');
|
||||
verifyNotWritable(String.prototype.normalize, 'length');
|
||||
verifyConfigurable(String.prototype.normalize, 'length');
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
String.prototype.normalize.name value and descriptor.
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
String.prototype.normalize.name, 'normalize',
|
||||
'The value of `String.prototype.normalize.name` is `"normalize"`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(String.prototype.normalize, 'name');
|
||||
verifyNotWritable(String.prototype.normalize, 'name');
|
||||
verifyConfigurable(String.prototype.normalize, 'name');
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Property type and descriptor.
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof String.prototype.normalize,
|
||||
'function',
|
||||
'`typeof String.prototype.normalize` is `function`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(String.prototype, 'normalize');
|
||||
verifyWritable(String.prototype, 'normalize');
|
||||
verifyConfigurable(String.prototype, 'normalize');
|
21
test/built-ins/String/prototype/normalize/return-abrupt-from-form-as-symbol.js
vendored
Normal file
21
test/built-ins/String/prototype/normalize/return-abrupt-from-form-as-symbol.js
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Returns abrupt from ToString(form) as a Symbol.
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
...
|
||||
4. If form is not provided or form is undefined, let form be "NFC".
|
||||
5. Let f be ToString(form).
|
||||
6. ReturnIfAbrupt(f).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol('foo');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
'foo'.normalize(s);
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Returns abrupt from ToString(form)
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
...
|
||||
4. If form is not provided or form is undefined, let form be "NFC".
|
||||
5. Let f be ToString(form).
|
||||
6. ReturnIfAbrupt(f).
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
'foo'.normalize(o);
|
||||
});
|
20
test/built-ins/String/prototype/normalize/return-abrupt-from-this-as-symbol.js
vendored
Normal file
20
test/built-ins/String/prototype/normalize/return-abrupt-from-this-as-symbol.js
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Returns abrupt from ToString(this) where this is a Symbol
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
3. ReturnIfAbrupt(S).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol('foo');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
String.prototype.normalize.call(s);
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Returns abrupt from ToString(this)
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
3. ReturnIfAbrupt(S).
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
String.prototype.normalize.call(o);
|
||||
});
|
37
test/built-ins/String/prototype/normalize/return-normalized-string-from-coerced-form.js
vendored
Normal file
37
test/built-ins/String/prototype/normalize/return-normalized-string-from-coerced-form.js
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Returns normalized string from coerced form.
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
...
|
||||
4. If form is not provided or form is undefined, let form be "NFC".
|
||||
5. Let f be ToString(form).
|
||||
6. ReturnIfAbrupt(f).
|
||||
7. If f is not one of "NFC", "NFD", "NFKC", or "NFKD", throw a RangeError
|
||||
exception.
|
||||
8. Let ns be the String value that is the result of normalizing S into the
|
||||
normalization form named by f as specified in
|
||||
http://www.unicode.org/reports/tr15/tr15-29.html.
|
||||
9. Return ns.
|
||||
---*/
|
||||
|
||||
var s = '\u00C5\u2ADC\u0958\u2126\u0344';
|
||||
var nfc = '\xC5\u2ADD\u0338\u0915\u093C\u03A9\u0308\u0301';
|
||||
var nfd = 'A\u030A\u2ADD\u0338\u0915\u093C\u03A9\u0308\u0301';
|
||||
var o = {
|
||||
toString: function() { return 'NFC'; }
|
||||
};
|
||||
|
||||
assert.sameValue(s.normalize(['NFC']), nfc, 'coerced array - NFC');
|
||||
assert.sameValue(s.normalize(o), nfc, 'coerced object - NFC');
|
||||
|
||||
o = {
|
||||
toString: function() { return 'NFD'; }
|
||||
};
|
||||
|
||||
assert.sameValue(s.normalize(['NFD']), nfd, 'coerced array - NFD');
|
||||
assert.sameValue(s.normalize(o), nfd, 'coerced object - NFD');
|
23
test/built-ins/String/prototype/normalize/return-normalized-string-using-default-parameter.js
vendored
Normal file
23
test/built-ins/String/prototype/normalize/return-normalized-string-using-default-parameter.js
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Returns normalized string.
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
...
|
||||
4. If form is not provided or form is undefined, let form be "NFC".
|
||||
...
|
||||
8. Let ns be the String value that is the result of normalizing S into the
|
||||
normalization form named by f as specified in
|
||||
http://www.unicode.org/reports/tr15/tr15-29.html.
|
||||
9. Return ns.
|
||||
---*/
|
||||
|
||||
var s = '\u00C5\u2ADC\u0958\u2126\u0344';
|
||||
var nfc = '\xC5\u2ADD\u0338\u0915\u093C\u03A9\u0308\u0301';
|
||||
|
||||
assert.sameValue(s.normalize(), nfc, 'Use NFC as the default form');
|
||||
assert.sameValue(s.normalize(undefined), nfc, 'Use NFC as the default form');
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Returns normalized string.
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
...
|
||||
7. If f is not one of "NFC", "NFD", "NFKC", or "NFKD", throw a RangeError
|
||||
exception.
|
||||
8. Let ns be the String value that is the result of normalizing S into the
|
||||
normalization form named by f as specified in
|
||||
http://www.unicode.org/reports/tr15/tr15-29.html.
|
||||
9. Return ns.
|
||||
---*/
|
||||
|
||||
var s = '\u1E9B\u0323';
|
||||
|
||||
assert.sameValue(s.normalize('NFC'), '\u1E9B\u0323', 'Normalized on NFC');
|
||||
assert.sameValue(s.normalize('NFD'), '\u017F\u0323\u0307', 'Normalized on NFD');
|
||||
assert.sameValue(s.normalize('NFKC'), '\u1E69', 'Normalized on NFKC');
|
||||
assert.sameValue(s.normalize('NFKD'), '\u0073\u0323\u0307', 'Normalized on NFKD');
|
||||
|
||||
assert.sameValue(
|
||||
'\u00C5\u2ADC\u0958\u2126\u0344'.normalize('NFC'),
|
||||
'\xC5\u2ADD\u0338\u0915\u093C\u03A9\u0308\u0301',
|
||||
'Normalized on NFC'
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
'\u00C5\u2ADC\u0958\u2126\u0344'.normalize('NFD'),
|
||||
'A\u030A\u2ADD\u0338\u0915\u093C\u03A9\u0308\u0301',
|
||||
'Normalized on NFD'
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
'\u00C5\u2ADC\u0958\u2126\u0344'.normalize('NFKC'),
|
||||
'\xC5\u2ADD\u0338\u0915\u093C\u03A9\u0308\u0301',
|
||||
'Normalized on NFKC'
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
'\u00C5\u2ADC\u0958\u2126\u0344'.normalize('NFKD'),
|
||||
'A\u030A\u2ADD\u0338\u0915\u093C\u03A9\u0308\u0301',
|
||||
'Normalized on NFKD'
|
||||
);
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Throws TypeError when `this` is null
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
String.prototype.normalize.call(null);
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.12
|
||||
description: >
|
||||
Throws TypeError when `this` is undefined
|
||||
info: >
|
||||
21.1.3.12 String.prototype.normalize ( [ form ] )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
String.prototype.normalize.call(undefined);
|
||||
});
|
Loading…
Reference in New Issue