forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringTagFunctions.js
More file actions
80 lines (63 loc) · 3.92 KB
/
StringTagFunctions.js
File metadata and controls
80 lines (63 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
// String tag function tests -- verifies behavior of functions like String.prototype.link
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
}
var tests = [
{
name: "Quote characters are escaped correctly",
body: function() {
var _this = 'value';
var property = 'any string with a quote " longer than 32 characters';
assert.areEqual('<a href="any string with a quote " longer than 32 characters">value</a>', _this.link(property), "Verify String.prototype.link escapes quote characters correctly");
_this = '""""""""""""""""';
property = '""""""""""""""""';
assert.areEqual('<a name="""""""""""""""""">""""""""""""""""</a>', _this.anchor(property), "Multiple quote characters");
_this = 'value';
property = 'long string with " multiple " quote characters " and " the final character is a quote "';
assert.areEqual('<font size="long string with " multiple " quote characters " and " the final character is a quote "">value</font>', _this.fontsize(property), "The final character in the property is a quote");
}
},
{
name: "String without null terminator at length",
body: function() {
var _this = 'value';
var property = "-\"";
assert.areEqual('<a href="-">value</a>', _this.link(property.substring(1,0)), "String.prototype.substring reuses the string buffer but returns a string with a different length");
}
},
{
name: "String with embedded null characters",
body: function() {
var _this = 'value';
var property = " a string with quotes \"\" and an embedded null \0 character";
var result = _this.fontcolor(property);
assert.areEqual("<font color=\" a string with quotes "" and an embedded null \0 character\">value</font>", result, "Embedded null character doesn't truncate the property we copy (string will be truncated in output)");
assert.areEqual(94, result.length, "Length of string is correct even if it's truncated in test output");
result = "\0".fontsize("\0");
assert.areEqual("<font size=\"\0\">\0</font>", result, "Embedded null characters in both property and this field");
assert.areEqual(23, result.length, "Length of string is correct even though it may show up truncated in the test output");
}
},
{
name: "Zero-length strings",
body: function() {
var _this = 'value';
var property = '';
assert.areEqual("<font size=\"\">value</font>", _this.fontsize(property), "Zero-length property string doesn't cause null dereference");
_this = '';
assert.areEqual("<a href=\"\"></a>", _this.link(property), "Zero-length property and this strings");
}
},
{
name: "Function with no property",
body: function() {
var _this = 'value';
assert.areEqual("<blink>value</blink>", _this.blink(), "String tag functions with no property work correctly");
}
}
];
testRunner.runTests(tests);