jerryscript/tests/jerry/es.next/template_string.js
Dániel Bátyai fde0d556ac
Re-target for ES.Next (#3901)
A list of changes:
- 'es2015-subset' profile is deprecated, and an 'es.next' profile is added.
- The default profile is changed to 'es.next'
- Renamed the JERRY_ES2015 guard to JERRY_ESNEXT
- Renamed JERRY_ES2015_BUILTIN_* guards to JERRY_BUILTIN_*
- Moved es2015 specific tests to a new 'es.next' subdirectory
- Updated docs, targets, and test runners to reflect these changes

Resolves #3737.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2020-06-12 17:55:00 +02:00

105 lines
2.4 KiB
JavaScript

/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function must_throw (str)
{
try
{
eval ("switch (1) { default: " + str + "}");
assert (false);
}
catch (e)
{
}
try
{
eval (str);
assert (false);
}
catch (e)
{
}
}
var a = 'A';
var b = 'B';
switch (1)
{
default:
``;
`abc`;
`ab${a+b}${ `x` }c`;
assert (`` === '');
assert (`abc` === 'abc');
assert (`ab\
c` === 'ab c');
assert (`ab
c` === 'ab\n c');
assert (`prefix${a}` === 'prefixA');
assert (`${a}postfix` === 'Apostfix');
assert (`prefix${a}postfix` === 'prefixApostfix');
assert (`${a}${b}` === 'AB');
assert (`${a},${b}` === 'A,B');
assert (`${a}${b}${a}${b}` === 'ABAB');
assert (`${a},${b},${a},${b}` === 'A,B,A,B');
assert (`$${a},${b},${a},${b}$` === '$A,B,A,B$');
assert (`\${}` === '${}');
assert (`$\{}` === '${}');
assert (`x${ `y` + `z` }x` === 'xyzx');
assert (`x${ `y` , `z` }x` === 'xzx');
function f(x) { return x + 1; }
/* Precedence. */
var c = 1;
assert (`x${ f(1) * f(2) }x${ c = 4 }` === 'x6x4');
assert (c === 4);
assert (`m${0 || 93}n${7 && 0}o` === 'm93n0o');
/* Result is always a string. */
assert (`${ function() { return true } () }` === 'true');
assert (`${ function() { return a.length } () }` === '1');
/* Result is a single string with its properties. */
assert(`${a}${b}${a}${b}`.length === 4);
}
must_throw ("`");
must_throw ("`${");
must_throw ("`${7");
must_throw ("`${}`");
must_throw ("`${1}");
must_throw ("`${1}.${");
must_throw ("`${1}.${2}");
// line break normalization
var cr = eval("`a" + String.fromCharCode(13) + "b`");
var lf = eval("`a" + String.fromCharCode(10) + "b`");
var crlf = eval("`a" + String.fromCharCode(13,10) + "b`");
assert(cr.length === 3);
assert(lf.length === 3);
assert(crlf.length === 3);
assert(cr[1] === lf[1]);
assert(lf[1] === crlf[1]);
assert(crlf[1] === '\n');