Kuang-che Wu | cab9245 | 2019-01-19 18:24:29 +0800 | [diff] [blame^] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | """Test codechange module.""" |
| 6 | |
| 7 | from __future__ import print_function |
| 8 | import unittest |
| 9 | |
| 10 | from bisect_kit import cli |
| 11 | from bisect_kit import codechange |
| 12 | |
| 13 | |
| 14 | class TestCodeChange(unittest.TestCase): |
| 15 | """Test functions in codechange module.""" |
| 16 | |
| 17 | def test_parse_intra_rev(self): |
| 18 | rev = codechange.make_intra_rev('abc', 'def', 123) |
| 19 | self.assertEqual(codechange.parse_intra_rev(rev), ('abc', 'def', 123)) |
| 20 | |
| 21 | self.assertEqual(codechange.parse_intra_rev('foo'), ('foo', 'foo', 0)) |
| 22 | |
| 23 | def test_argtype_intra_rev(self): |
| 24 | arg_type = codechange.argtype_intra_rev(cli.argtype_re(r'^[a-f]$', 'a')) |
| 25 | self.assertEqual(arg_type('a'), 'a') |
| 26 | self.assertEqual(arg_type('a~b/10'), 'a~b/10') |
| 27 | |
| 28 | with self.assertRaises(cli.ArgTypeError): |
| 29 | arg_type('a~b/c') |
| 30 | |
| 31 | with self.assertRaises(cli.ArgTypeError): |
| 32 | arg_type('a~g/10') |
| 33 | |
| 34 | |
| 35 | if __name__ == '__main__': |
| 36 | unittest.main() |