bisect-kit: refactor cli.argtype_multiplexer
extract regex matching as separate type, argtype_re
BUG=None
TEST=unittest
Change-Id: Ic5783ededa94f52274360a04233794ac41edd593
Reviewed-on: https://chromium-review.googlesource.com/1421577
Commit-Ready: Kuang-che Wu <kcwu@chromium.org>
Tested-by: Kuang-che Wu <kcwu@chromium.org>
Reviewed-by: Chung-yih Wang <cywang@chromium.org>
diff --git a/bisect_kit/cli_test.py b/bisect_kit/cli_test.py
index 54d15ce..1f630a4 100644
--- a/bisect_kit/cli_test.py
+++ b/bisect_kit/cli_test.py
@@ -34,8 +34,17 @@
with self.assertRaises(cli.ArgTypeError):
cli.argtype_notempty('')
+ def test_argtype_re(self):
+ argtype = cli.argtype_re(r'^r\d+$', 'r123')
+ self.assertEqual(argtype('r123'), 'r123')
+
+ with self.assertRaises(cli.ArgTypeError):
+ argtype('hello')
+
def test_argtype_multiplexer(self):
- argtype = cli.argtype_multiplexer(cli.argtype_int, 'foobar', r'^r\d+$')
+ argtype = cli.argtype_multiplexer(cli.argtype_int,
+ cli.argtype_re('foobar', 'foobar'),
+ cli.argtype_re(r'^r\d+$', 'r123'))
self.assertEqual(argtype('123456'), '123456')
self.assertEqual(argtype('foobar'), 'foobar')
self.assertEqual(argtype('r123'), 'r123')