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: File Name: 6-1.js michael@0: ECMA Section: Source Text michael@0: Description: michael@0: michael@0: ECMAScript source text is represented as a sequence of characters michael@0: representable using the Unicode version 2.0 character encoding. michael@0: michael@0: SourceCharacter :: michael@0: any Unicode character michael@0: michael@0: However, it is possible to represent every ECMAScript program using michael@0: only ASCII characters (which are equivalent to the first 128 Unicode michael@0: characters). Non-ASCII Unicode characters may appear only within comments michael@0: and string literals. In string literals, any Unicode character may also be michael@0: expressed as a Unicode escape sequence consisting of six ASCII characters, michael@0: namely \u plus four hexadecimal digits. Within a comment, such an escape michael@0: sequence is effectively ignored as part of the comment. Within a string michael@0: literal, the Unicode escape sequence contributes one character to the string michael@0: value of the literal. michael@0: michael@0: Note that ECMAScript differs from the Java programming language in the michael@0: behavior of Unicode escape sequences. In a Java program, if the Unicode escape michael@0: sequence \u000A, for example, occurs within a single-line comment, it is michael@0: interpreted as a line terminator (Unicode character 000A is line feed) and michael@0: therefore the next character is not part of the comment. Similarly, if the michael@0: Unicode escape sequence \u000A occurs within a string literal in a Java michael@0: program, it is likewise interpreted as a line terminator, which is not michael@0: allowed within a string literal-one must write \n instead of \u000A to michael@0: cause a line feed to be part of the string value of a string literal. In michael@0: an ECMAScript program, a Unicode escape sequence occurring within a comment michael@0: is never interpreted and therefore cannot contribute to termination of the michael@0: comment. Similarly, a Unicode escape sequence occurring within a string literal michael@0: in an ECMAScript program always contributes a character to the string value of michael@0: the literal and is never interpreted as a line terminator or as a quote mark michael@0: that might terminate the string literal. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: michael@0: var SECTION = "6-1"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "Source Text"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: // encoded quotes should not end a quote michael@0: michael@0: new TestCase( SECTION, michael@0: "var s = 'PAS\\u0022SED'; s", michael@0: "PAS\"SED", michael@0: eval("var s = 'PAS\\u0022SED'; s") ); michael@0: michael@0: new TestCase( SECTION, michael@0: 'var s = "PAS\\u0022SED"; s', michael@0: "PAS\"SED", michael@0: eval('var s = "PAS\\u0022SED"; s') ); michael@0: michael@0: michael@0: new TestCase( SECTION, michael@0: "var s = 'PAS\\u0027SED'; s", michael@0: "PAS\'SED", michael@0: eval("var s = 'PAS\\u0027SED'; s") ); michael@0: michael@0: michael@0: new TestCase( SECTION, michael@0: 'var s = "PAS\\u0027SED"; s', michael@0: "PAS\'SED", michael@0: eval('var s = "PAS\\u0027SED"; s') ); michael@0: michael@0: var testcase = new TestCase( SECTION, michael@0: 'var s="PAS\\u0027SED"; s', michael@0: "PAS\'SED", michael@0: "" ); michael@0: var s = "PAS\u0027SED"; michael@0: michael@0: testcase.actual = s; michael@0: michael@0: testcase = new TestCase( SECTION, michael@0: 'var s = "PAS\\u0022SED"; s', michael@0: "PAS\"SED", michael@0: "" ); michael@0: var s = "PAS\u0022SED"; michael@0: michael@0: testcase.actual = s; michael@0: michael@0: michael@0: test(); michael@0: