Permalink
Browse files

Import tests from Google V8 (templates)

These tests are derived from the following files within the Google V8
project:

    test/mjsunit/es6/templates.js

Some of these tests include non-printable characters, causing git to
infer that they are binary files. Introduce a `.gitattributes` file to
configure git to consistently display the source text of all JavaScript
files.
  • Loading branch information...
jugglinmike committed Mar 30, 2015
1 parent 43acf61 commit 1f22932d69f8cdd5ed1602300c4690c5cfc11ef9
Showing with 904 additions and 0 deletions.
  1. +1 −0 .gitattributes
  2. +21 −0 test/built-ins/String/raw/special-characters.js
  3. +9 −0 test/built-ins/String/raw/zero-literal-segments.js
  4. +25 −0 test/language/templates/expressions/evaluation-order.js
  5. +11 −0 test/language/templates/expressions/function-invocation.js
  6. +13 −0 test/language/templates/expressions/legacy-octal-escape-sequence-non-strict.js
  7. +14 −0 test/language/templates/expressions/legacy-octal-escape-sequence-strict.js
  8. +13 −0 test/language/templates/expressions/method-invocation.js
  9. +19 −0 test/language/templates/expressions/object-deference.js
  10. +24 −0 test/language/templates/expressions/object.js
  11. +11 −0 test/language/templates/expressions/primitives.js
  12. +9 −0 test/language/templates/expressions/template-literal.js
  13. +25 −0 test/language/templates/tagged/caching/differing-expressions-eval.js
  14. +29 −0 test/language/templates/tagged/caching/differing-expressions-new-function.js
  15. +24 −0 test/language/templates/tagged/caching/differing-expressions.js
  16. +24 −0 test/language/templates/tagged/caching/differing-raw-strings.js
  17. +24 −0 test/language/templates/tagged/caching/differing-string-count.js
  18. +23 −0 test/language/templates/tagged/caching/identical-source-eval.js
  19. +23 −0 test/language/templates/tagged/caching/identical-source-new-function.js
  20. +26 −0 test/language/templates/tagged/caching/identical-source.js
  21. +38 −0 test/language/templates/tagged/call-expression-argument-list-evaluation.js
  22. +20 −0 test/language/templates/tagged/chained-application.js
  23. +27 −0 test/language/templates/tagged/constructor-invocation.js
  24. +20 −0 test/language/templates/tagged/member-expression-context.js
  25. +47 −0 test/language/templates/tagged/template-object.js
  26. +88 −0 test/language/templates/template-values/character-escape-sequence.js
  27. BIN test/language/templates/template-values/escape-sequence.js
  28. +11 −0 test/language/templates/template-values/invalid/hexidecimal-character-escape-sequence-truncated.js
  29. +11 −0 test/language/templates/template-values/invalid/legacy-octal-escape-sequence.js
  30. +11 −0 test/language/templates/template-values/invalid/unicode-escape-sequence-truncated.js
  31. +19 −0 test/language/templates/template-values/line-continuation.js
  32. +20 −0 test/language/templates/template-values/line-terminator-sequence.js
  33. +13 −0 test/language/templates/template-values/multi-line.js
  34. +27 −0 test/language/templates/template-values/no-substitution.js
  35. BIN test/language/templates/template-values/non-escape-character.js
  36. BIN test/language/templates/template-values/null-character-escape-sequence.js
  37. +29 −0 test/language/templates/template-values/template-character.js
  38. +24 −0 test/language/templates/template-values/template-characters.js
  39. +29 −0 test/language/templates/template-values/template-head.js
  40. +29 −0 test/language/templates/template-values/template-middle.js
  41. +29 −0 test/language/templates/template-values/template-tail.js
  42. +29 −0 test/language/templates/template-values/utf16-escape-sequence.js
  43. +15 −0 test/language/templates/template-values/zwnbsp.js
View
@@ -0,0 +1 @@
*.js diff
@@ -0,0 +1,21 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.4
description: >
When used as a tag function of a tagged template, `String.raw` should
return the "raw" representation of the template.
---*/
assert.sameValue(
String.raw`\u0065\`\r\r\n\n${'test'}check`,
'\\u0065\\`\\r\\r\\n\\ntestcheck',
'Unicode escape sequences'
);
assert.sameValue(
String.raw`\\
\
`,
'\\\n\\\n\\\n',
'Literal characters'
);
@@ -0,0 +1,9 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.4
description: >
If literalSegments ≤ 0, return the empty string.
---*/
assert.sameValue(String.raw``, '');
@@ -0,0 +1,25 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Expressions should be evaluated in left-to-right order.
---*/
var tag = function(templateObject, a, b, c) {
callCount++;
assert.sameValue(a, 0);
assert.sameValue(b, 1);
assert.sameValue(c, 2);
};
var i = 0;
var callCount;
assert.sameValue(`a${ i++ }b${ i++ }c${ i++ }d`, 'a0b1c2d');
i = 0;
callCount = 0;
tag`a${ i++ }b${ i++ }c${ i++ }d`;
assert.sameValue(callCount, 1);
@@ -0,0 +1,11 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Expressions should be evaluated and converted to Stings accordingto the
ToString abstract operation.
---*/
function fn() { return 'result'; }
assert.sameValue(`foo ${fn()} bar`, 'foo result bar');
@@ -0,0 +1,13 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
The expression within the template should be evaluated according to the
semantics of the surrounding context.
The SV of EscapeSequence :: HexEscapeSequence is the SV of the
HexEscapeSequence.
flags: [noStrict]
---*/
assert.sameValue(`${'\07'}`, '');
@@ -0,0 +1,14 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
The expression within the template should be evaluated according to the
semantics of the surrounding context.
The SV of EscapeSequence :: HexEscapeSequence is the SV of the
HexEscapeSequence.
negative: SyntaxError
flags: [onlyStrict]
---*/
`${'\07'}`;
@@ -0,0 +1,13 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Expressions should be evaluated and converted to Stings accordingto the
ToString abstract operation.
---*/
var object = {
fn: function() { return 'result'; }
};
assert.sameValue(`foo ${object.fn()} bar`, 'foo result bar');
@@ -0,0 +1,19 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Expressions should be evaluated and converted to Stings accordingto the
ToString abstract operation.
---*/
var object = {
number: 5,
string: 'stringValue'
};
assert.sameValue(
`foo ${object.number} bar`, 'foo 5 bar', 'number value property'
);
assert.sameValue(
`foo ${object.string} bar`, 'foo stringValue bar', 'string value property'
);
@@ -0,0 +1,24 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Expressions should be evaluated and converted to Stings according to the
ToString abstract operation.
---*/
var plain = {};
var custom = {
toString: function() {
return '"own" toString';
}
};
assert.sameValue(`${plain}`, '[object Object]');
assert.sameValue(`1${plain}`, '1[object Object]');
assert.sameValue(`${plain}2`, '[object Object]2');
assert.sameValue(`1${plain}2`, '1[object Object]2');
assert.sameValue(`${custom}`, '"own" toString');
assert.sameValue(`1${custom}`, '1"own" toString');
assert.sameValue(`${custom}2`, '"own" toString2');
assert.sameValue(`1${custom}2`, '1"own" toString2');
@@ -0,0 +1,11 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Expressions should be evaluated and converted to Stings accordingto the
ToString abstract operation.
---*/
assert.sameValue(`foo ${5} bar`, 'foo 5 bar', 'number value');
assert.sameValue(`foo ${'string'} bar`, 'foo string bar', 'string value');
@@ -0,0 +1,9 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Expressions should be evaluated and converted to Stings accordingto the
ToString abstract operation.
---*/
assert.sameValue(`foo ${`bar ${5} baz`} qux`, 'foo bar 5 baz qux');
@@ -0,0 +1,25 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Previously-created template objects should be retrieved from the internal
template registry when their source is identical but their expressions
evaluate to different values and the tagged template is being evaluated in
an `eval` context.
---*/
function tag(templateObject) {
previousObject = templateObject;
}
var a = 1;
var b = 2;
var firstObject = null;
var previousObject = null;
tag`head${a}tail`;
firstObject = previousObject;
assert(firstObject !== null);
previousObject = null;
eval('tag`head${b}tail`');
assert.sameValue(previousObject, firstObject);
@@ -0,0 +1,29 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Previously-created template objects should be retrieved from the internal
template registry when their source is identical but their expressions
evaluate to different values and the tagged template is being evaluated in
an `eval` context.
---*/
function tag(templateObject) {
previousObject = templateObject;
}
var a = 1;
var b = 2;
var firstObject = null;
var previousObject = null;
tag`head${a}tail`;
firstObject = previousObject;
assert(firstObject !== null);
previousObject = null;
(new Function('tag', 'a', 'b', 'return tag`head${b}tail`;'))(tag, 1, 2);
assert.sameValue(
previousObject,
firstObject,
'The realm\'s template cache is referenced when tagged templates are declared within "new Function" contexts and templated values differ'
);
@@ -0,0 +1,24 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Previously-created template objects should be retrieved from the internal
template registry when their source is identical but their expressions
evaluate to different values.
---*/
function tag(templateObject) {
previousObject = templateObject;
}
var a = 1;
var b = 2;
var firstObject = null;
var previousObject = null;
tag`head${a}tail`;
firstObject = previousObject;
assert(firstObject !== null);
previousObject = null;
tag`head${b}tail`;
assert.sameValue(previousObject, firstObject);
@@ -0,0 +1,24 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
The internal template registry should be queried according to the "raw"
strings of the tagged template.
---*/
var previousObject = null;
var firstObject = null;
function tag(templateObject) {
previousObject = templateObject;
}
tag`\uc548\ub155`;
assert(previousObject !== null);
firstObject = previousObject;
previousObject = null;
tag`안녕`;
assert(previousObject !== null);
assert(firstObject !== previousObject);
@@ -0,0 +1,24 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
The internal template registry should be queried according to the number of
"raw" strings in the tagged template.
---*/
var previousObject = null;
var firstObject = null;
function tag(templateObject) {
previousObject = templateObject;
}
tag`foo${1}bar`;
assert(previousObject !== null);
firstObject = previousObject;
previousObject = null;
tag`foo\${1}bar`;
assert(previousObject !== null);
assert(firstObject !== previousObject);
@@ -0,0 +1,23 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Previously-created template objects should be retrieved from the internal
template registry when their source is identical and the tagged template is
being evaluated in an `eval` context.
---*/
function tag(templateObject) {
previousObject = templateObject;
}
var a = 1;
var firstObject = null;
var previousObject = null;
tag`head${a}tail`;
firstObject = previousObject;
assert(firstObject !== null);
previousObject = null;
eval('tag`head${a}tail`');
assert.sameValue(previousObject, firstObject);
@@ -0,0 +1,23 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Previously-created template objects should be retrieved from the internal
template registry when their source is identical and the tagged template is
being evaluated in a `new Function` context.
---*/
function tag(templateObject) {
previousObject = templateObject;
}
var a = 1;
var firstObject = null;
var previousObject = null;
tag`head${a}tail`;
firstObject = previousObject;
assert(firstObject !== null);
previousObject = null;
(new Function('tag', 'a', 'b', 'return tag`head${b}tail`;'))(tag, 1, 2);
assert.sameValue(previousObject, firstObject);
@@ -0,0 +1,26 @@
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.8
description: >
Previously-created template objects should be retrieved from the internal
template registry when their source is identical.
---*/
function tag(templateObject) {
previousObject = templateObject;
}
var a = 1;
var firstObject = null;
var previousObject = null;
tag`head${a}tail`;
firstObject = previousObject;
assert(firstObject !== null);
previousObject = null;
tag`head${a}tail`;
assert.sameValue(
previousObject,
firstObject,
'The realm\'s template cache is used when tagged templates are executed in the source code directly'
);
Oops, something went wrong.

0 comments on commit 1f22932

Please sign in to comment.