-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathunittest.html
123 lines (100 loc) · 6.52 KB
/
unittest.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<title>Unit tests</title>
</head>
<body style="padding: 30px;">
<p><strong>Shared and maintained by <a href="http://www.nezasa.com">Nezasa</a> | Published under <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache 2.0 License</a> | © <a href="http://www.nezasa.com">Nezasa</a>, 2012</strong></p>
<hr style="border-color: rgb(221,221,221);" />
<h1>ISO8601 Period - Testing</h1>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Test Description</th>
<th>Input</th>
<th>Result</th>
<th>Expected Result</th>
<th>Test Status</th>
</tr>
</thead>
<tbody id="testResults">
</tbody>
</table>
<p>Total tests: <span id="cntTotalTests"></span>
| Successful: <span id="cntTotalOkTests"></span>
| Failed: <span id="cntTotalFailedTests"></span></p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap.js"></script>
<script type="text/javascript" src="iso8601.js"></script>
<script type="text/javascript">
function test(result, title, input, expectedResult) {
// generate html output
var row = document.createElement('tr');
var resultContainer = document.getElementById("testResults");
resultContainer.appendChild(row);
var titleCell = document.createElement('td');
titleCell.innerHTML = title;
row.appendChild(titleCell);
var inputCell = document.createElement('td');
inputCell.innerHTML = input;
row.appendChild(inputCell);
var resultCell = document.createElement('td');
resultCell.innerHTML = result;
row.appendChild(resultCell);
var expectedResultCell = document.createElement('td');
expectedResultCell.innerHTML = expectedResult;
row.appendChild(expectedResultCell);
var testStatusCell = document.createElement('td');
if (result == expectedResult) {
testStatusCell.innerHTML = "ok";
row.setAttribute('class', 'status success')
}
else {
testStatusCell.innerHTML = "failed";
row.setAttribute('class', 'status error')
}
row.appendChild(testStatusCell);
};
/* test parsing */
test(nezasa.iso8601.Period.parse("PT1S"), "Array output - 1 second", "PT1S", "0,0,0,0,0,0,1");
test(nezasa.iso8601.Period.parse("PT1M"), "Array output - 1 minute", "PT1M", "0,0,0,0,0,1,0");
test(nezasa.iso8601.Period.parse("PT1H"), "Array output - 1 hour", "PT1H", "0,0,0,0,1,0,0");
test(nezasa.iso8601.Period.parse("P1D"), "Array output - 1 day", "P1D", "0,0,0,1,0,0,0");
test(nezasa.iso8601.Period.parse("P1W"), "Array output - 1 week", "P1D", "0,0,1,0,0,0,0");
test(nezasa.iso8601.Period.parse("P1M"), "Array output - 1 mounth", "P1M", "0,1,0,0,0,0,0");
test(nezasa.iso8601.Period.parse("P1Y"), "Array output - 1 year", "P1Y", "1,0,0,0,0,0,0");
test(nezasa.iso8601.Period.parse("P3Y6M1W4DT12H30M17S"), "Array output - combined period example", "P3Y61WM4DT12H30M17S", "3,6,1,4,12,30,17");
/* test total duration */
test(nezasa.iso8601.Period.parseToTotalSeconds("PT1S"), "total duration - 1 second", "PT1S", 1);
test(nezasa.iso8601.Period.parseToTotalSeconds("PT1M"), "total duration - 1 minute", "PT1M", 60);
test(nezasa.iso8601.Period.parseToTotalSeconds("PT1H"), "total duration - 1 hour", "PT1H", 60*60);
test(nezasa.iso8601.Period.parseToTotalSeconds("P1D"), "total duration - 1 day", "P1D", 24*60*60);
test(nezasa.iso8601.Period.parseToTotalSeconds("P1W"), "total duration - 1 week", "P1W", 24*60*60*7);
test(nezasa.iso8601.Period.parseToTotalSeconds("P1M"), "total duration - 1 month", "P1M", 30*24*60*60);
test(nezasa.iso8601.Period.parseToTotalSeconds("P1Y"), "total duration - 1 year", "P1Y", 360*24*60*60);
test(nezasa.iso8601.Period.parseToTotalSeconds("P3Y6M4DT12H30M17S"), "total duration - combined period example", "P3Y6M4DT12H30M17S", ((((3*12+6)*30+4)*24+12)*60+30)*60+17);
/* test string parsing */
test(nezasa.iso8601.Period.parseToString("PT1S"), "string output - 1 second", "PT1S", "1 second");
test(nezasa.iso8601.Period.parseToString("PT1M"), "string output - 1 minute", "PT1M", "1 minute");
test(nezasa.iso8601.Period.parseToString("PT1H"), "string output - 1 hour", "PT1H", "1 hour");
test(nezasa.iso8601.Period.parseToString("P1D"), "string output - 1 day", "P1D", "1 day");
test(nezasa.iso8601.Period.parseToString("P1W"), "string output - 1 week", "P1W", "1 week");
test(nezasa.iso8601.Period.parseToString("P1M"), "string output - 1 month", "P1M", "1 month");
test(nezasa.iso8601.Period.parseToString("P1Y"), "string output - 1 year", "P1Y", "1 year");
test(nezasa.iso8601.Period.parseToString("PT1H1S"), "string output - combined period example - English units (default)", "PT1H1S", "1 hour 1 second");
test(nezasa.iso8601.Period.parseToString("P1WT1H"), "string output - combined period example - English units (default)", "P1W1H", "1 week 1 hour");
test(nezasa.iso8601.Period.parseToString("P1Y4DT1H13M1S"), "string output - combined period example - English units (default)", "P1Y4DT1H13M1S", "1 year 4 days 1 hour 13 minutes 1 second");
test(nezasa.iso8601.Period.parseToString("P1Y4DT1H3S"), "string output - combined period example - English units (default)", "P1Y4DT1H3S", "1 year 4 days 1 hour 3 seconds");
test(nezasa.iso8601.Period.parseToString("P3Y6M4DT12H30M17S"), "string output - combined period example - English units (default)", "P3Y6M4DT12H30M17S", "3 years 6 months 4 days 12 hours 30 minutes 17 seconds");
/* test customized unit strings */
var deUnits = ['Jahr', 'Monat', 'Woche', 'Tag', 'Stunde', 'Minute', 'Sekunde'];
var deUnitsPlural = ['Jahre', 'Monate', 'Wochen', 'Tage', 'Stunden', 'Minuten', 'Sekunden'];
test(nezasa.iso8601.Period.parseToString("P3Y6M1W4DT12H30M17S", deUnits, deUnitsPlural), "string output - combined period example - German units", "P3Y6M4DT12H30M17S", "3 Jahre 6 Monate 1 Woche 4 Tage 12 Stunden 30 Minuten 17 Sekunden");
$("#cntTotalTests").html($(".status").size());
$("#cntTotalOkTests").html($(".status.success").size());
$("#cntTotalFailedTests").html($(".status.error").size());
</script>
</body>
</html>