1 function test_utils() { |
|
2 module("Utility function tests"); |
|
3 |
|
4 test("test a function to preserve the scope of a method in a callback", function() { |
|
5 var obj = { a : 2}; |
|
6 obj.b = function(e, f) { |
|
7 equal(this.a, 2, "the scope is preserved"); |
|
8 equal(e, 1, "arg 1 passed correctly"); |
|
9 equal(f, 2, "arg 2 passed correctly"); |
|
10 }; |
|
11 |
|
12 (IriSP.wrap(obj, obj.b))(1, 2); |
|
13 |
|
14 }); |
|
15 |
|
16 test("test function to convert a ratio to a percentage", function() { |
|
17 var time = 2; |
|
18 var total = 3; |
|
19 |
|
20 equal(IriSP.timeToPourcent(2, 3), 66, "the function returns the correct result"); |
|
21 |
|
22 var total = -total; |
|
23 |
|
24 equal(IriSP.timeToPourcent(2, 3), 66, "the function is immune to negative numbers"); |
|
25 }); |
|
26 |
|
27 test("test padding function", function() { |
|
28 equal(IriSP.padWithZeros(3), "03", "function works correctly"); |
|
29 }); |
|
30 |
|
31 test("test function to convert from seconds to a time", function() { |
|
32 var h = 13, m = 7, s = 41; |
|
33 var t = 13 * 3600 + 7* 60 + 41; |
|
34 |
|
35 var r = IriSP.secondsToTime(t); |
|
36 ok(r.hours === h && r.minutes === m && r.seconds === s, "the converted time is correct"); |
|
37 |
|
38 t = -t; |
|
39 var r = IriSP.secondsToTime(t); |
|
40 ok(r.hours === h && r.minutes === m && r.seconds === s, "the function is immune to negative numbers."); |
|
41 equal(IriSP.secondsToTime(t), "13:07:41"); |
|
42 }); |
|
43 |
|
44 test("test function to format a tweet", function() { |
|
45 var inputs = ["@handle", "@bundle", "#hashtag", "http://t.co/11111", "++", "--"]; |
|
46 var outputs = ["<a href='http://twitter.com/handle'>@handle</a>", |
|
47 "<a href='http://twitter.com/bundle'>@bundle</a>", |
|
48 "<a href='http://twitter.com/search?q=%23hashtag'>#hashtag</a>", |
|
49 "<a href='http://t.co/11111'>http://t.co/11111</a>", |
|
50 "<span class='Ldt-PolemicPlusPlus'>++</span>", |
|
51 "<span class='Ldt-PolemicMinusMinus'>--</span>"]; |
|
52 |
|
53 var i = 0; |
|
54 for(i = 0; i < inputs.length; i++) { |
|
55 equal(IriSP.formatTweet(inputs[i]), outputs[i], "the correct output is given"); |
|
56 } |
|
57 }); |
|
58 |
|
59 test("test function to convert decimal color to hexadecimal", function() { |
|
60 equal(IriSP.DEC_HEXA_COLOR(125), "7D", "first test passes"); |
|
61 equal(IriSP.DEC_HEXA_COLOR(24345), "5F19", "second test passes"); |
|
62 |
|
63 }); |
|
64 |
|
65 test("test template function", function() { |
|
66 IriSP.default_templates_vars["test_fixture"] = "FIXTURE"; |
|
67 equal(IriSP.templToHTML("{{test_fixture}} {{foo}}", {foo: 2}), "FIXTURE 2", "correct template returned"); |
|
68 }); |
|
69 |
|
70 test("test url encoding function", function() { |
|
71 equal(IriSP.encodeURI("!'()*"), "%21%27%28%29%2A", "the returned string is correct"); |
|
72 }); |
|
73 } |
|