js/src/tests/ecma/SourceText/6-2.js

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

mercurial