1 | ## @file
|
---|
2 | # Routines for generating Pcd Database
|
---|
3 | #
|
---|
4 | # Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 | # SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | import unittest
|
---|
8 | from Common.Misc import RemoveCComments
|
---|
9 | from Workspace.BuildClassObject import ArrayIndex
|
---|
10 |
|
---|
11 | class TestRe(unittest.TestCase):
|
---|
12 | def test_ccomments(self):
|
---|
13 | TestStr1 = """ {0x01,0x02} """
|
---|
14 | self.assertEquals(TestStr1, RemoveCComments(TestStr1))
|
---|
15 |
|
---|
16 | TestStr2 = """ L'TestString' """
|
---|
17 | self.assertEquals(TestStr2, RemoveCComments(TestStr2))
|
---|
18 |
|
---|
19 | TestStr3 = """ 'TestString' """
|
---|
20 | self.assertEquals(TestStr3, RemoveCComments(TestStr3))
|
---|
21 |
|
---|
22 | TestStr4 = """
|
---|
23 | {CODE({
|
---|
24 | {0x01, {0x02, 0x03, 0x04 }},// Data comment
|
---|
25 | {0x01, {0x02, 0x03, 0x04 }},// Data comment
|
---|
26 | })
|
---|
27 | } /*
|
---|
28 | This is multiple line comments
|
---|
29 | The seconde line comment
|
---|
30 | */
|
---|
31 | // This is a comment
|
---|
32 | """
|
---|
33 | Expect_TestStr4 = """{CODE({
|
---|
34 | {0x01, {0x02, 0x03, 0x04 }},
|
---|
35 | {0x01, {0x02, 0x03, 0x04 }},
|
---|
36 | })
|
---|
37 | }"""
|
---|
38 | self.assertEquals(Expect_TestStr4, RemoveCComments(TestStr4).strip())
|
---|
39 |
|
---|
40 | def Test_ArrayIndex(self):
|
---|
41 | TestStr1 = """[1]"""
|
---|
42 | self.assertEquals(['[1]'], ArrayIndex.findall(TestStr1))
|
---|
43 |
|
---|
44 | TestStr2 = """[1][2][0x1][0x01][]"""
|
---|
45 | self.assertEquals(['[1]','[2]','[0x1]','[0x01]','[]'], ArrayIndex.findall(TestStr2))
|
---|
46 |
|
---|
47 | if __name__ == '__main__':
|
---|
48 | unittest.main()
|
---|