forked from milanvrekic/JS-humanize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.html
executable file
·88 lines (84 loc) · 4.38 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
<script type="text/javascript" src="humanize.js"></script>
<script type="text/javascript">
function runTests( tests ) {
document.write( '<table border="1">' );
document.write( '<tr><th>Test</th><th>Result</th></tr>' );
for ( i in tests ) {
document.write( '<tr>' );
var testFunction = tests[ i ][0].replace(/(\r\n|\n|\r)/gm,"\\n");
document.write( '<td>'+testFunction+'</td>' );
var result = eval( testFunction );
var expected = tests[i][1];
var isRegexp = expected instanceof RegExp;
if (isRegexp) {
var passed = (expected.exec(result)[0] === result);
} else {
var passed = (result === expected);
}
document.write( '<td style="background-color:'+(passed?"green":"red")+'">'+result.replace(/(<)/gm,"<").replace(/(>)/gm,">")+'</td>' );
document.write( '</tr>' );
}
document.write( '</table>' );
}
var tests = [
['Humanize.intcomma( 4500000 )','4,500,000']
, ['Humanize.intcomma( 450000 )', '450,000']
, ['Humanize.intcomma( 45000 )', '45,000']
, ['Humanize.intword( 1000000 )', '1.0 million']
, ['Humanize.intword( 1200000 )', '1.2 million']
, ['Humanize.intword( 1200000000 )', '1.2 billion']
, ['Humanize.naturalDay( time() )', 'today']
, ['Humanize.naturalDay( time() +60*60*24 )', 'tomorrow']
, ['Humanize.naturalDay( time() -60*60*24 )', 'yesterday']
, ['Humanize.naturalDay( time() -2*60*60*24 )', '2012-04-14']
, ['Humanize.naturalDay( "13 April 2012" )', '2012-04-13']
, ['Humanize.naturalDay( "15 April 2012 16:25:30" )', 'yesterday']
, ['Humanize.naturalTime( time() )', 'now']
, ['Humanize.naturalTime( time() +130 )', 'in 2 minutes']
, ['Humanize.naturalTime( time() +70 )', 'in one minute']
, ['Humanize.naturalTime( time() +20 )', /in (19|20|21) seconds/] // these should be 20 secs exactly ?
, ['Humanize.naturalTime( time() -20 )', /(19|20|21) seconds ago/] // ^^
, ['Humanize.naturalTime( time() -70 )', 'one minute ago']
, ['Humanize.naturalTime( time() -130 )', '2 minutes ago']
, ['Humanize.naturalTime( time() +70 )', 'in one minute']
, ['Humanize.naturalTime( time() +130 )', 'in 2 minutes']
, ['Humanize.naturalTime( time() +60*20 )', 'in 20 minutes']
, ['Humanize.naturalTime( time() +60*60*5 )', 'in about 5 hours']
, ['Humanize.naturalTime( time() +60*60*20 )', /\d+:\d\d[ap]m/]
, ['Humanize.ordinal( 1 )', '1st']
, ['Humanize.ordinal( 2 )', '2nd']
, ['Humanize.ordinal( 3 )', '3rd']
, ['Humanize.ordinal( 4 )', '4th']
, ['Humanize.ordinal( 11 )', '11th']
, ['Humanize.ordinal( 12 )', '12th']
, ['Humanize.ordinal( 13 )', '13th']
, ['Humanize.ordinal( 14 )', '14th']
, ['Humanize.ordinal( 24 )', '24th']
, ['Humanize.ordinal( 127 )', '127th']
, ['Humanize.filesizeformat( 123456789 )', '117.74 MB']
, ['Humanize.filesizeformat( 1234567890 )', '1.15 GB']
, ['Humanize.filesizeformat( 123456 )', '121 KB']
, ['Humanize.filesizeformat( 123 )', '123 bytes']
, ['Humanize.linebreaks( "Play\ning with blank lines" )', '<p>Play<br />ing with blank lines</p>']
, ['Humanize.linebreaks( "Here is what happens\nwhen we add newlines\n\nfollowed by\n\na blank line" )', '<p>Here is what happens<br />when we add newlines</p><p>followed by</p><p>a blank line</p>']
, ['Humanize.linebreaksbr( "Play\ning with blank lines" )', 'Play<br />ing with blank lines']
, ['Humanize.linebreaksbr( "Play\n\ning with more \n\nblank lines" )', 'Play<br /><br />ing with more <br /><br />blank lines']
, ['Humanize.pluralize( 1 )', '']
, ['Humanize.pluralize( 2 )', 's']
, ['Humanize.pluralize( 1, "es" )', '']
, ['Humanize.pluralize( 2, "es" )', 'es']
, ['Humanize.pluralize( 1, "y", "ies" )', 'y']
, ['Humanize.pluralize( 2, "y", "ies" )', 'ies']
, ['Humanize.truncatechars( "hello world", 20 )', 'hello world']
, ['Humanize.truncatechars( "hello world", 13 )', 'hello world']
, ['Humanize.truncatechars( "hello world", 10 )', 'hello w...']
, ['Humanize.truncatechars( "hello world", 5 )', 'he...']
, ['Humanize.truncatewords( "Playing with truncate words", 5 )', 'Playing with truncate words']
, ['Humanize.truncatewords( "Playing with truncate words", 4 )', 'Playing with truncate words']
, ['Humanize.truncatewords( "Playing with truncate words", 3 )', 'Playing with truncate ...']
, ['Humanize.truncatewords( "Playing with truncate words", 2 )', 'Playing with ...']
, ['Humanize.truncatewords( "Playing with truncate words", 1 )', 'Playing ...']
, ['Humanize.truncatewords( "Playing with truncate words", 0 )', '...']
];
runTests( tests );
</script>