Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | function run_test() { |
michael@0 | 5 | do_check_matches({x:1}, {x:1}); // pass |
michael@0 | 6 | todo_check_matches({x:1}, {}); // fail: all pattern props required |
michael@0 | 7 | todo_check_matches({x:1}, {x:2}); // fail: values must match |
michael@0 | 8 | do_check_matches({x:1}, {x:1, y:2}); // pass: extra props tolerated |
michael@0 | 9 | |
michael@0 | 10 | // Property order is irrelevant. |
michael@0 | 11 | do_check_matches({x:"foo", y:"bar"}, {y:"bar", x:"foo"});// pass |
michael@0 | 12 | |
michael@0 | 13 | do_check_matches({x:undefined}, {x:1});// pass: 'undefined' is wildcard |
michael@0 | 14 | do_check_matches({x:undefined}, {x:2}); |
michael@0 | 15 | todo_check_matches({x:undefined}, {y:2});// fail: 'x' must still be there |
michael@0 | 16 | |
michael@0 | 17 | // Patterns nest. |
michael@0 | 18 | do_check_matches({a:1, b:{c:2,d:undefined}}, {a:1, b:{c:2,d:3}}); |
michael@0 | 19 | |
michael@0 | 20 | // 'length' property counts, even if non-enumerable. |
michael@0 | 21 | do_check_matches([3,4,5], [3,4,5]); // pass |
michael@0 | 22 | todo_check_matches([3,4,5], [3,5,5]); // fail; value doesn't match |
michael@0 | 23 | todo_check_matches([3,4,5], [3,4,5,6]);// fail; length doesn't match |
michael@0 | 24 | |
michael@0 | 25 | // functions in patterns get applied. |
michael@0 | 26 | do_check_matches({foo:function (v) v.length == 2}, {foo:"hi"});// pass |
michael@0 | 27 | todo_check_matches({foo:function (v) v.length == 2}, {bar:"hi"});// fail |
michael@0 | 28 | todo_check_matches({foo:function (v) v.length == 2}, {foo:"hello"});// fail |
michael@0 | 29 | |
michael@0 | 30 | // We don't check constructors, prototypes, or classes. However, if |
michael@0 | 31 | // pattern has a 'length' property, we require values to match that as |
michael@0 | 32 | // well, even if 'length' is non-enumerable in the pattern. So arrays |
michael@0 | 33 | // are useful as patterns. |
michael@0 | 34 | do_check_matches({0:0, 1:1, length:2}, [0,1]); // pass |
michael@0 | 35 | do_check_matches({0:1}, [1,2]); // pass |
michael@0 | 36 | do_check_matches([0], {0:0, length:1}); // pass |
michael@0 | 37 | } |