Skip to content

Commit

Permalink
fix match to accept boolean values as pattern
Browse files Browse the repository at this point in the history
PR meteor#4107

[stubailo: merged two commits]
  • Loading branch information
István Rábel authored and Sashko Stubailo committed Apr 2, 2015
1 parent e0e30c3 commit 7ed59d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/check/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ var checkSubtree = function (value, pattern) {
throw new Match.Error("Expected null, got " + EJSON.stringify(value));
}

// Strings and numbers match literally. Goes well with Match.OneOf.
if (typeof pattern === "string" || typeof pattern === "number") {
// Strings, numbers, and booleans match literally. Goes well with Match.OneOf.
if (typeof pattern === "string" || typeof pattern === "number" || typeof pattern === "boolean") {
if (value === pattern)
return;
throw new Match.Error("Expected " + pattern + ", got " +
Expand Down
5 changes: 5 additions & 0 deletions packages/check/match_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ Tinytest.add("check - check", function (test) {
fails(123, 456);
fails("123", 123);
fails(123, "123");
matches(true, true);
matches(false, false);
fails(true, false);
fails(true, "true");
fails("false", false);

matches(/foo/, RegExp);
fails(/foo/, String);
Expand Down

0 comments on commit 7ed59d8

Please sign in to comment.