bisect-kit: argtype_intra_rev should accept major version number as well

local build bisectors 'switch' command should accept not only intra
versions but also major versions.

This CL also add unittests for codechange module.

BUG=None
TEST=unittest

Change-Id: I93c24fe047e3fd554a038b9502ac1785b8c37dee
Reviewed-on: https://chromium-review.googlesource.com/1423941
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/codechange_test.py b/bisect_kit/codechange_test.py
new file mode 100644
index 0000000..25cd96b
--- /dev/null
+++ b/bisect_kit/codechange_test.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Test codechange module."""
+
+from __future__ import print_function
+import unittest
+
+from bisect_kit import cli
+from bisect_kit import codechange
+
+
+class TestCodeChange(unittest.TestCase):
+  """Test functions in codechange module."""
+
+  def test_parse_intra_rev(self):
+    rev = codechange.make_intra_rev('abc', 'def', 123)
+    self.assertEqual(codechange.parse_intra_rev(rev), ('abc', 'def', 123))
+
+    self.assertEqual(codechange.parse_intra_rev('foo'), ('foo', 'foo', 0))
+
+  def test_argtype_intra_rev(self):
+    arg_type = codechange.argtype_intra_rev(cli.argtype_re(r'^[a-f]$', 'a'))
+    self.assertEqual(arg_type('a'), 'a')
+    self.assertEqual(arg_type('a~b/10'), 'a~b/10')
+
+    with self.assertRaises(cli.ArgTypeError):
+      arg_type('a~b/c')
+
+    with self.assertRaises(cli.ArgTypeError):
+      arg_type('a~g/10')
+
+
+if __name__ == '__main__':
+  unittest.main()