-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjquery_replace_test.html
More file actions
91 lines (70 loc) · 3.25 KB
/
jquery_replace_test.html
File metadata and controls
91 lines (70 loc) · 3.25 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
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>JavaScript unit test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="lib/jsunittest.js" type="text/javascript"></script>
<script src="lib/jquery.js" type="text/javascript"></script>
<!-- TODO: REPLACE "example_library_to_test" throughout file with name of file to test -->
<script src="jquery.replace.js" type="text/javascript"></script>
<link rel="stylesheet" href="lib/unittest.css" type="text/css" />
</head>
<body>
<div id="content">
<div id="header">
<h1>JavaScript unit test file</h1>
<p>
This file tests <strong>jquery.replace.js</strong>.
</p>
</div>
<!-- Log output (one per Runner, via {testLog: "testlog"} option)-->
<div id="testlog"></div>
<!-- Put sample/test html here -->
<div id="sample">
<div id="test" style="display: none;">Tentative tent is content with tending to that.</div>
<ul style="display: none;">
<li>testing</li>
<li>testing</li>
</ul>
<p id="test_p">My anchor should be outside my <a href="#anchor">anchor</a>.</p>
<p id="test_black_list">Black Listing is fun to do for <a href="#">fun fun fun</a></p>
</div>
</div>
<script type="text/javascript">
// <![CDATA[
new Test.Unit.Runner({
setup: function(){
$('#test').html('Tentative event is content with tending to that.');
},
testReplaceStringWithString: function(){ with(this) {
assertEqual('Tentative event is content with tending to that.', $('#test').replace(' tent', 'event').html());
}},
testReplaceRegexpWithString: function(){ with(this) {
assertEqual('Tentative event is content with tending to that.', $('#test').replace(/\btent\b/, 'event').html());
}},
testReplaceRegexpWithDollar: function(){ with(this) {
assertEqual('Tentative event <i>is</i> content with tending to that.', $('#test').replace(/(is)/, "<i>$1</i>").html())
}},
testReplaceRegexpWithFunction: function(){ with(this) {
assertEqual('Tentative event is CONTENT with tending to that.', $('#test').replace(/content/, function(match){ return match.toUpperCase() }).html())
}},
testReplaceRegexpGloballyWithString: function(){ with(this){ // leet speak wannabes beware
assertEqual('10tative event is con10t with 10ding to that.', $('#test').replace(/ten/ig, '10').html())
}},
testReplaceMultipleObjects: function(){ with(this){
$('li').replace('testing', 'validating');
assertEqual('validating', $('li:first').html());
assertEqual('validating', $('li:last').html());
}},
testReplaceDoesNotBreakAnchors: function(){ with(this){
assert('My <a href="#">replacement</a> should be outside my <a href="#anchor">anchor</a>.', $('#test_p').replace(/anchor/g, '<a href=\"#\">replacement</a>').html());
}},
testReplaceAnchorsWithBlackList: function(){ with(this){
assert('Black Listing is great to do for <a href="#">great great great</a>', $('#test_black_list').replace(/fun/g, 'great').html());
}}
});
// ]]>
</script>
</body>
</html>