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')) {
26 } else if (typeof a == 'object' && typeof b == 'object') {
27 if (a.length != b.length) {
30 for (var i = 0; i < a.length; i++) {
31 if (! tree_equal (a[i], b[i])) {
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",
59 conkeror.encode_xpcom_structure ("foo")
60 .QueryInterface (Components.interfaces.nsISupportsString)
63 function test_decode_xpcom_string () {
64 var data = Components.classes["@mozilla.org/supports-string;1"]
65 .createInstance(Components.interfaces.nsISupportsString);
67 assert_equal ("batchjs", "conkeror.decode_xpcom_structure decodes string",
69 conkeror.decode_xpcom_structure (data));
71 test_decode_xpcom_string ();
74 assert_equal ("batchjs", "decode_xpcom_structure (encode_xpcom_structure ( ... )) 1",
76 conkeror.decode_xpcom_structure (
77 conkeror.encode_xpcom_structure (
80 assert_that ("batchjs", "decode_xpcom_structure (encode_xpcom_structure ( ... )) 2",
82 conkeror.decode_xpcom_structure (
83 conkeror.encode_xpcom_structure (
86 assert_that ("batchjs", "decode_xpcom_structure (encode_xpcom_structure ( ... )) 3",
88 conkeror.decode_xpcom_structure (
89 conkeror.encode_xpcom_structure (
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 () {
100 conkeror.add_hook (myhook, 1);
101 assert_that ("batchjs", "test_add_hook_set",
102 tree_equal ([1,2,3], myhook));
105 conkeror.add_hook (myhook, 4, true);
106 assert_that ("batchjs", "test_add_hook_set (append)",
107 tree_equal ([1,2,3,4], myhook));
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
121 function test_prefix_duplication () {
122 function inner (pfx1, pfx2) {
123 assert_that ("batchjs", "test_prefix_duplication",
124 pfx1 == pfx2 && pfx1 == 1);
127 current_prefix_argument: 1,
128 message: function (str) {dump (str + "\n");}
130 interactive ("test-prefix-duplication", inner, ['P', 'P']);
131 call_interactively (fake_window, "test-prefix-duplication");
134 test_prefix_duplication();