fix match to accept boolean values as pattern

PR #4107

[stubailo: merged two commits]
This commit is contained in:
István Rábel
2015-04-02 16:27:19 +02:00
committed by Sashko Stubailo
parent e0e30c3260
commit 7ed59d866c
2 changed files with 7 additions and 2 deletions

View File

@@ -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 " +

View File

@@ -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);