summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/annexB/built-ins/String/prototype/substr/surrogate-pairs.js
blob: 605596d33512773c51895f37f5bb4b7276a8f468 (plain)
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
// 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-string.prototype.substr
es6id: B.2.3.1
description: >
    Behavior when input string contains a surrogate pair
info: |
    [...]
    4. If length is undefined, let end be +∞; otherwise let end be ?
       ToInteger(length).
    [...]
    7. Let resultLength be min(max(end, 0), size - intStart).
    8. If resultLength ≤ 0, return the empty String "".
    9. Return a String containing resultLength consecutive code units from S
       beginning with the code unit at index intStart.
---*/

assert.sameValue('\ud834\udf06'.substr(0), '\ud834\udf06', 'start: 0');
assert.sameValue('\ud834\udf06'.substr(1), '\udf06', 'start: 1');
assert.sameValue('\ud834\udf06'.substr(2), '', 'start: 2');
assert.sameValue('\ud834\udf06'.substr(0, 0), '', 'end: 0');
assert.sameValue('\ud834\udf06'.substr(0, 1), '\ud834', 'end: 1');
assert.sameValue('\ud834\udf06'.substr(0, 2), '\ud834\udf06', 'end: 2');

reportCompare(0, 0);