Skip to content

Commit b71123f

Browse files
authored
[clang-doc] Pre-commit tests for static members and functions (#135456)
Issue #59813 mentions that static members are not included in the documentation generated by clang-doc. This patch adds some basic testing for that property, with the current incorrect behavior. Follow up patches will address the missing documentation.
1 parent 761787d commit b71123f

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,25 @@ class Calculator {
4343
* @throw std::invalid_argument if b is zero.
4444
*/
4545
double divide(int a, int b);
46-
};
46+
47+
/**
48+
* @brief Performs the mod operation on integers.
49+
*
50+
* @param a First integer.
51+
* @param b Second integer.
52+
* @return The result of a % b.
53+
*/
54+
static int mod(int a, int b) {
55+
return a % b;
56+
}
57+
58+
/**
59+
* @brief A static value.
60+
*/
61+
static constexpr int static_val = 10;
62+
63+
/**
64+
* @brief Holds a public value.
65+
*/
66+
int public_val = -1;
67+
};

clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ int Calculator::multiply(int a, int b) {
1515
double Calculator::divide(int a, int b) {
1616
return static_cast<double>(a) / b;
1717
}
18+

clang-tools-extra/test/clang-doc/basic-project.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@
129129
// HTML-CALC: <div>brief</div>
130130
// HTML-CALC: <p> A simple calculator class.</p>
131131
// HTML-CALC: <p> Provides basic arithmetic operations.</p>
132+
133+
// HTML-CALC: <h2 id="Members">Members</h2>
134+
// HTML-CALC: <div>brief</div>
135+
// HTML-CALC: <p> Holds a public value.</p>
136+
// HTML-CALC: <div>public int public_val</div>
137+
132138
// HTML-CALC: <h2 id="Functions">Functions</h2>
133139
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">add</h3>
134140
// HTML-CALC: <p>public int add(int a, int b)</p>
@@ -185,6 +191,18 @@
185191
// HTML-CALC: <div>throw</div>
186192
// HTML-CALC: <p>if b is zero.</p>
187193

194+
// HTML-CALC: <p>public int mod(int a, int b)</p>
195+
// CALC-NO-REPOSITORY: Defined at line 54 of file .{{.}}include{{.}}Calculator.h
196+
// CALC-REPOSITORY: Defined at line
197+
// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./include/Calculator.h#54">54</a>
198+
// CALC-LINE-PREFIX: <a href="https://repository.com/./include/Calculator.h#L54">54</a>
199+
// CALC-REPOSITORY-NEXT: of file
200+
// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./include/Calculator.h">Calculator.h</a>
201+
// HTML-CALC: <div>brief</div>
202+
// HTML-CALC: <p> Performs the mod operation on integers.</p>
203+
// HTML-CALC: <div>return</div>
204+
// HTML-CALC: <p> The result of a % b.</p>
205+
188206
// HTML-RECTANGLE: <h1>class Rectangle</h1>
189207
// RECTANGLE-NO-REPOSITORY: <p>Defined at line 10 of file .{{.}}include{{.}}Rectangle.h</p>
190208
// RECTANGLE-REPOSITORY: <p>
@@ -306,6 +324,8 @@
306324
// MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#8*
307325
// MD-CALC: **brief** A simple calculator class.
308326
// MD-CALC: Provides basic arithmetic operations.
327+
// MD-CALC: ## Members
328+
// MD-CALC: public int public_val
309329
// MD-CALC: ## Functions
310330
// MD-CALC: ### add
311331
// MD-CALC: *public int add(int a, int b)*
@@ -336,6 +356,13 @@
336356
// MD-CALC: **b** Second integer.
337357
// MD-CALC: **return** double The result of a / b.
338358
// MD-CALC: **throw**if b is zero.
359+
// MD-CALC: ### mod
360+
// MD-CALC: *public int mod(int a, int b)*
361+
// MD-CALC: *Defined at ./include{{[\/]}}Calculator.h#54*
362+
// MD-CALC: **brief** Performs the mod operation on integers.
363+
// MD-CALC: **a** First integer.
364+
// MD-CALC: **b** Second integer.
365+
// MD-CALC: **return** The result of a % b.
339366

340367
// MD-CIRCLE: # class Circle
341368
// MD-CIRCLE: *Defined at .{{[\/]}}include{{[\/]}}Circle.h#10*

0 commit comments

Comments
 (0)