• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
5 *
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
23    File Name:          6-1.js
24    ECMA Section:       Source Text
25    Description:
26
27    ECMAScript source text is represented as a sequence of characters
28    representable using the Unicode version 2.0 character encoding.
29
30    SourceCharacter ::
31    any Unicode character
32
33    However, it is possible to represent every ECMAScript program using
34    only ASCII characters (which are equivalent to the first 128 Unicode
35    characters). Non-ASCII Unicode characters may appear only within comments
36    and string literals. In string literals, any Unicode character may also be
37    expressed as a Unicode escape sequence consisting of six ASCII characters,
38    namely \u plus four hexadecimal digits. Within a comment, such an escape
39    sequence is effectively ignored as part of the comment. Within a string
40    literal, the Unicode escape sequence contributes one character to the string
41    value of the literal.
42
43    Note that ECMAScript differs from the Java programming language in the
44    behavior of Unicode escape sequences. In a Java program, if the Unicode escape
45    sequence \u000A, for example, occurs within a single-line comment, it is
46    interpreted as a line terminator (Unicode character 000A is line feed) and
47    therefore the next character is not part of the comment. Similarly, if the
48    Unicode escape sequence \u000A occurs within a string literal in a Java
49    program, it is likewise interpreted as a line terminator, which is not
50    allowed within a string literal-one must write \n instead of \u000A to
51    cause a line feed to be part of the string value of a string literal. In
52    an ECMAScript program, a Unicode escape sequence occurring within a comment
53    is never interpreted and therefore cannot contribute to termination of the
54    comment. Similarly, a Unicode escape sequence occurring within a string literal
55    in an ECMAScript program always contributes a character to the string value of
56    the literal and is never interpreted as a line terminator or as a quote mark
57    that might terminate the string literal.
58
59    Author:             christine@netscape.com
60    Date:               12 november 1997
61*/
62
63    var SECTION = "6-1";
64    var VERSION = "ECMA_1";
65    startTest();
66    var TITLE   = "Source Text";
67
68    writeHeaderToLog( SECTION + " "+ TITLE);
69
70    var testcases = new Array();
71
72    // encoded quotes should not end a quote
73
74    testcases[tc++]= new TestCase(  SECTION,
75                                    "var s = 'PAS\\u0022SED'; s",
76                                    "PAS\"SED",
77                                    eval("var s = 'PAS\\u0022SED'; s") );
78
79    testcases[tc++]= new TestCase(  SECTION,
80                                    'var s = "PAS\\u0022SED"; s',
81                                    "PAS\"SED",
82                                    eval('var s = "PAS\\u0022SED"; s') );
83
84
85    testcases[tc++]= new TestCase(  SECTION,
86                                    "var s = 'PAS\\u0027SED'; s",
87                                    "PAS\'SED",
88                                    eval("var s = 'PAS\\u0027SED'; s") );
89
90
91    testcases[tc++]= new TestCase(  SECTION,
92                                    'var s = "PAS\\u0027SED"; s',
93                                    "PAS\'SED",
94                                    eval('var s = "PAS\\u0027SED"; s') );
95
96    testcases[tc] = new TestCase( SECTION,
97                                    'var s="PAS\\u0027SED"; s',
98                                    "PAS\'SED",
99                                    "" )
100    var s = "PAS\u0027SED";
101
102    testcases[tc].actual =  s;
103
104    tc++;
105
106    testcases[tc]= new TestCase(  SECTION,
107                                    'var s = "PAS\\u0027SED"; s',
108                                    "PAS\"SED",
109                                    "" );
110    var s = "PAS\u0022SED";
111
112    testcases[tc].actual = s;
113
114
115    test();
116
117function test() {
118    for ( tc=0; tc < testcases.length; tc++ ) {
119        testcases[tc].passed = writeTestCaseResult(
120                            testcases[tc].expect,
121                            testcases[tc].actual,
122                            testcases[tc].description +" = "+
123                            testcases[tc].actual );
124
125        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
126    }
127    stopTest();
128    return ( testcases );
129}
130