Skip to content

Commit

Permalink
validation and a test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthropohedron committed Apr 4, 2015
1 parent d1e92a1 commit 6b45897
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ function createPattern(pattern) {
}

function Matcher(patterns) {
if (!(patterns && patterns.length)) {
throw new Error("No patterns provided to Matcher");
}
this.patterns = patterns.map(createPattern);
}

Expand Down
11 changes: 10 additions & 1 deletion test/test-matcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var Matcher = require("./matcher").Matcher;

exports["test create path matcher"] = function(assert) {
exports["test create matcher"] = function(assert) {
var patterns = [
"TAG:^Content-Type: image/",
"NO-RESPONSE-TAG:^User-Agent: .*Internet",
Expand All @@ -15,4 +15,13 @@ exports["test create path matcher"] = function(assert) {
patterns.length, "Correct number of patterns");
};

exports["test create match no patterns"] = function(assert) {
assert.throws(function() {
new Matcher();
}, /no patterns/i, "No arguments to Matcher constructor");
assert.throws(function() {
new Matcher([]);
}, /no patterns/i, "Empty array passed to Matcher constructor");
}

require("sdk/test").run(exports);

0 comments on commit 6b45897

Please sign in to comment.