work in progress [might break]

This commit is contained in:
Leon van Kammen 2024-04-04 16:48:39 +00:00
parent 4f15c6b6cf
commit 7e39b79eb6
3 changed files with 22 additions and 28 deletions

View File

@ -45,7 +45,9 @@ 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" ) valid = testURL( item.data, item.expect.input, item.expect.out );
if( item.expect.fn == "testURL" ) valid = testURL( item.data, item.expect.input, item.expect.out, false );
if( item.expect.fn == "testURLHash" ) valid = testURL( item.data, item.expect.input, item.expect.out, false );
if( item.expect.fn == "testURLBrowse" ) valid = testURL( item.data, item.expect.input, item.expect.out, true );
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);
@ -86,25 +88,13 @@ class Test {
static public function testURL( url:String, attr:String, output:String, browserMode: Bool = false): Bool {
var URL = xrfragment.URL;
var url = URL.parse(url,false);
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;
var parts:Array<String> = attr.split(".");
if( parts.length > 1 && parts[0] == "hash" && url.hash.exists( parts[1]) ){
return url.hash.get( parts[1] ) == output;
}else{
if( Reflect.hasField(url, attr) && Reflect.field(url,attr) == output ) return true;
}
return false;
}
static public function testFilter():Void {

View File

@ -4,5 +4,6 @@
{"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":"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"}
{"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"},
{"fn":"url","data":"http://foo.com/a/b?foo=1#mycustom=foo", "expect":{ "fn":"testURL", "input":"hash.mycustom","out":"foo"},"label":"test URL hash #mycustom == foo"}
]

View File

@ -52,6 +52,7 @@ class URL
public var browserMode: Bool;
public var fragment : String;
public var hash : haxe.DynamicAccess<Dynamic>;
public var XRF : haxe.DynamicAccess<Dynamic>;
/**
* class constructor
@ -77,7 +78,6 @@ class URL
var url:URL = new URL();
url.browserMode = browserMode;
trace(url);
// Use reflection to set each part
for (i in 0..._parts.length)
@ -95,17 +95,20 @@ class URL
}
}
url.hash = {};
if( url.fragment.length > 0 ){
trace("ja");
url.hash = xrfragment.URI.parse( url.fragment, 0 );
trace(url.hash.get('mycustom'));
}else url.hash = {};
url.XRF = xrfragment.URI.parse( "#"+url.fragment, 0 );
var key:String;
for( key in url.XRF.keys() ){
var v:haxe.DynamicAccess<Dynamic> = url.XRF.get(key);
url.hash[key] = v.get("string");
}
}
return url;
}
/**
* Serialize an URL object into an
* Serialize an URl OBJect into an
* URL string
*/
public static function toString(url:URL):String