Debian Codegraph @

rhino/testsrc/tests/ecma/SourceText/6-2.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 gTestfile = '6-2.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 // encoded quotes should not end a quote
57
58 new TestCase( SECTION,
59 "var s = 'PAS\\u0022SED'; s",
60 "PAS\"SED",
61 eval("var s = 'PAS\\u0022SED'; s") );
62
63 new TestCase( SECTION,
64 'var s = "PAS\\u0022SED"; s',
65 "PAS\"SED",
66 eval('var s = "PAS\\u0022SED"; s') );
67
68
69 new TestCase( SECTION,
70 "var s = 'PAS\\u0027SED'; s",
71 "PAS\'SED",
72 eval("var s = 'PAS\\u0027SED'; s") );
73
74
75 new TestCase( SECTION,
76 'var s = "PAS\\u0027SED"; s',
77 "PAS\'SED",
78 eval('var s = "PAS\\u0027SED"; s') );
79
80 var testcase = new TestCase( SECTION,
81 'var s="PAS\\u0027SED"; s',
82 "PAS\'SED",
83 "" );
84 var s = "PAS\u0027SED";
85
86 testcase.actual = s;
87
88 testcase = new TestCase( SECTION,
89 'var s = "PAS\\u0022SED"; s',
90 "PAS\"SED",
91 "" );
92 var s = "PAS\u0022SED";
93
94 testcase.actual = s;
95
96
97 test();
98