Skip to content

Commit

Permalink
Tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awwright committed Jun 5, 2017
1 parent f9a4f1f commit 5bde99b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ Variables are alphanumeric, and optionally end with a variable modifier:

## Evaluation order

URI Template Router returns a single, best matching URI.
URI Template Router returns a single, best matching template and the values that the expressions matched.

### Characters are preferred over expressions

The matching processor will only return a single, best match. If there's multiple matching templates, the processor evaluates the URI left to right, preferring to match character literals over expressions, and then in the order the templates were defined.
The matching processor will only return a single, best match. If there's multiple matching templates, the processor evaluates the URI left to right, preferring templates that match character literals over expressions, and then in the order the templates were defined.

For example, given the URI <`.../foo.html`>, the following templates would be preferred in the given order:

Expand Down
41 changes: 18 additions & 23 deletions perf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

function us(v){
var s = '' + (v[0]*10e9 + v[1]);
var s = '' + (v[0]*1e9 + v[1]);
if(s.length > 9) return s;
return (' ' + s).substr(-9) + 'us';
}
Expand All @@ -11,34 +11,29 @@ function pus(n, start){
console.log( pad + ' ' + us(process.hrtime(start)) );
}

function compareJSONParsedObject(a, b){
if(a===b) return true;
if(typeof a != typeof b) return false;
if(Array.isArray(a)){
if(a.length!=b.length) return false;
return a.every(function(k,i){ return compareJSONParsedObject(a[i], b[i]); });
}else{
if(Object.keys(a).length != Object.keys(b).length) return false;
return Object.keys(a).every(function(k){ return compareJSONParsedObject(a[k], b[k]); });
}
}

var testRouters = {
range: require('./route-range.js').Router,
// range2: require('./route-range2.js').Router,
// range3: require('./route-range3.js').Router,
range4: require('./route-range4.js').Router,
control: require('./route.js').Router,
};
padlen = Math.max.apply(null, Object.keys(testRouters).map(function(v){ return v.length; }));

function test(uri){
var a = r.resolveURI(uri);
if(!a.length){
return;
}
a.forEach(function(v, i){
return;
});
}

function test2(uri){
//return uri.match(/^http:\/\/example.com\/blog\/$/);
var a = r2.resolveURI(uri);
if(!a.length){
return;
}
a.forEach(function(v, i){
return;
});
}

var testData = require('./t/data.json');
var cycles = 60000;
var cycles = 100000;

testData.forEach(function(testPage, pg){
console.log('\nTesting page '+pg);
Expand Down
2 changes: 1 addition & 1 deletion tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var file = './route-range4.js';
var file = './route.js';
console.log(file);
var Router = require(file).Router;
var r = new Router;
Expand Down

0 comments on commit 5bde99b

Please sign in to comment.