hardened filter tests

This commit is contained in:
Leon van Kammen 2023-11-23 11:25:52 +01:00
parent ca0ded3095
commit f11a647bb7
3 changed files with 15 additions and 11 deletions

View File

@ -31,7 +31,7 @@ class Test {
var valid:Bool = false;
var item:Dynamic = spec[i];
f = new Filter(item.data);
res = URI.parse(item.data,0);
res = URI.parse(item.data,null);
if( item.expect.fn == "test" ) valid = item.expect.out == f.test( item.expect.input[0] );
if( item.expect.fn == "testProperty" ) valid = item.expect.out == f.testProperty( item.expect.input[0], item.expect.input[1] );
if( item.expect.fn == "testPropertyInt" ) valid = item.expect.out == f.testProperty( item.expect.input[0], item.expect.input[1] );
@ -45,7 +45,7 @@ class Test {
if( item.expect.fn == "equal.x" ) valid = equalX(res,item);
if( item.expect.fn == "equal.xy" ) valid = equalXY(res,item);
if( item.expect.fn == "equal.xyz" ) valid = equalXYZ(res,item);
if( item.expect.fn == "testFilterRoot" ) valid = item.expect.out == f.get()[ item.expect.input[0] ].root;
if( item.expect.fn == "testFilterRoot" ) valid = res.exists(item.expect.input[0]) && res.get(item.expect.input[0]).filter.get().root == item.expect.out;
var ok:String = valid ? "[ ] " : "[ ] ";
trace( ok + item.fn + ": '" + item.data + "'" + (item.label ? " (" + (item.label?item.label:item.expect.fn) +")" : ""));
if( !valid ) errors += 1;

View File

@ -2,12 +2,16 @@
{"fn":"url","data":"http://foo.com?foo=1#foo*&-sometag&-someid&myid", "expect":{ "fn":"testParsed", "input":"myid","out":true},"label":"myid exists"},
{"fn":"url","data":"http://foo.com?foo=1#tag=bar", "expect":{ "fn":"testParsed", "input":"tag", "out":true},"label":"tag exists"},
{"fn":"url","data":"http://foo.com?foo=1#-tag=bar", "expect":{ "fn":"testParsed", "input":"tag", "out":true},"label":"tag exists"},
{"fn":"url","data":"http://foo.com?foo=1#price=>2", "expect":{ "fn":"testParsed", "input":"price","out":true},"label":"query test"},
{"fn":"query","data":"tag=bar", "expect":{ "fn":"testProperty","input":["tag","bar"],"out":true}},
{"fn":"query","data":"-tag=foo", "expect":{ "fn":"testProperty","input":["tag","foo"],"out":false}},
{"fn":"query","data":"-tag*=foo", "expect":{ "fn":"testProperty","input":["tag","foo"],"out":false}},
{"fn":"query","data":"-tag=>2", "expect":{ "fn":"testProperty","input":["tag","3"],"out":false}},
{"fn":"query","data":"price=>2", "expect":{ "fn":"testProperty","input":["price","1"],"out":false}},
{"fn":"query","data":"price=<2", "expect":{ "fn":"testProperty","input":["price","5"],"out":false}},
{"fn":"query","data":"price=<2", "expect":{ "fn":"testProperty","input":["price","1"],"out":true}}
{"fn":"url","data":"http://foo.com?foo=1#price=>2", "expect":{ "fn":"testParsed", "input":"price","out":true},"label":"filter test"},
{"fn":"filter","data":"tag=bar", "expect":{ "fn":"testProperty","input":["tag","bar"],"out":true}},
{"fn":"filter","data":"-tag=foo", "expect":{ "fn":"testProperty","input":["tag","foo"],"out":false}},
{"fn":"filter","data":"-tag*=foo", "expect":{ "fn":"testProperty","input":["tag","foo"],"out":false}},
{"fn":"filter","data":"-tag=>2", "expect":{ "fn":"testProperty","input":["tag","3"],"out":false}},
{"fn":"filter","data":"price=>2", "expect":{ "fn":"testProperty","input":["price","1"],"out":false}},
{"fn":"filter","data":"price=<2", "expect":{ "fn":"testProperty","input":["price","5"],"out":false}},
{"fn":"filter","data":"price=<2", "expect":{ "fn":"testProperty","input":["price","1"],"out":true}},
{"fn":"url","data":"#/foo", "expect":{ "fn":"testFilterRoot","input":["foo"],"out":true},"label":"foo should be root-only"},
{"fn":"url","data":"#/foo&foo","expect":{ "fn":"testFilterRoot","input":["foo"],"out":false},"label":"foo should recursively selected"},
{"fn":"url","data":"#/foo&foo&/bar", "expect":{ "fn":"testFilterRoot","input":["foo"],"out":false},"label":"bar should be root-only"},
{"fn":"url","data":"#-/foo", "expect":{ "fn":"testFilterRoot","input":["foo"],"out":true},"label":"foo should be root-only"}
]

View File

@ -98,7 +98,7 @@ class Filter {
else rule[oper] = v;
q.set('expr',rule);
}else{ // 1. <b>ELSE </b> we are dealing with an object
q.set("root", isRoot.match(str) ? true : false ); // 1. and we set `root` to `true` or `false` (true=`/` root selector is present)
q.set("root", isRoot.match(str) ? true : false ); // 1. and we set `root` to `true` or `false` (true=`/` root selector is present)
}
q.set("show", isExclude.match(str) ? false : true ); // 1. therefore we we set `show` to `true` or `false` (false=excluder `-`)
q.set("key", operators.replace(k,'') );