diff options
author | Nathan Gass | 2017-11-28 14:58:34 +0100 |
---|---|---|
committer | Nathan Gass | 2017-11-28 14:58:34 +0100 |
commit | 7a065544ad3b43c891d72ea5ae400a143f38f070 (patch) | |
tree | 669cd72c40c18e4e3d90ff093a0ae1532f8fdafc | |
parent | 94fba3bea36844b308829cfd04f0285c0b134a81 (diff) | |
download | itools-7a065544ad3b43c891d72ea5ae400a143f38f070.tar.gz itools-7a065544ad3b43c891d72ea5ae400a143f38f070.tar.bz2 itools-7a065544ad3b43c891d72ea5ae400a143f38f070.zip |
extract U tests in json file (so they can be used elsewhere)
-rw-r--r-- | tests/U_tests.json | 50 | ||||
-rwxr-xr-x | tests/it_html.t | 48 |
2 files changed, 53 insertions, 45 deletions
diff --git a/tests/U_tests.json b/tests/U_tests.json new file mode 100644 index 0000000..bf8d129 --- /dev/null +++ b/tests/U_tests.json @@ -0,0 +1,50 @@ +[ + + { + "args": ["/foo.html", {"bar": {"gna": 42, "qux": {"quux": "<Zürich>", "gnöp": "fasel"}}}], + "exp": "/foo.html?bar[gna]=42&bar[qux][quux]=%3CZ%C3%BCrich%3E&bar[qux][gn%C3%B6p]=fasel", + "name": "U() with nested arrays" + }, + + { + "args": ["/foo.html?a=b&bar=qux&c=d", {"bar": "baz"}], + "exp": "/foo.html?a=b&bar=baz&c=d", + "name": "U() args override get params in base url" + }, + + { + "args": ["/foo.html?bar.qux=a.b", {"c.d": "e.f", "g h": "i j"}], + "exp": "/foo.html?bar.qux=a.b&c.d=e.f&g+h=i+j", + "name": "U() dots and spaces in arg names are preserved" + }, + + { + "args": ["/foo.html?bar=qux#frag=frog", {"baz": "gna"}], + "exp": "/foo.html?bar=qux&baz=gna#frag=frog", + "name": "U() fragment after params" + }, + + { + "args": ["Jet d'eau"], + "exp": "Jet%20d%27eau", + "name": "U() with single quotes in URL" + }, + + { + "args": ["/test.html?foo=bar?qux=gna", {"?q": "?r"}], + "exp": "/test.html?foo=bar%3Fqux%3Dgna&%3Fq=%3Fr", + "name": "U() quoting of ? in args but not base" + }, + + { + "args": ["%% %1%x %1x%x1%xx%11%ff%FF"], + "exp": "%25%25%20%251%25x%20%251x%25x1%25xx%11%ff%FF", + "name": "U() quoting of % if not followed by 2 hex digits" + }, + + { + "args": ["a\\b"], + "exp": "a/b", + "name": "U() converting of \\ to /" + } +] diff --git a/tests/it_html.t b/tests/it_html.t index 875cccd..9231010 100755 --- a/tests/it_html.t +++ b/tests/it_html.t @@ -183,51 +183,9 @@ is( 'empty tags removal' ); -is( - U("/foo.html", array('bar' => array('gna' => 42, 'qux' => array('quux' => "<Zürich>", 'gnöp' => "fasel")))), - '/foo.html?bar[gna]=42&bar[qux][quux]=%3CZ%C3%BCrich%3E&bar[qux][gn%C3%B6p]=fasel', - 'U() with nested arrays' -); - -is( - U("/foo.html?a=b&bar=qux&c=d", array('bar' => "baz")), - '/foo.html?a=b&bar=baz&c=d', - 'U() args override get params in base url' -); - -is( - U("/foo.html?bar.qux=a.b", array('c.d' => "e.f", 'g h' => "i j")), - '/foo.html?bar.qux=a.b&c.d=e.f&g+h=i+j', - 'U() dots and spaces in arg names are preserved' -); - -is( - U("/foo.html?bar=qux#frag=frog", array('baz' => "gna")), - '/foo.html?bar=qux&baz=gna#frag=frog', - 'U() fragment after params' -); -is( - U("Jet d'eau"), - 'Jet%20d%27eau', - 'U() with single quotes in URL' -); - -is( - U('/test.html?foo=bar?qux=gna', array('?q' => '?r')), - '/test.html?foo=bar%3Fqux%3Dgna&%3Fq=%3Fr', - 'U() quoting of ? in args but not base' -); -is( - U('%% %1%x %1x%x1%xx%11%ff%FF'), - '%25%25%20%251%25x%20%251x%25x1%25xx%11%ff%FF', - 'U() quoting of % if not followed by 2 hex digits' -); - -is( - U('a\\b'), - 'a/b', - 'U() converting of \ to /' -); +foreach (search::json_decode(file_get_contents(dirname($argv[0]) . '/U_tests.json')) as $test) { + is(U(...$test['args']), $test['exp'], $test['name']); +} is(it_html::entity_decode("ä"), "ä"); is(it_html::entity_decode("J"), "J"); |