Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/addition/coerce-bigint-to-string.js

raw
1 // Copyright (C) 2017 Robin Templeton. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 description: ToString is applied BigInt values in an additive expression with another string
6 esid: prod-AdditiveExpression
7 info: |
8 AdditiveExpression: AdditiveExpression + MultiplicativeExpression
9
10 ...
11 7. If Type(lprim) is String or Type(rprim) is String, then
12 a. Let lstr be ? ToString(lprim).
13 b. Let rstr be ? ToString(rprim).
14 c. Return the String that is the result of concatenating lstr and rstr.
15 ...
16
17 ToString Applied to the BigInt Type
18
19 1. If i is less than zero, return the String concatenation of the String "-" and ToString(-i).
20 2. Return the String consisting of the code units of the digits of the decimal representation of i.
21 features: [BigInt]
22 ---*/
23
24 function ToString(x) { return x + ""; }
25
26 assert.sameValue(-1n + "", "-1");
27 assert.sameValue("" + -1n, "-1");
28 assert.sameValue(0n + "", "0");
29 assert.sameValue("" + 0n, "0");
30 assert.sameValue(1n + "", "1");
31 assert.sameValue("" + 1n, "1");
32 assert.sameValue(123456789000000000000000n + "", "123456789000000000000000");
33 assert.sameValue("" + 123456789000000000000000n, "123456789000000000000000");
34 assert.sameValue(-123456789000000000000000n + "", "-123456789000000000000000");
35 assert.sameValue("" + -123456789000000000000000n, "-123456789000000000000000");