michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: /* michael@0: This test case uses String.quote(), because that method uses the JS printf() michael@0: functions internally. The printf() functions print to a char* buffer, causing michael@0: conversion to and from UTF-8 if UTF-8 is enabled. If not, UTF-8 sequences are michael@0: converted to ASCII \uXXXX sequences. Thus, both return values are acceptable. michael@0: */ michael@0: michael@0: var BUGNUMBER = 315974; michael@0: var summary = 'Test internal printf() for wide characters'; michael@0: michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: enterFunc (String (BUGNUMBER)); michael@0: michael@0: var goodSurrogatePair = '\uD841\uDC42'; michael@0: var badSurrogatePair = '\uD841badbad'; michael@0: michael@0: var goodSurrogatePairQuotedUtf8 = '"\uD841\uDC42"'; michael@0: var badSurrogatePairQuotedUtf8 = 'no error thrown!'; michael@0: var goodSurrogatePairQuotedNoUtf8 = '"\\uD841\\uDC42"'; michael@0: var badSurrogatePairQuotedNoUtf8 = '"\\uD841badbad"'; michael@0: michael@0: var status = summary + ': String.quote() should pay respect to surrogate pairs'; michael@0: var actual = goodSurrogatePair.quote(); michael@0: /* Result in case UTF-8 is enabled. */ michael@0: var expect = goodSurrogatePairQuotedUtf8; michael@0: /* Result in case UTF-8 is disabled. */ michael@0: if (actual != expect && actual == goodSurrogatePairQuotedNoUtf8) michael@0: expect = actual; michael@0: reportCompare(expect, actual, status); michael@0: michael@0: /* michael@0: * A malformed surrogate pair throws an out-of-memory error, michael@0: * but only if UTF-8 is enabled. michael@0: */ michael@0: status = summary + ': String.quote() should throw error on bad surrogate pair'; michael@0: /* Out of memory is not catchable. */ michael@0: actual = badSurrogatePair.quote(); michael@0: /* Come here only if UTF-8 is disabled. */ michael@0: reportCompare(badSurrogatePairQuotedNoUtf8, actual, status); michael@0: michael@0: exitFunc (String (BUGNUMBER));