Skip to content

Commit 219df18

Browse files
committed
[clang-doc] add basic e2e test
1 parent 9871486 commit 219df18

File tree

11 files changed

+1626
-0
lines changed

11 files changed

+1626
-0
lines changed

clang-tools-extra/test/clang-doc/Inputs/clang-doc-default-stylesheet.css

Lines changed: 969 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "Calculator.h"
2+
#include <stdexcept>
3+
4+
int Calculator::add(int a, int b) {
5+
return a + b;
6+
}
7+
8+
int Calculator::subtract(int a, int b) {
9+
return a - b;
10+
}
11+
12+
int Calculator::multiply(int a, int b) {
13+
return a * b;
14+
}
15+
16+
double Calculator::divide(int a, int b) {
17+
if (b == 0) {
18+
throw std::invalid_argument("Division by zero");
19+
}
20+
return static_cast<double>(a) / b;
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
3+
/**
4+
* @brief A simple calculator class.
5+
*
6+
* Provides basic arithmetic operations.
7+
*/
8+
class Calculator {
9+
public:
10+
/**
11+
* @brief Adds two integers.
12+
*
13+
* @param a First integer.
14+
* @param b Second integer.
15+
* @return int The sum of a and b.
16+
*/
17+
int add(int a, int b);
18+
19+
/**
20+
* @brief Subtracts the second integer from the first.
21+
*
22+
* @param a First integer.
23+
* @param b Second integer.
24+
* @return int The result of a - b.
25+
*/
26+
int subtract(int a, int b);
27+
28+
/**
29+
* @brief Multiplies two integers.
30+
*
31+
* @param a First integer.
32+
* @param b Second integer.
33+
* @return int The product of a and b.
34+
*/
35+
int multiply(int a, int b);
36+
37+
/**
38+
* @brief Divides the first integer by the second.
39+
*
40+
* @param a First integer.
41+
* @param b Second integer.
42+
* @return double The result of a / b.
43+
* @throw std::invalid_argument if b is zero.
44+
*/
45+
double divide(int a, int b);
46+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "Circle.h"
2+
3+
Circle::Circle(double radius) : radius_(radius) {}
4+
5+
double Circle::area() const {
6+
return 3.141 * radius_ * radius_;
7+
}
8+
9+
double Circle::perimeter() const {
10+
return 3.141 * radius_;
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#include "Shape.h"
4+
5+
/**
6+
* @brief Circle class derived from Shape.
7+
*
8+
* Represents a circle with a given radius.
9+
*/
10+
class Circle : public Shape {
11+
public:
12+
/**
13+
* @brief Constructs a new Circle object.
14+
*
15+
* @param radius Radius of the circle.
16+
*/
17+
Circle(double radius);
18+
19+
/**
20+
* @brief Calculates the area of the circle.
21+
*
22+
* @return double The area of the circle.
23+
*/
24+
double area() const override;
25+
26+
/**
27+
* @brief Calculates the perimeter of the circle.
28+
*
29+
* @return double The perimeter of the circle.
30+
*/
31+
double perimeter() const override;
32+
33+
private:
34+
double radius_; ///< Radius of the circle.
35+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "Rectangle.h"
2+
3+
Rectangle::Rectangle(double width, double height)
4+
: width_(width), height_(height) {}
5+
6+
double Rectangle::area() const {
7+
return width_ * height_;
8+
}
9+
10+
double Rectangle::perimeter() const {
11+
return 2 * (width_ + height_);
12+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
3+
#include "Shape.h"
4+
5+
/**
6+
* @brief Rectangle class derived from Shape.
7+
*
8+
* Represents a rectangle with a given width and height.
9+
*/
10+
class Rectangle : public Shape {
11+
public:
12+
/**
13+
* @brief Constructs a new Rectangle object.
14+
*
15+
* @param width Width of the rectangle.
16+
* @param height Height of the rectangle.
17+
*/
18+
Rectangle(double width, double height);
19+
20+
/**
21+
* @brief Calculates the area of the rectangle.
22+
*
23+
* @return double The area of the rectangle.
24+
*/
25+
double area() const override;
26+
27+
/**
28+
* @brief Calculates the perimeter of the rectangle.
29+
*
30+
* @return double The perimeter of the rectangle.
31+
*/
32+
double perimeter() const override;
33+
34+
private:
35+
double width_; ///< Width of the rectangle.
36+
double height_; ///< Height of the rectangle.
37+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
/**
4+
* @brief Abstract base class for shapes.
5+
*
6+
* Provides a common interface for different types of shapes.
7+
*/
8+
class Shape {
9+
public:
10+
/**
11+
* @brief Virtual destructor.
12+
*/
13+
virtual ~Shape() {}
14+
15+
/**
16+
* @brief Calculates the area of the shape.
17+
*
18+
* @return double The area of the shape.
19+
*/
20+
virtual double area() const = 0;
21+
22+
/**
23+
* @brief Calculates the perimeter of the shape.
24+
*
25+
* @return double The perimeter of the shape.
26+
*/
27+
virtual double perimeter() const = 0;
28+
};
29+
30+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"directory": "$test_dir/build",
4+
"command": "clang++ -o Calculator.o -I../include $test_dir/src/Calculator.cpp",
5+
"file": "$test_dir/src/Calculator.cpp"
6+
},
7+
{
8+
"directory": "$test_dir/build",
9+
"command": "clang++ -o Circle.o -I../include $test_dir/src/Circle.cpp",
10+
"file": "$test_dir/src/Circle.cpp"
11+
},
12+
{
13+
"directory": "$test_dir/build",
14+
"command": "clang++ -o Rectangle.o -I../include $test_dir/src/Rectangle.cpp",
15+
"file": "$test_dir/src/Rectangle.cpp"
16+
}
17+
]
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Append using posix-style a file name or directory to Base
2+
function append(Base, New) {
3+
if (!New)
4+
return Base;
5+
if (Base)
6+
Base += "/";
7+
Base += New;
8+
return Base;
9+
}
10+
11+
// Get relative path to access FilePath from CurrentDirectory
12+
function computeRelativePath(FilePath, CurrentDirectory) {
13+
var Path = FilePath;
14+
while (Path) {
15+
if (CurrentDirectory == Path)
16+
return FilePath.substring(Path.length + 1);
17+
Path = Path.substring(0, Path.lastIndexOf("/"));
18+
}
19+
20+
var Dir = CurrentDirectory;
21+
var Result = "";
22+
while (Dir) {
23+
if (Dir == FilePath)
24+
break;
25+
Dir = Dir.substring(0, Dir.lastIndexOf("/"));
26+
Result = append(Result, "..")
27+
}
28+
Result = append(Result, FilePath.substring(Dir.length))
29+
return Result;
30+
}
31+
32+
function genLink(Ref, CurrentDirectory) {
33+
var Path = computeRelativePath(Ref.Path, CurrentDirectory);
34+
if (Ref.RefType == "namespace")
35+
Path = append(Path, "index.html");
36+
else
37+
Path = append(Path, Ref.Name + ".html")
38+
39+
ANode = document.createElement("a");
40+
ANode.setAttribute("href", Path);
41+
var TextNode = document.createTextNode(Ref.Name);
42+
ANode.appendChild(TextNode);
43+
return ANode;
44+
}
45+
46+
function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
47+
// Out will store the HTML elements that Index requires to be generated
48+
var Out = [];
49+
if (Index.Name) {
50+
var SpanNode = document.createElement("span");
51+
var TextNode = document.createTextNode(Index.Name);
52+
SpanNode.appendChild(genLink(Index, CurrentDirectory));
53+
Out.push(SpanNode);
54+
}
55+
if (Index.Children.length == 0)
56+
return Out;
57+
// Only the outermost list should use ol, the others should use ul
58+
var ListNodeName = IsOutermostList ? "ol" : "ul";
59+
var ListNode = document.createElement(ListNodeName);
60+
for (Child of Index.Children) {
61+
var LiNode = document.createElement("li");
62+
ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
63+
for (Node of ChildNodes)
64+
LiNode.appendChild(Node);
65+
ListNode.appendChild(LiNode);
66+
}
67+
Out.push(ListNode);
68+
return Out;
69+
}
70+
71+
function createIndex(Index) {
72+
// Get the DOM element where the index will be created
73+
var IndexDiv = document.getElementById("sidebar-left");
74+
// Get the relative path of this file
75+
CurrentDirectory = IndexDiv.getAttribute("path");
76+
var IndexNodes = genHTMLOfIndex(Index, CurrentDirectory, true);
77+
for (Node of IndexNodes)
78+
IndexDiv.appendChild(Node);
79+
}
80+
81+
// Runs after DOM loads
82+
document.addEventListener("DOMContentLoaded", function() {
83+
// JsonIndex is a variable from another file that contains the index
84+
// in JSON format
85+
var Index = JSON.parse(JsonIndex);
86+
createIndex(Index);
87+
});

0 commit comments

Comments
 (0)