2 # ===- test.py - ---------------------------------------------*- python -*--===#
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
8 # ===------------------------------------------------------------------------===#
10 from cppreference_parser
import _ParseSymbolPage
, _ParseIndexPage
15 class TestStdGen(unittest
.TestCase
):
16 def testParseIndexPage(self
):
18 <a href="abs.html" title="abs"><tt>abs()</tt></a> (int) <br>
19 <a href="complex/abs.html" title="abs"><tt>abs<>()</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<>()</tt></a> <span class="t-mark-rev t-since-cxx20">(since C++20)</span> <br>
25 actual
= _ParseIndexPage(html
)
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),
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])
39 def testParseSymbolPage_SingleHeader(self
):
40 # Defined in header <cmath>
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"><cmath></a></code>
51 <td>this is matched</td>
55 self
.assertEqual(_ParseSymbolPage(html
, "foo"), set(["<cmath>"]))
57 def testParseSymbolPage_MulHeaders(self
):
58 # Defined in header <cstddef>
59 # Defined in header <cstdio>
60 # Defined in header <cstdlib>
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"><cstddef></a></code>
71 <td>this mentions foo, but isn't matched</td>
73 <tr class="t-dsc-header">
74 <td> <div>Defined in header <code><a href="cstdio.html" title="cstdio"><cstdio></a></code>
79 <tr class="t-dsc-header">
80 <td> <div>Defined in header <code><a href=".cstdlib.html" title="ccstdlib"><cstdlib></a></code>
91 <td>this is matched</td>
95 self
.assertEqual(_ParseSymbolPage(html
, "foo"), set(["<cstdio>", "<cstdlib>"]))
97 def testParseSymbolPage_MulHeadersInSameDiv(self
):
98 # Multile <code> blocks in a Div.
99 # Defined in header <algorithm>
100 # Defined in header <utility>
102 <table class="t-dcl-begin"><tbody>
103 <tr class="t-dsc-header">
105 Defined in header <code><a href="../header/algorithm.html" title="cpp/header/algorithm"><algorithm></a></code><br>
106 Defined in header <code><a href="../header/utility.html" title="cpp/header/utility"><utility></a></code>
116 <td>this is matched</td>
121 _ParseSymbolPage(html
, "foo"), set(["<algorithm>", "<utility>"])
124 def testParseSymbolPage_MulSymbolsInSameTd(self
):
125 # defined in header <cstdint>
129 <table class="t-dcl-begin"><tbody>
130 <tr class="t-dsc-header">
132 Defined in header <code><a href="cstdint.html" title="cstdint"><cstdint></a></code><br>
141 <td>this is matched</td>
145 self
.assertEqual(_ParseSymbolPage(html
, "int8_t"), set(["<cstdint>"]))
146 self
.assertEqual(_ParseSymbolPage(html
, "int16_t"), set(["<cstdint>"]))
149 if __name__
== "__main__":