Debian Codegraph @

rhino/testsrc/tests/js1_5/Regress/regress-315974.js

raw symbols SCIP
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 var gTestfile = 'regress-315974.js';
7 //-----------------------------------------------------------------------------
8
9 /*
10 This test case uses String.quote(), because that method uses the JS printf()
11 functions internally. The printf() functions print to a char* buffer, causing
12 conversion to and from UTF-8 if UTF-8 is enabled. If not, UTF-8 sequences are
13 converted to ASCII \uXXXX sequences. Thus, both return values are acceptable.
14 */
15
16 var BUGNUMBER = 315974;
17 var summary = 'Test internal printf() for wide characters';
18
19 printBugNumber(BUGNUMBER);
20 printStatus (summary);
21
22 enterFunc (String (BUGNUMBER));
23
24 var goodSurrogatePair = '\uD841\uDC42';
25 var badSurrogatePair = '\uD841badbad';
26
27 var goodSurrogatePairQuotedUtf8 = '"\uD841\uDC42"';
28 var badSurrogatePairQuotedUtf8 = 'no error thrown!';
29 var goodSurrogatePairQuotedNoUtf8 = '"\\uD841\\uDC42"';
30 var badSurrogatePairQuotedNoUtf8 = '"\\uD841badbad"';
31
32 var status = summary + ': String.quote() should pay respect to surrogate pairs';
33 var actual = goodSurrogatePair.quote();
34 /* Result in case UTF-8 is enabled. */
35 var expect = goodSurrogatePairQuotedUtf8;
36 /* Result in case UTF-8 is disabled. */
37 if (actual != expect && actual == goodSurrogatePairQuotedNoUtf8)
38 expect = actual;
39 reportCompare(expect, actual, status);
40
41 /*
42 * A malformed surrogate pair throws an out-of-memory error,
43 * but only if UTF-8 is enabled.
44 */
45 status = summary + ': String.quote() should throw error on bad surrogate pair';
46 /* Out of memory is not catchable. */
47 actual = badSurrogatePair.quote();
48 /* Come here only if UTF-8 is disabled. */
49 reportCompare(badSurrogatePairQuotedNoUtf8, actual, status);
50
51 exitFunc (String (BUGNUMBER));