work in progress [might break]
This commit is contained in:
parent
36e48a521d
commit
4f15c6b6cf
3 changed files with 27 additions and 5 deletions
23
src/Test.hx
23
src/Test.hx
|
|
@ -45,7 +45,7 @@ class Test {
|
|||
if( item.expect.fn == "testPropertyAssign" ) valid = res.exists(item.expect.input) && item.expect.out == res.get(item.expect.input).is( XRF.PROP_BIND) ;
|
||||
if( item.expect.fn == "testBrowserOverride" ) valid = item.expect.out == (URI.parse(item.data,XRF.NAVIGATOR)).exists(item.expect.input);
|
||||
if( item.expect.fn == "testEmbedOverride" ) valid = item.expect.out == (URI.parse(item.data,XRF.METADATA)).exists(item.expect.input);
|
||||
if( item.expect.fn == "testURL" ) testURL( item.data, item.expect.input, item.expect.out );
|
||||
if( item.expect.fn == "testURL" ) valid = testURL( item.data, item.expect.input, item.expect.out );
|
||||
|
||||
if( item.expect.fn == "equal.string" ) valid = res.get(item.expect.input) && item.expect.out == res.get(item.expect.input).string;
|
||||
if( item.expect.fn == "equal.x" ) valid = equalX(res,item);
|
||||
|
|
@ -83,10 +83,27 @@ class Test {
|
|||
else return res.get( key ).floats[ Std.parseInt(item.expect.input) ] == Std.parseFloat(item.expect.out);
|
||||
}
|
||||
|
||||
static public function testURL( url:String, attr:String, output:String): Bool {
|
||||
static public function testURL( url:String, attr:String, output:String, browserMode: Bool = false): Bool {
|
||||
var URL = xrfragment.URL;
|
||||
var url = URL.parse(url,false);
|
||||
if( attr == 'scheme' && url.scheme == output ) return true;
|
||||
trace("url:"+url.url);
|
||||
trace("source:"+url.source);
|
||||
trace("scheme:"+url.scheme);
|
||||
trace("auth:"+url.authority);
|
||||
trace("uinfo:"+url.userInfo);
|
||||
trace("u:"+url.user);
|
||||
trace("pw:"+url.password);
|
||||
trace("host:"+url.host);
|
||||
trace("port:"+url.port);
|
||||
trace("relative:"+url.relative);
|
||||
trace("path:"+url.path);
|
||||
trace("directory:"+url.directory);
|
||||
trace("file:"+url.file);
|
||||
trace("query:"+url.query);
|
||||
trace("browserMode:"+url.browserMode);
|
||||
trace("fragment:"+url.fragment);
|
||||
trace("hash:"+url.hash);
|
||||
if( Reflect.hasField(url, attr) && Reflect.field(url,attr) == output ) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@
|
|||
{"fn":"url","data":"http://foo.com?foo=1#mypredefinedview&another", "expect":{ "fn":"testPredefinedView", "input":"another","out":true},"label":"test predefined view executed (multiple)"},
|
||||
{"fn":"url","data":"http://foo.com?foo=1#mypredefinedview&another", "expect":{ "fn":"testPredefinedView", "input":"mypredefinedview","out":true},"label":"test predefined view executed (multiple)"},
|
||||
{"fn":"url","data":"http://foo.com?foo=1#mycustom=foo", "expect":{ "fn":"testParsed", "input":"mycustom","out":true},"label":"test custom property"},
|
||||
{"fn":"url","data":"http://foo.com?foo=1#mycustom=foo", "expect":{ "fn":"testURL", "input":"scheme","out":"https://"},"label":"test URL scheme"}
|
||||
{"fn":"url","data":"http://foo.com?foo=1#mycustom=foo", "expect":{ "fn":"testURL", "input":"scheme","out":"http"},"label":"test URL scheme http"},
|
||||
{"fn":"url","data":"http://foo.com/a/b?foo=1#mycustom=foo", "expect":{ "fn":"testURL", "input":"path","out":"/a/b"},"label":"test URL path /a/b"}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import xrfragment.URI;
|
|||
*
|
||||
* @author Yannick Dominguez
|
||||
*/
|
||||
@:expose // <- makes the class reachable from plain JavaScript
|
||||
@:keep // <- avoids accidental removal by dead code elimination
|
||||
class URL
|
||||
{
|
||||
/**
|
||||
|
|
@ -67,7 +69,6 @@ class URL
|
|||
*/
|
||||
public static function parse(stringUrl:String, browserMode:Bool ):URL
|
||||
{
|
||||
|
||||
// The almighty regexp (courtesy of http://blog.stevenlevithan.com/archives/parseuri)
|
||||
var r : EReg = ~/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
||||
|
||||
|
|
@ -76,6 +77,7 @@ class URL
|
|||
|
||||
var url:URL = new URL();
|
||||
url.browserMode = browserMode;
|
||||
trace(url);
|
||||
|
||||
// Use reflection to set each part
|
||||
for (i in 0..._parts.length)
|
||||
|
|
@ -94,7 +96,9 @@ class URL
|
|||
}
|
||||
|
||||
if( url.fragment.length > 0 ){
|
||||
trace("ja");
|
||||
url.hash = xrfragment.URI.parse( url.fragment, 0 );
|
||||
trace(url.hash.get('mycustom'));
|
||||
}else url.hash = {};
|
||||
|
||||
return url;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue