~twpol/chatzilla/tests

« back to all changes in this revision

Viewing changes to js/tests/unit/test_utils.js

  • Committer: James Ross
  • Date: 2008-09-15 01:15:44 UTC
  • Revision ID: silver@warwickcompsoc.co.uk-20080915011544-pr3yha06zgbjotdc
Added some tests for replaceVars.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
function run_test()
2
2
{
3
3
    load("../../lib/utils.js");
4
 
    do_check_eq(ecmaEscape("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./"), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./");
5
4
 
6
5
    // Alas, the test framework uses dump(), which croaks on nulls. We must
7
6
    // therefore avoid using them in any of the literals that could be
8
7
    // displayed. Sigh.
 
8
    do_check_eq(ecmaEscape("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./"), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./");
9
9
    do_check_eq(ecmaEscape("\x01\x02\x03\x04\x05"), "%01%02%03%04%05");
10
10
    do_check_eq(ecmaEscape("\u0001\u0002\u0003\u0004\u0005"), "%01%02%03%04%05");
11
11
    do_check_eq(ecmaEscape("\u0100\u0101\u0102\u0103\u0104"), "%u0100%u0101%u0102%u0103%u0104");
21
21
 
22
22
    do_check_eq(encodeForXMLAttribute("&<>\"'&<>\"'"), "&amp;&lt;&gt;&quot;&apos;&amp;&lt;&gt;&quot;&apos;");
23
23
    do_check_eq(encodeForXMLAttribute("&&&amp;"), "&amp;&amp;&amp;amp;");
 
24
 
 
25
    var o = { foo: 42 };
 
26
    do_check_eq(replaceVars("foo", o), "foo");
 
27
    do_check_eq(replaceVars("foo$foofoo", o), "foo$foofoo");
 
28
    do_check_eq(replaceVars("foo $foo foo", o), "foo 42 foo");
 
29
    do_check_eq(replaceVars("$foo foo $foo", o), "42 foo 42");
 
30
    o["foo-bar"] = 43;
 
31
    do_check_eq(replaceVars("$foo $foo-bar $bar", o), "42 43 $bar");
 
32
    o["-bar"] = 44;
 
33
    do_check_eq(replaceVars("foo $-bar foo", o), "foo $-bar foo");
 
34
    o["42"] = 45;
 
35
    o["f42"] = 46;
 
36
    //FIXME:do_check_eq(replaceVars("$42 $f42", o), "$42 46");
24
37
}