1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci * 3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci * You may obtain a copy of the License at 6425bb815Sopenharmony_ci * 7425bb815Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci * 9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci * limitations under the License. 14425bb815Sopenharmony_ci */ 15425bb815Sopenharmony_ci 16425bb815Sopenharmony_cifunction must_throw (str) 17425bb815Sopenharmony_ci{ 18425bb815Sopenharmony_ci try 19425bb815Sopenharmony_ci { 20425bb815Sopenharmony_ci eval ("switch (1) { default: " + str + "}"); 21425bb815Sopenharmony_ci assert (false); 22425bb815Sopenharmony_ci } 23425bb815Sopenharmony_ci catch (e) 24425bb815Sopenharmony_ci { 25425bb815Sopenharmony_ci } 26425bb815Sopenharmony_ci 27425bb815Sopenharmony_ci try 28425bb815Sopenharmony_ci { 29425bb815Sopenharmony_ci eval (str); 30425bb815Sopenharmony_ci assert (false); 31425bb815Sopenharmony_ci } 32425bb815Sopenharmony_ci catch (e) 33425bb815Sopenharmony_ci { 34425bb815Sopenharmony_ci } 35425bb815Sopenharmony_ci} 36425bb815Sopenharmony_ci 37425bb815Sopenharmony_civar a = 'A'; 38425bb815Sopenharmony_civar b = 'B'; 39425bb815Sopenharmony_ci 40425bb815Sopenharmony_ciswitch (1) 41425bb815Sopenharmony_ci{ 42425bb815Sopenharmony_cidefault: 43425bb815Sopenharmony_ci 44425bb815Sopenharmony_ci ``; 45425bb815Sopenharmony_ci `abc`; 46425bb815Sopenharmony_ci `ab${a+b}${ `x` }c`; 47425bb815Sopenharmony_ci 48425bb815Sopenharmony_ci assert (`` === ''); 49425bb815Sopenharmony_ci assert (`abc` === 'abc'); 50425bb815Sopenharmony_ci assert (`ab\ 51425bb815Sopenharmony_ci c` === 'ab c'); 52425bb815Sopenharmony_ci assert (`ab 53425bb815Sopenharmony_ci c` === 'ab\n c'); 54425bb815Sopenharmony_ci 55425bb815Sopenharmony_ci assert (`prefix${a}` === 'prefixA'); 56425bb815Sopenharmony_ci assert (`${a}postfix` === 'Apostfix'); 57425bb815Sopenharmony_ci assert (`prefix${a}postfix` === 'prefixApostfix'); 58425bb815Sopenharmony_ci 59425bb815Sopenharmony_ci assert (`${a}${b}` === 'AB'); 60425bb815Sopenharmony_ci assert (`${a},${b}` === 'A,B'); 61425bb815Sopenharmony_ci assert (`${a}${b}${a}${b}` === 'ABAB'); 62425bb815Sopenharmony_ci assert (`${a},${b},${a},${b}` === 'A,B,A,B'); 63425bb815Sopenharmony_ci assert (`$${a},${b},${a},${b}$` === '$A,B,A,B$'); 64425bb815Sopenharmony_ci 65425bb815Sopenharmony_ci assert (`\${}` === '${}'); 66425bb815Sopenharmony_ci assert (`$\{}` === '${}'); 67425bb815Sopenharmony_ci assert (`x${ `y` + `z` }x` === 'xyzx'); 68425bb815Sopenharmony_ci assert (`x${ `y` , `z` }x` === 'xzx'); 69425bb815Sopenharmony_ci 70425bb815Sopenharmony_ci function f(x) { return x + 1; } 71425bb815Sopenharmony_ci 72425bb815Sopenharmony_ci /* Precedence. */ 73425bb815Sopenharmony_ci var c = 1; 74425bb815Sopenharmony_ci assert (`x${ f(1) * f(2) }x${ c = 4 }` === 'x6x4'); 75425bb815Sopenharmony_ci assert (c === 4); 76425bb815Sopenharmony_ci assert (`m${0 || 93}n${7 && 0}o` === 'm93n0o'); 77425bb815Sopenharmony_ci 78425bb815Sopenharmony_ci /* Result is always a string. */ 79425bb815Sopenharmony_ci assert (`${ function() { return true } () }` === 'true'); 80425bb815Sopenharmony_ci assert (`${ function() { return a.length } () }` === '1'); 81425bb815Sopenharmony_ci 82425bb815Sopenharmony_ci /* Result is a single string with its properties. */ 83425bb815Sopenharmony_ci assert(`${a}${b}${a}${b}`.length === 4); 84425bb815Sopenharmony_ci} 85425bb815Sopenharmony_ci 86425bb815Sopenharmony_cimust_throw ("`"); 87425bb815Sopenharmony_cimust_throw ("`${"); 88425bb815Sopenharmony_cimust_throw ("`${7"); 89425bb815Sopenharmony_cimust_throw ("`${}`"); 90425bb815Sopenharmony_cimust_throw ("`${1}"); 91425bb815Sopenharmony_cimust_throw ("`${1}.${"); 92425bb815Sopenharmony_cimust_throw ("`${1}.${2}"); 93425bb815Sopenharmony_ci 94425bb815Sopenharmony_ci// line break normalization 95425bb815Sopenharmony_civar cr = eval("`a" + String.fromCharCode(13) + "b`"); 96425bb815Sopenharmony_civar lf = eval("`a" + String.fromCharCode(10) + "b`"); 97425bb815Sopenharmony_civar crlf = eval("`a" + String.fromCharCode(13,10) + "b`"); 98425bb815Sopenharmony_ci 99425bb815Sopenharmony_ciassert(cr.length === 3); 100425bb815Sopenharmony_ciassert(lf.length === 3); 101425bb815Sopenharmony_ciassert(crlf.length === 3); 102425bb815Sopenharmony_ciassert(cr[1] === lf[1]); 103425bb815Sopenharmony_ciassert(lf[1] === crlf[1]); 104425bb815Sopenharmony_ciassert(crlf[1] === '\n'); 105