|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 //----------------------------------------------------------------------------- |
|
7 |
|
8 /* |
|
9 This test case uses String.quote(), because that method uses the JS printf() |
|
10 functions internally. The printf() functions print to a char* buffer, causing |
|
11 conversion to and from UTF-8 if UTF-8 is enabled. If not, UTF-8 sequences are |
|
12 converted to ASCII \uXXXX sequences. Thus, both return values are acceptable. |
|
13 */ |
|
14 |
|
15 var BUGNUMBER = 315974; |
|
16 var summary = 'Test internal printf() for wide characters'; |
|
17 |
|
18 printBugNumber(BUGNUMBER); |
|
19 printStatus (summary); |
|
20 |
|
21 enterFunc (String (BUGNUMBER)); |
|
22 |
|
23 var goodSurrogatePair = '\uD841\uDC42'; |
|
24 var badSurrogatePair = '\uD841badbad'; |
|
25 |
|
26 var goodSurrogatePairQuotedUtf8 = '"\uD841\uDC42"'; |
|
27 var badSurrogatePairQuotedUtf8 = 'no error thrown!'; |
|
28 var goodSurrogatePairQuotedNoUtf8 = '"\\uD841\\uDC42"'; |
|
29 var badSurrogatePairQuotedNoUtf8 = '"\\uD841badbad"'; |
|
30 |
|
31 var status = summary + ': String.quote() should pay respect to surrogate pairs'; |
|
32 var actual = goodSurrogatePair.quote(); |
|
33 /* Result in case UTF-8 is enabled. */ |
|
34 var expect = goodSurrogatePairQuotedUtf8; |
|
35 /* Result in case UTF-8 is disabled. */ |
|
36 if (actual != expect && actual == goodSurrogatePairQuotedNoUtf8) |
|
37 expect = actual; |
|
38 reportCompare(expect, actual, status); |
|
39 |
|
40 /* |
|
41 * A malformed surrogate pair throws an out-of-memory error, |
|
42 * but only if UTF-8 is enabled. |
|
43 */ |
|
44 status = summary + ': String.quote() should throw error on bad surrogate pair'; |
|
45 /* Out of memory is not catchable. */ |
|
46 actual = badSurrogatePair.quote(); |
|
47 /* Come here only if UTF-8 is disabled. */ |
|
48 reportCompare(badSurrogatePairQuotedNoUtf8, actual, status); |
|
49 |
|
50 exitFunc (String (BUGNUMBER)); |