summaryrefslogtreecommitdiffstats
path: root/BaseTools/Tests/TestRegularExpression.py
diff options
context:
space:
mode:
authorFeng, Bob C <bob.c.feng@intel.com>2018-12-15 00:15:21 +0800
committerBobCF <bob.c.feng@intel.com>2018-12-18 10:15:50 +0800
commit4c6e6f9f75a7b86d7760f5409a24b3c20759ccb9 (patch)
tree9cd4b8bdd536f7160ea2e78893994186eba8fe03 /BaseTools/Tests/TestRegularExpression.py
parent778c7640505aafa0bfde1b084ba870d361cacaef (diff)
downloadedk2-4c6e6f9f75a7b86d7760f5409a24b3c20759ccb9.tar.gz
edk2-4c6e6f9f75a7b86d7760f5409a24b3c20759ccb9.tar.bz2
edk2-4c6e6f9f75a7b86d7760f5409a24b3c20759ccb9.zip
BaseTools: Fix PcdArray issue
https://bugzilla.tianocore.org/show_bug.cgi?id=1390 1. support hex number for array index 2. support Non-Dynamic Pcd for array data type 3. support {} and {CODE()} for array data type 4. Change GetStructurePcdMaxSize to be a static function since it need to be called in another static function. And this function does not depend on it's class instance. 5. Add unittest for RemoveCComments function and ArrayIndex regular expression. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Philippe Mathieu-Daud? <philmd@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Tests/TestRegularExpression.py')
-rw-r--r--BaseTools/Tests/TestRegularExpression.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/BaseTools/Tests/TestRegularExpression.py b/BaseTools/Tests/TestRegularExpression.py
new file mode 100644
index 0000000000..07143d6a76
--- /dev/null
+++ b/BaseTools/Tests/TestRegularExpression.py
@@ -0,0 +1,54 @@
+## @file
+# Routines for generating Pcd Database
+#
+# Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+import unittest
+from Common.Misc import RemoveCComments
+from Workspace.BuildClassObject import ArrayIndex
+
+class TestRe(unittest.TestCase):
+ def test_ccomments(self):
+ TestStr1 = """ {0x01,0x02} """
+ self.assertEquals(TestStr1, RemoveCComments(TestStr1))
+
+ TestStr2 = """ L'TestString' """
+ self.assertEquals(TestStr2, RemoveCComments(TestStr2))
+
+ TestStr3 = """ 'TestString' """
+ self.assertEquals(TestStr3, RemoveCComments(TestStr3))
+
+ TestStr4 = """
+ {CODE({
+ {0x01, {0x02, 0x03, 0x04 }},// Data comment
+ {0x01, {0x02, 0x03, 0x04 }},// Data comment
+ })
+ } /*
+ This is multiple line comments
+ The seconde line comment
+ */
+ // This is a comment
+ """
+ Expect_TestStr4 = """{CODE({
+ {0x01, {0x02, 0x03, 0x04 }},
+ {0x01, {0x02, 0x03, 0x04 }},
+ })
+ }"""
+ self.assertEquals(Expect_TestStr4, RemoveCComments(TestStr4).strip())
+
+ def Test_ArrayIndex(self):
+ TestStr1 = """[1]"""
+ self.assertEquals(['[1]'], ArrayIndex.findall(TestStr1))
+
+ TestStr2 = """[1][2][0x1][0x01][]"""
+ self.assertEquals(['[1]','[2]','[0x1]','[0x01]','[]'], ArrayIndex.findall(TestStr2))
+
+if __name__ == '__main__':
+ unittest.main()