]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Tests/TestRegularExpression.py
BaseTools: Fix PcdArray issue
[mirror_edk2.git] / BaseTools / Tests / TestRegularExpression.py
1 ## @file
2 # Routines for generating Pcd Database
3 #
4 # Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 import unittest
14 from Common.Misc import RemoveCComments
15 from Workspace.BuildClassObject import ArrayIndex
16
17 class TestRe(unittest.TestCase):
18 def test_ccomments(self):
19 TestStr1 = """ {0x01,0x02} """
20 self.assertEquals(TestStr1, RemoveCComments(TestStr1))
21
22 TestStr2 = """ L'TestString' """
23 self.assertEquals(TestStr2, RemoveCComments(TestStr2))
24
25 TestStr3 = """ 'TestString' """
26 self.assertEquals(TestStr3, RemoveCComments(TestStr3))
27
28 TestStr4 = """
29 {CODE({
30 {0x01, {0x02, 0x03, 0x04 }},// Data comment
31 {0x01, {0x02, 0x03, 0x04 }},// Data comment
32 })
33 } /*
34 This is multiple line comments
35 The seconde line comment
36 */
37 // This is a comment
38 """
39 Expect_TestStr4 = """{CODE({
40 {0x01, {0x02, 0x03, 0x04 }},
41 {0x01, {0x02, 0x03, 0x04 }},
42 })
43 }"""
44 self.assertEquals(Expect_TestStr4, RemoveCComments(TestStr4).strip())
45
46 def Test_ArrayIndex(self):
47 TestStr1 = """[1]"""
48 self.assertEquals(['[1]'], ArrayIndex.findall(TestStr1))
49
50 TestStr2 = """[1][2][0x1][0x01][]"""
51 self.assertEquals(['[1]','[2]','[0x1]','[0x01]','[]'], ArrayIndex.findall(TestStr2))
52
53 if __name__ == '__main__':
54 unittest.main()