diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2018-08-10 10:38:32 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-08-10 11:50:45 -0700 |
commit | c4cafcecb1f50e38275b7d82852fd33b63964fb2 (patch) | |
tree | 421842c344d27873bcf3ce9f458a6f0c27a4315f /tools/util_test.py | |
parent | e28d7abc1c369185cc9d1deb4891c6004d9d7ad7 (diff) |
Support wildcard matching of output in tests
Diffstat (limited to 'tools/util_test.py')
-rw-r--r-- | tools/util_test.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tools/util_test.py b/tools/util_test.py new file mode 100644 index 000000000..3315a4eaf --- /dev/null +++ b/tools/util_test.py @@ -0,0 +1,31 @@ +# Copyright 2018 the Deno authors. All rights reserved. MIT license. +from util import pattern_match + + +def pattern_match_test(): + print "Testing util.pattern_match()..." + # yapf: disable + fixtures = [("foobarbaz", "foobarbaz", True), + ("[WILDCARD]", "foobarbaz", True), + ("foobar", "foobarbaz", False), + ("foo[WILDCARD]baz", "foobarbaz", True), + ("foo[WILDCARD]baz", "foobazbar", False), + ("foo[WILDCARD]baz[WILDCARD]qux", "foobarbazqatqux", True), + ("foo[WILDCARD]", "foobar", True), + ("foo[WILDCARD]baz[WILDCARD]", "foobarbazqat", True)] + # yapf: enable + + # Iterate through the fixture lists, testing each one + for (pattern, string, expected) in fixtures: + actual = pattern_match(pattern, string) + assert expected == actual, "expected %s for\nExpected:\n%s\nTo equal actual:\n%s" % ( + expected, pattern, string) + + assert pattern_match("foo[BAR]baz", "foobarbaz", + "[BAR]") == True, "expected wildcard to be set" + assert pattern_match("foo[BAR]baz", "foobazbar", + "[BAR]") == False, "expected wildcard to be set" + + +def util_test(): + pattern_match_test() |