Debian Codegraph @

clang/tools/include-mapping/test.py

raw
1 #!/usr/bin/env python
2 # ===- test.py - ---------------------------------------------*- python -*--===#
3 #
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 #
8 # ===------------------------------------------------------------------------===#
9
10 from cppreference_parser import _ParseSymbolPage, _ParseIndexPage
11
12 import unittest
13
14
15 class TestStdGen(unittest.TestCase):
16 def testParseIndexPage(self):
17 html = """
18 <a href="abs.html" title="abs"><tt>abs()</tt></a> (int) <br>
19 <a href="complex/abs.html" title="abs"><tt>abs&lt;&gt;()</tt></a> (std::complex) <br>
20 <a href="acos.html" title="acos"><tt>acos()</tt></a> <br>
21 <a href="acosh.html" title="acosh"><tt>acosh()</tt></a> <span class="t-mark-rev">(since C++11)</span> <br>
22 <a href="as_bytes.html" title="as bytes"><tt>as_bytes&lt;&gt;()</tt></a> <span class="t-mark-rev t-since-cxx20">(since C++20)</span> <br>
23 """
24
25 actual = _ParseIndexPage(html)
26 expected = [
27 ("abs", "abs.html", "int"),
28 ("abs", "complex/abs.html", "std::complex"),
29 ("acos", "acos.html", None),
30 ("acosh", "acosh.html", None),
31 ("as_bytes", "as_bytes.html", None),
32 ]
33 self.assertEqual(len(actual), len(expected))
34 for i in range(0, len(actual)):
35 self.assertEqual(expected[i][0], actual[i][0])
36 self.assertTrue(actual[i][1].endswith(expected[i][1]))
37 self.assertEqual(expected[i][2], actual[i][2])
38
39 def testParseSymbolPage_SingleHeader(self):
40 # Defined in header <cmath>
41 html = """
42 <table class="t-dcl-begin"><tbody>
43 <tr class="t-dsc-header">
44 <td> <div>Defined in header <code><a href="cmath.html" title="cmath">&lt;cmath&gt;</a></code>
45 </div></td>
46 <td></td>
47 <td></td>
48 </tr>
49 <tr class="t-dcl">
50 <td>void foo()</td>
51 <td>this is matched</td>
52 </tr>
53 </tbody></table>
54 """
55 self.assertEqual(_ParseSymbolPage(html, "foo", "foo"), set(["<cmath>"]))
56
57 def testParseSymbolPage_MulHeaders(self):
58 # Defined in header <cstddef>
59 # Defined in header <cstdio>
60 # Defined in header <cstdlib>
61 html = """
62 <table class="t-dcl-begin"><tbody>
63 <tr class="t-dsc-header">
64 <td> <div>Defined in header <code><a href="cstddef.html" title="cstddef">&lt;cstddef&gt;</a></code>
65 </div></td>
66 <td></td>
67 <td></td>
68 </tr>
69 <tr class="t-dcl">
70 <td>void bar()</td>
71 <td>this mentions foo, but isn't matched</td>
72 </tr>
73 <tr class="t-dsc-header">
74 <td> <div>Defined in header <code><a href="cstdio.html" title="cstdio">&lt;cstdio&gt;</a></code>
75 </div></td>
76 <td></td>
77 <td></td>
78 </tr>
79 <tr class="t-dsc-header">
80 <td> <div>Defined in header <code><a href=".cstdlib.html" title="ccstdlib">&lt;cstdlib&gt;</a></code>
81 </div></td>
82 <td></td>
83 <td></td>
84 </tr>
85 <tr class="t-dcl">
86 <td>
87 <span>void</span>
88 foo
89 <span>()</span>
90 </td>
91 <td>this is matched</td>
92 </tr>
93 </tbody></table>
94 """
95 self.assertEqual(
96 _ParseSymbolPage(html, "foo", "foo"), set(["<cstdio>", "<cstdlib>"])
97 )
98
99 def testParseSymbolPage_MulHeadersInSameDiv(self):
100 # Multile <code> blocks in a Div.
101 # Defined in header <algorithm>
102 # Defined in header <utility>
103 html = """
104 <table class="t-dcl-begin"><tbody>
105 <tr class="t-dsc-header">
106 <td><div>
107 Defined in header <code><a href="../header/algorithm.html" title="cpp/header/algorithm">&lt;algorithm&gt;</a></code><br>
108 Defined in header <code><a href="../header/utility.html" title="cpp/header/utility">&lt;utility&gt;</a></code>
109 </div></td>
110 <td></td>
111 </tr>
112 <tr class="t-dcl">
113 <td>
114 <span>void</span>
115 foo
116 <span>()</span>
117 </td>
118 <td>this is matched</td>
119 </tr>
120 </tbody></table>
121 """
122 self.assertEqual(
123 _ParseSymbolPage(html, "foo", "foo"), set(["<algorithm>", "<utility>"])
124 )
125
126 def testParseSymbolPage_MulSymbolsInSameTd(self):
127 # defined in header <cstdint>
128 # int8_t
129 # int16_t
130 html = """
131 <table class="t-dcl-begin"><tbody>
132 <tr class="t-dsc-header">
133 <td><div>
134 Defined in header <code><a href="cstdint.html" title="cstdint">&lt;cstdint&gt;</a></code><br>
135 </div></td>
136 <td></td>
137 </tr>
138 <tr class="t-dcl">
139 <td>
140 <span>int8_t</span>
141 <span>int16_t</span>
142 </td>
143 <td>this is matched</td>
144 </tr>
145 </tbody></table>
146 """
147 self.assertEqual(_ParseSymbolPage(html, "int8_t", "int8_t"), set(["<cstdint>"]))
148 self.assertEqual(
149 _ParseSymbolPage(html, "int16_t", "int16_t"), set(["<cstdint>"])
150 )
151
152
153 if __name__ == "__main__":
154 unittest.main()