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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/SourceText/6-2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          6-1.js
    1.12 +   ECMA Section:       Source Text
    1.13 +   Description:
    1.14 +
    1.15 +   ECMAScript source text is represented as a sequence of characters
    1.16 +   representable using the Unicode version 2.0 character encoding.
    1.17 +
    1.18 +   SourceCharacter ::
    1.19 +   any Unicode character
    1.20 +
    1.21 +   However, it is possible to represent every ECMAScript program using
    1.22 +   only ASCII characters (which are equivalent to the first 128 Unicode
    1.23 +   characters). Non-ASCII Unicode characters may appear only within comments
    1.24 +   and string literals. In string literals, any Unicode character may also be
    1.25 +   expressed as a Unicode escape sequence consisting of six ASCII characters,
    1.26 +   namely \u plus four hexadecimal digits. Within a comment, such an escape
    1.27 +   sequence is effectively ignored as part of the comment. Within a string
    1.28 +   literal, the Unicode escape sequence contributes one character to the string
    1.29 +   value of the literal.
    1.30 +
    1.31 +   Note that ECMAScript differs from the Java programming language in the
    1.32 +   behavior of Unicode escape sequences. In a Java program, if the Unicode escape
    1.33 +   sequence \u000A, for example, occurs within a single-line comment, it is
    1.34 +   interpreted as a line terminator (Unicode character 000A is line feed) and
    1.35 +   therefore the next character is not part of the comment. Similarly, if the
    1.36 +   Unicode escape sequence \u000A occurs within a string literal in a Java
    1.37 +   program, it is likewise interpreted as a line terminator, which is not
    1.38 +   allowed within a string literal-one must write \n instead of \u000A to
    1.39 +   cause a line feed to be part of the string value of a string literal. In
    1.40 +   an ECMAScript program, a Unicode escape sequence occurring within a comment
    1.41 +   is never interpreted and therefore cannot contribute to termination of the
    1.42 +   comment. Similarly, a Unicode escape sequence occurring within a string literal
    1.43 +   in an ECMAScript program always contributes a character to the string value of
    1.44 +   the literal and is never interpreted as a line terminator or as a quote mark
    1.45 +   that might terminate the string literal.
    1.46 +
    1.47 +   Author:             christine@netscape.com
    1.48 +   Date:               12 november 1997
    1.49 +*/
    1.50 +
    1.51 +var SECTION = "6-1";
    1.52 +var VERSION = "ECMA_1";
    1.53 +startTest();
    1.54 +var TITLE   = "Source Text";
    1.55 +
    1.56 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.57 +
    1.58 +// encoded quotes should not end a quote
    1.59 +
    1.60 +new TestCase(  SECTION,
    1.61 +	       "var s = 'PAS\\u0022SED'; s",
    1.62 +	       "PAS\"SED",
    1.63 +	       eval("var s = 'PAS\\u0022SED'; s") );
    1.64 +
    1.65 +new TestCase(  SECTION,
    1.66 +	       'var s = "PAS\\u0022SED"; s',
    1.67 +	       "PAS\"SED",
    1.68 +	       eval('var s = "PAS\\u0022SED"; s') );
    1.69 +
    1.70 +
    1.71 +new TestCase(  SECTION,
    1.72 +	       "var s = 'PAS\\u0027SED'; s",
    1.73 +	       "PAS\'SED",
    1.74 +	       eval("var s = 'PAS\\u0027SED'; s") );
    1.75 +
    1.76 +
    1.77 +new TestCase(  SECTION,
    1.78 +	       'var s = "PAS\\u0027SED"; s',
    1.79 +	       "PAS\'SED",
    1.80 +	       eval('var s = "PAS\\u0027SED"; s') );
    1.81 +
    1.82 +var testcase =  new TestCase( SECTION,
    1.83 +			      'var s="PAS\\u0027SED"; s',
    1.84 +			      "PAS\'SED",
    1.85 +			      "" );
    1.86 +var s = "PAS\u0027SED";
    1.87 +
    1.88 +testcase.actual =  s;
    1.89 +
    1.90 +testcase = new TestCase(  SECTION,
    1.91 +			  'var s = "PAS\\u0022SED"; s',
    1.92 +			  "PAS\"SED",
    1.93 +			  "" );
    1.94 +var s = "PAS\u0022SED";
    1.95 +
    1.96 +testcase.actual = s;
    1.97 +
    1.98 +
    1.99 +test();
   1.100 +

mercurial