| 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 | gTestfile = '6-1.js'; |
| 7 | |
| 8 | /** |
| 9 | File Name: 6-1.js |
| 10 | ECMA Section: Source Text |
| 11 | Description: |
| 12 | |
| 13 | ECMAScript source text is represented as a sequence of characters |
| 14 | representable using the Unicode version 2.0 character encoding. |
| 15 | |
| 16 | SourceCharacter :: |
| 17 | any Unicode character |
| 18 | |
| 19 | However, it is possible to represent every ECMAScript program using |
| 20 | only ASCII characters (which are equivalent to the first 128 Unicode |
| 21 | characters). Non-ASCII Unicode characters may appear only within comments |
| 22 | and string literals. In string literals, any Unicode character may also be |
| 23 | expressed as a Unicode escape sequence consisting of six ASCII characters, |
| 24 | namely \u plus four hexadecimal digits. Within a comment, such an escape |
| 25 | sequence is effectively ignored as part of the comment. Within a string |
| 26 | literal, the Unicode escape sequence contributes one character to the string |
| 27 | value of the literal. |
| 28 | |
| 29 | Note that ECMAScript differs from the Java programming language in the |
| 30 | behavior of Unicode escape sequences. In a Java program, if the Unicode escape |
| 31 | sequence \u000A, for example, occurs within a single-line comment, it is |
| 32 | interpreted as a line terminator (Unicode character 000A is line feed) and |
| 33 | therefore the next character is not part of the comment. Similarly, if the |
| 34 | Unicode escape sequence \u000A occurs within a string literal in a Java |
| 35 | program, it is likewise interpreted as a line terminator, which is not |
| 36 | allowed within a string literal-one must write \n instead of \u000A to |
| 37 | cause a line feed to be part of the string value of a string literal. In |
| 38 | an ECMAScript program, a Unicode escape sequence occurring within a comment |
| 39 | is never interpreted and therefore cannot contribute to termination of the |
| 40 | comment. Similarly, a Unicode escape sequence occurring within a string literal |
| 41 | in an ECMAScript program always contributes a character to the string value of |
| 42 | the literal and is never interpreted as a line terminator or as a quote mark |
| 43 | that might terminate the string literal. |
| 44 | |
| 45 | Author: [email protected] |
| 46 | Date: 12 november 1997 |
| 47 | */ |
| 48 | |
| 49 | var SECTION = "6-1"; |
| 50 | var VERSION = "ECMA_1"; |
| 51 | startTest(); |
| 52 | var TITLE = "Source Text"; |
| 53 | |
| 54 | writeHeaderToLog( SECTION + " "+ TITLE); |
| 55 | |
| 56 | var testcase = new TestCase( SECTION, |
| 57 | "// the following character should not be interpreted as a line terminator in a comment: \u000A", |
| 58 | 'PASSED', |
| 59 | "PASSED" ); |
| 60 | |
| 61 | // \u000A testcase.actual = "FAILED!"; |
| 62 | |
| 63 | testcase = |
| 64 | new TestCase( SECTION, |
| 65 | "// the following character should not be interpreted as a line terminator in a comment: \\n 'FAILED'", |
| 66 | 'PASSED', |
| 67 | 'PASSED' ); |
| 68 | |
| 69 | // the following character should noy be interpreted as a line terminator: \\n testcase.actual = "FAILED" |
| 70 | |
| 71 | testcase = |
| 72 | new TestCase( SECTION, |
| 73 | "// the following character should not be interpreted as a line terminator in a comment: \\u000A 'FAILED'", |
| 74 | 'PASSED', |
| 75 | 'PASSED' ); |
| 76 | |
| 77 | // the following character should not be interpreted as a line terminator: \u000A testcase.actual = "FAILED" |
| 78 | |
| 79 | testcase = |
| 80 | new TestCase( SECTION, |
| 81 | "// the following character should not be interpreted as a line terminator in a comment: \n 'PASSED'", |
| 82 | 'PASSED', |
| 83 | 'PASSED' ); |
| 84 | // the following character should not be interpreted as a line terminator: \n testcase.actual = 'FAILED' |
| 85 | |
| 86 | testcase = |
| 87 | new TestCase( SECTION, |
| 88 | "// the following character should not be interpreted as a line terminator in a comment: u000D", |
| 89 | 'PASSED', |
| 90 | 'PASSED' ); |
| 91 | |
| 92 | // the following character should not be interpreted as a line terminator: \u000D testcase.actual = "FAILED" |
| 93 | |
| 94 | test(); |
| 95 |