-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benches and tests for normalization, improve normalization perf
- Loading branch information
Showing
6 changed files
with
129 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var RouteRecognizer = require('../../dist/route-recognizer'); | ||
var Normalizer = RouteRecognizer.Normalizer; | ||
|
||
var router = new RouteRecognizer(); | ||
|
||
var paths = { | ||
complex: "/foo/" + encodeURIComponent("http://example.com/index.html?foo=bar&baz=faz#hashtag"), | ||
simple: "/post/123", | ||
medium: "/abc%3Adef" | ||
|
||
}; | ||
|
||
module.exports = [{ | ||
name: 'Normalize Complex', | ||
fn: function() { | ||
Normalizer.normalizePath(paths.complex); | ||
} | ||
}, { | ||
name: 'Normalize Simple', | ||
fn: function() { | ||
Normalizer.normalizePath(paths.simple); | ||
} | ||
}, { | ||
name: 'Normalize Medium', | ||
fn: function() { | ||
Normalizer.normalizePath(paths.medium); | ||
} | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* globals QUnit */ | ||
|
||
import RouteRecognizer from 'route-recognizer'; | ||
|
||
var Normalizer = RouteRecognizer.Normalizer; | ||
|
||
module("Normalization"); | ||
|
||
var expectations = [{ | ||
paths: ["/foo/bar"], | ||
normalized: "/foo/bar" | ||
}, { | ||
paths: ["/foo%3Abar", "/foo%3abar"], | ||
normalized: "/foo:bar" | ||
}, { | ||
paths: ["/foo%2fbar", "/foo%2Fbar"], | ||
normalized: "/foo%2Fbar" | ||
}, { | ||
paths: ["/café", "/caf%C3%A9", "/caf%c3%a9"], | ||
normalized: "/café" | ||
}, { | ||
paths: ["/abc%25def"], | ||
normalized: "/abc%25def" | ||
}, { | ||
paths: ["/" + encodeURIComponent("http://example.com/index.html?foo=100%&baz=boo#hash")], | ||
normalized: "/http:%2F%2Fexample.com%2Findex.html?foo=100%25&baz=boo#hash" | ||
}, { | ||
paths: ["/%25%25%25%25"], | ||
normalized: "/%25%25%25%25" | ||
}, { | ||
paths: ["/%25%25%25%25%3A%3a%2F%2f%2f"], | ||
normalized: "/%25%25%25%25::%2F%2F%2F" | ||
}]; | ||
|
||
expectations.forEach(function(expectation) { | ||
var paths = expectation.paths; | ||
var normalized = expectation.normalized; | ||
|
||
paths.forEach(function(path) { | ||
test("the path '" + path + "' is normalized to '" + normalized + "'", function() { | ||
equal(Normalizer.normalizePath(path), normalized); | ||
}); | ||
}); | ||
}); |