youporn.js: Remove unneeded title scraping
[conkeror.git] / test / batch-suite.js
blobfb0589a86df9dca444499bc8c1ffd4667f1a2a94
2 /*
3  *
4  *
5  */
6 function report_assertion (desc, passfail) {
7     conkeror.dumpln ("test: " + desc + " ... " + (passfail ? "pass" : "fail"));
10 function assert_that (suite, desc, thing) {
11     report_assertion (desc, (thing ? true : false));
14 function assert_not (suite, desc, thing) {
15     report_assertion (desc, (thing ? false : true));
18 function assert_equal (suite, desc, expected, actual) {
19     report_assertion (desc, (expected == actual ? true : false));
22 function tree_equal (a, b) {
23     if ((typeof a == 'string' && typeof b == 'string') ||
24         (typeof a == 'number' && typeof b == 'number')) {
25         return a == b;
26     } else if (typeof a == 'object' && typeof b == 'object') {
27         if (a.length != b.length) {
28             return false;
29         }
30         for (var i = 0; i < a.length; i++) {
31             if (! tree_equal (a[i], b[i])) {
32                 return false;
33             }
34         }
35         return true;
36     } else {
37         return false;
38     }
41 assert_that ("batchjs", "tree_equal 1", tree_equal ("a", "a"));
42 assert_that ("batchjs", "tree_equal 2", tree_equal ([], []));
43 assert_that ("batchjs", "tree_equal 3", tree_equal (["b"], ["b"]));
44 assert_that ("batchjs", "tree_equal 4", tree_equal ([["b"]], [["b"]]));
45 assert_that ("batchjs", "tree_equal 5", tree_equal ([["b"],"c"], [["b"],"c"]));
46 assert_not ("batchjs", "not tree_equal 1", tree_equal ("a", "b"));
47 assert_not ("batchjs", "not tree_equal 2", tree_equal ("a", []));
48 assert_not ("batchjs", "not tree_equal 3", tree_equal ([[]], []));
50 // check the behavior of the `%' operator.  We depend on this to be a
51 // remainder, rather than modulus, in the frameset/iframe commands.
53 assert_equal ("batchjs", "% means REMAINDER, not MODULUS", -4, -4 % 7);
55 // test conkeror.encode_xpcom_structure and conkeror.decode_xpcom_structure.
57 assert_equal ("batchjs", "conkeror.encode_xpcom_structure encodes string",
58               "foo",
59               conkeror.encode_xpcom_structure ("foo")
60               .QueryInterface (Components.interfaces.nsISupportsString)
61               .data);
63 function test_decode_xpcom_string () {
64     var data = Components.classes["@mozilla.org/supports-string;1"]
65         .createInstance(Components.interfaces.nsISupportsString);
66     data.data = "bar";
67     assert_equal ("batchjs", "conkeror.decode_xpcom_structure decodes string",
68                   "bar",
69                   conkeror.decode_xpcom_structure (data));
71 test_decode_xpcom_string ();
74 assert_equal ("batchjs", "decode_xpcom_structure (encode_xpcom_structure ( ... )) 1",
75               "a",
76               conkeror.decode_xpcom_structure (
77                   conkeror.encode_xpcom_structure (
78                       "a")));
80 assert_that ("batchjs", "decode_xpcom_structure (encode_xpcom_structure ( ... )) 2",
81              tree_equal ([],
82                          conkeror.decode_xpcom_structure (
83                              conkeror.encode_xpcom_structure (
84                                  []))));
86 assert_that ("batchjs", "decode_xpcom_structure (encode_xpcom_structure ( ... )) 3",
87              tree_equal (["a"],
88                          conkeror.decode_xpcom_structure (
89                              conkeror.encode_xpcom_structure (
90                                  ["a"]))));
92 assert_that ("batchjs", "decode_xpcom_structure (encode_xpcom_structure ( ... )) 4",
93              tree_equal ([["foo", "bar"], "baz", ["quux"]],
94                          conkeror.decode_xpcom_structure (
95                              conkeror.encode_xpcom_structure (
96                                  [["foo", "bar"], "baz", ["quux"]]))));
98 function test_add_hook_set () {
99     var myhook = [1,2,3];
100     conkeror.add_hook (myhook, 1);
101     assert_that ("batchjs", "test_add_hook_set",
102                  tree_equal ([1,2,3], myhook));
104     myhook = [1,2,3];
105     conkeror.add_hook (myhook, 4, true);
106     assert_that ("batchjs", "test_add_hook_set (append)",
107                  tree_equal ([1,2,3,4], myhook));
109     myhook = [1,2,3];
110     conkeror.add_hook (myhook, 0);
111     assert_that ("batchjs", "test_add_hook_set (append)",
112                  tree_equal ([0,1,2,3], myhook));
114 test_add_hook_set ();
117 // test_prefix_duplication: this tests whether an interactive command
118 // can receive two copies of raw-prefix-arg.  For this to work, the
119 // prefix arg cannot be nulled until all interactive data has been
120 // collected.
121 function test_prefix_duplication () {
122     function inner (pfx1, pfx2) {
123         assert_that ("batchjs", "test_prefix_duplication",
124                      pfx1 == pfx2 && pfx1 == 1);
125     }
126     var fake_window = {
127         current_prefix_argument: 1,
128         message: function (str) {dump (str + "\n");}
129     };
130     interactive ("test-prefix-duplication", inner, ['P', 'P']);
131     call_interactively (fake_window, "test-prefix-duplication");
132     return true;
134 test_prefix_duplication();