RetroZilla/extensions/irc/js/tests/test_matchobject.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-10-21 05:03:22 +02:00
function test_matchObject()
{
var f = true;
obj1 = {foo:"hey", bar:"ho"}
obj2 = {a:"1", b:"2"}
p1 = {foo:"hey"}
p2 = {bar:"ho"}
p3 = {a:"1"}
p4 = {b:"2"}
/* true, single pattern, and it matches */
f &= matchObject (obj1, p1);
/* false, single pattern matches, negated */
f &= !matchObject (obj1, p1, true);
/* false, single pattern doesn't match */
f &= !matchObject (obj1, p3);
/* true, single pattern doesn't match, negated */
f &= matchObject (obj1, p3, true);
/* true, p1 matches */
f &= matchObject (obj1, [p1, p3]);
/* false, p1 matches, negated */
f &= !matchObject (obj1, [p1, p3], true);
/* true, both paterns match */
f &= matchObject (obj2, [p3, p4]);
/* false, both patterns match, negated */
f &= !matchObject (obj2, [p3, p4], true);
/* false, neither pattern matches */
f &= !matchObject (obj1, [p3, p4]);
/* true, neither pattern matches, negated */
f &= matchObject (obj1, [p3, p4], true);
return Boolean(f); /* you've got to find any problems by hand :) */
}