-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.html
96 lines (89 loc) · 2.54 KB
/
tests.html
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
92
93
94
95
96
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="jquery-1.3.2.min.js"></script>
<script src="json2.js"></script>
<script src="jquery.parsley.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="qunit.js"></script>
<script>
$(document).ready(function(){
test("extracting regex", function() {
same($(".date").extract(/\d+/).simple(), ["12", "01"]);
});
test("extracting attribute", function() {
same($(".message").extract("@id").simple(), ["b", "a"]);
});
test("extracting function", function() {
same($(".date").extract(function(node){
var text = $(node).text();
var arr = text.split("/");
var max = 0;
$.each(arr,function(){
var i = parseInt(this);
if(i > max) max = i;
});
return max;
}).simple(), [25, 10]);
});
test("extract", function(){
var parselet = {
page: location.href.split("/").pop,
messages: [{
"message_id": $(".message").extract("@id"),
"date": $(".date"),
"text": $(".message")
}]
};
pQuery.extract(parselet);
same(parselet.messages[0].message_id.simple(), ["b", "a"]);
});
test("grouping", function() {
var parselet = {
page: location.href.split("/").pop(),
messages: [{
"message_id": $(".message").extract("@id"),
"date": $(".date"),
"text": $(".message")
}]
};
var output = pQuery.extractAndGroup(parselet);
var expected = {
page: "tests.html",
messages: [{
message_id: "b",
date: "12/25/09",
text: "Merry christmas!"
},
{
message_id: "b",
date: "01/01/10",
text: "Happy new year!"
}]
};
same(output.messages[0].text, expected.messages[0].text);
});
});
</script>
</head>
<body>
<h1 id="qunit-header">QUnit example</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="test_dom">
<h1>Test dom</h1>
<ul>
<li>
<span class="date">12/25/09</span>
<span class="message" id="b">Merry christmas!</span>
</li>
<li>
<span class="date">01/01/10</span>
<span class="message" id="a">Happy new year!</span>
</li>
</ul>
</div>
</body>
</html>