position_in_strings: new util
[conkeror.git] / tests / simple / utils.js
blob89fe7bb34f1dd62fe5185b910efba2b28b87ab0d
2 require('walnut.js');
4 walnut_run({
5     test_remove_duplicates_filter_1: function () {
6         var ar = [1, 2, 3, 3];
7         assert_objects_equal(ar.filter(remove_duplicates_filter()), [1, 2, 3]);
8     },
9     test_get_home_directory_1: function () {
10         assert(get_home_directory() instanceof Ci.nsIFile);
11     },
12     test_splice_range_1: function () {
13         assert_objects_equal(splice_range([[1,3],[4,6],[7,10]], 2, 8),
14                              [[1,10]]);
15     }
16 });
18 walnut_run({
19     test_string_format_1: function () {
20         assert_equals(string_format("", {}),
21                       "");
22     },
23     test_string_format_2: function () {
24         assert_equals(string_format("%a", {a: 'hello'}),
25                       "hello");
26     },
27     test_string_format_3: function () {
28         assert_equals(string_format("%a%a", {a: 'hello'}),
29                       "hellohello");
30     }
31 });
34 walnut_run({
35     test_array_p_1: function () {
36         assert(array_p([]));
37     },
38     test_array_p_2: function () {
39         assert(array_p(Array()));
40     },
41     test_make_array_1: function () {
42         assert_objects_equal(make_array(undefined), []);
43     },
44     test_make_array_2: function () {
45         assert_objects_equal(make_array(null), [null]);
46     }
47 });
50 walnut_run({
51     test_possibly_valid_url_1: function () {
52         assert_not(possibly_valid_url(""));
53     },
54     test_possibly_valid_url_2: function () {
55         assert_not(possibly_valid_url("         "));
56     },
57     test_possibly_valid_url_3: function () {
58         assert(possibly_valid_url("example"));
59     },
60     test_possibly_valid_url_4: function () {
61         assert(possibly_valid_url("  example  "));
62     },
63     test_possibly_valid_url_5: function () {
64         assert_not(possibly_valid_url("example foo"));
65     },
66     test_possibly_valid_url_6: function () {
67         assert(possibly_valid_url("example/ foo"));
68     },
69     test_possibly_valid_url_7: function () {
70         assert_not(possibly_valid_url("example /foo"));
71     },
72     test_possibly_valid_url_8: function () {
73         assert(possibly_valid_url("/example foo"));
74     },
75     test_possibly_valid_url_9: function () {
76         assert(possibly_valid_url(" /example foo"));
77     },
78     test_possibly_valid_url_10: function () {
79         assert(possibly_valid_url(" ex/ample foo"));
80     },
81     test_possibly_valid_url_11: function () {
82         assert(possibly_valid_url("/"));
83     }
84 });
87 walnut_run({
88     test_position_in_strings_1: function () {
89         assert_equals(position_in_strings([null], 0), -1);
90     },
91     test_position_in_strings_2: function () {
92         assert_equals(position_in_strings([], 0), -1);
93     },
94     test_position_in_strings_3: function () {
95         assert_equals(position_in_strings(["a"], 0), -1);
96     },
97     test_position_in_strings_4: function () {
98         assert_equals(position_in_strings(["a"], 1), 0);
99     },
100     test_position_in_strings_5: function () {
101         assert_equals(position_in_strings(["a"], 2), 0);
102     },
103     test_position_in_strings_6: function () {
104         assert_equals(position_in_strings(["a", "b"], 1), 0);
105     },
106     test_position_in_strings_7: function () {
107         assert_equals(position_in_strings(["a", "b"], 2), 1);
108     },
109     test_position_in_strings_8: function () {
110         assert_equals(position_in_strings(["a", "b"], 3), 1);
111     },
112     test_position_in_strings_9: function () {
113         assert_equals(position_in_strings(["a", "b", "c"], 3), 2);
114     },
115     test_position_in_strings_10: function () {
116         assert_equals(position_in_strings([""], 1), 0);
117     },
118     test_position_in_strings_11: function () {
119         assert_equals(position_in_strings(["foo", " ", "bar"], 0), -1);
120     },
121     test_position_in_strings_12: function () {
122         assert_equals(position_in_strings(["foo", " ", "bar"], 1), 0);
123     },
124     test_position_in_strings_13: function () {
125         assert_equals(position_in_strings(["foo", " ", "bar"], 2), 0);
126     },
127     test_position_in_strings_14: function () {
128         assert_equals(position_in_strings(["foo", " ", "bar"], 3), 0);
129     },
130     test_position_in_strings_15: function () {
131         assert_equals(position_in_strings(["foo", " ", "bar"], 4), 1);
132     },
133     test_position_in_strings_16: function () {
134         assert_equals(position_in_strings(["foo", " ", "bar"], 5), 2);
135     },
136     test_position_in_strings_17: function () {
137         assert_equals(position_in_strings(["foo", " ", "bar"], 6), 2);
138     },
139     test_position_in_strings_18: function () {
140         assert_equals(position_in_strings(["foo", " ", "bar"], 7), 2);
141     },
142     test_position_in_strings_19: function () {
143         assert_equals(position_in_strings(["foo", " ", "bar"], 8), 2);
144     }