Skip to content

Commit 030522a

Browse files
authored
Tests for md generation (#1464)
commit-id:3a7ce9d5
1 parent 4023a26 commit 030522a

17 files changed

+359
-0
lines changed

Diff for: Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: extensions/scarb-doc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ smol_str.workspace = true
3434
[dev-dependencies]
3535
assert_fs.workspace = true
3636
scarb-test-support = { path = "../../utils/scarb-test-support" }
37+
walkdir.workspace = true
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[book]
2+
authors = ["<unknown>"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "hello_world - Cairo"
7+
8+
[output.html]
9+
no-section-label = true
10+
11+
[output.html.playground]
12+
runnable = false
13+
14+
[output.html.fold]
15+
enable = true
16+
level = 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Summary
2+
3+
# Modules
4+
5+
- [hello_world](./hello_world.md)
6+
7+
- [tests](./hello_world-tests.md)
8+
9+
# Constants
10+
11+
- [FOO](./hello_world-FOO.md)
12+
13+
# Free functions
14+
15+
- [main](./hello_world-main.md)
16+
17+
- [fib](./hello_world-fib.md)
18+
19+
- [it_works](./hello_world-tests-it_works.md)
20+
21+
# Structs
22+
23+
- [Circle](./hello_world-Circle.md)
24+
25+
# Enums
26+
27+
- [Color](./hello_world-Color.md)
28+
29+
# Type Aliases
30+
31+
- [Pair](./hello_world-Pair.md)
32+
33+
# Traits
34+
35+
- [Shape](./hello_world-Shape.md)
36+
37+
# Impls
38+
39+
- [CircleShape](./hello_world-CircleShape.md)
40+
41+
- [CircleDrop](./hello_world-CircleDrop.md)
42+
43+
- [CircleSerde](./hello_world-CircleSerde.md)
44+
45+
- [CirclePartialEq](./hello_world-CirclePartialEq.md)
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Circle
2+
3+
Circle struct with radius field
4+
5+
6+
Fully qualified path: `hello_world::Circle`
7+
8+
## Members
9+
10+
### radius
11+
12+
Radius of the circle
13+
14+
Fully qualified path: `hello_world::Circle::radius`
15+
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CircleDrop
2+
3+
Fully qualified path: `hello_world::CircleDrop`
4+
5+
```rust
6+
impl CircleDrop of core::traits::Drop<Circle>;
7+
```
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# CirclePartialEq
2+
3+
Fully qualified path: `hello_world::CirclePartialEq`
4+
5+
```rust
6+
impl CirclePartialEq of core::traits::PartialEq<Circle>
7+
```
8+
9+
## Impl Functions
10+
11+
### eq
12+
13+
Fully qualified path: `hello_world::CirclePartialEq::eq`
14+
15+
```rust
16+
fn eq(lhs: @Circle, rhs: @Circle) -> bool
17+
```
18+
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# CircleSerde
2+
3+
Fully qualified path: `hello_world::CircleSerde`
4+
5+
```rust
6+
impl CircleSerde of core::serde::Serde<Circle>
7+
```
8+
9+
## Impl Functions
10+
11+
### serialize
12+
13+
Fully qualified path: `hello_world::CircleSerde::serialize`
14+
15+
```rust
16+
fn serialize(self: @Circle, ref output: core::array::Array<felt252>)
17+
```
18+
19+
20+
### deserialize
21+
22+
Fully qualified path: `hello_world::CircleSerde::deserialize`
23+
24+
```rust
25+
fn deserialize(ref serialized: core::array::Span<felt252>) -> core::option::Option<Circle>
26+
```
27+
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# CircleShape
2+
3+
Implementation of the Shape trait for Circle
4+
5+
6+
Fully qualified path: `hello_world::CircleShape`
7+
8+
```rust
9+
impl CircleShape of Shape<Circle>
10+
```
11+
12+
## Impl Constants
13+
14+
### SHAPE_CONST
15+
16+
Shape constant
17+
18+
19+
Fully qualified path: `hello_world::CircleShape::SHAPE_CONST`
20+
21+
```rust
22+
const SHAPE_CONST: felt252 = 'xyz';
23+
```
24+
25+
26+
## Impl Functions
27+
28+
### area
29+
30+
Implementation of the area method for Circle
31+
32+
33+
Fully qualified path: `hello_world::CircleShape::area`
34+
35+
```rust
36+
fn area(self: Circle) -> u32
37+
```
38+
39+
40+
## Impl Types
41+
42+
### ShapePair
43+
44+
Type alias for a pair of circles
45+
46+
47+
Fully qualified path: `hello_world::CircleShape::ShapePair`
48+
49+
```rust
50+
type ShapePair = (Circle, Circle);
51+
```
52+
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Color
2+
3+
Color enum with Red, Green, and Blue variants
4+
5+
6+
Fully qualified path: `hello_world::Color`
7+
8+
## Variants
9+
10+
### Red
11+
12+
Red color
13+
14+
Fully qualified path: `hello_world::Color::Red`
15+
16+
17+
### Green
18+
19+
Green color
20+
21+
Fully qualified path: `hello_world::Color::Green`
22+
23+
24+
### Blue
25+
26+
Blue color
27+
28+
Fully qualified path: `hello_world::Color::Blue`
29+
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# FOO
2+
3+
FOO constant with value 42
4+
5+
6+
Fully qualified path: `hello_world::FOO`
7+
8+
```rust
9+
const FOO: u32 = 42;
10+
```
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Pair
2+
3+
Pair type alias for a tuple of two u32 values
4+
5+
6+
Fully qualified path: `hello_world::Pair`
7+
8+
```rust
9+
type Pair = (u32, u32);
10+
```
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Shape
2+
3+
Shape trait for objects that have an area
4+
5+
6+
Fully qualified path: `hello_world::Shape`
7+
8+
```rust
9+
trait Shape<T>
10+
```
11+
12+
## Trait Constants
13+
14+
### SHAPE_CONST
15+
16+
Constant for the shape type
17+
18+
19+
Fully qualified path: `hello_world::Shape::SHAPE_CONST`
20+
21+
22+
## Trait Functions
23+
24+
### area
25+
26+
Calculate the area of the shape
27+
28+
29+
Fully qualified path: `Shape::area`
30+
31+
```rust
32+
fn area(self: T) -> u32
33+
```
34+
35+
36+
## Trait Types
37+
38+
### ShapePair
39+
40+
Type alias for a pair of shapes
41+
42+
43+
Fully qualified path: `hello_world::Shape::ShapePair`
44+
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# fib
2+
3+
Calculate the nth Fibonacci number
4+
5+
# Arguments
6+
* `n` - The index of the Fibonacci number to calculate
7+
8+
9+
Fully qualified path: `hello_world::fib`
10+
11+
```rust
12+
fn fib(mut n: u32) -> u32
13+
```
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# main
2+
3+
Fibonacci sequence calculator
4+
Main function that calculates the 16th Fibonacci number
5+
6+
7+
Fully qualified path: `hello_world::main`
8+
9+
```rust
10+
fn main() -> u32
11+
```
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# it_works
2+
3+
Really
4+
works.
5+
6+
7+
Fully qualified path: `hello_world::tests::it_works`
8+
9+
```rust
10+
fn it_works()
11+
```
12+

Diff for: extensions/scarb-doc/tests/test.rs

+36
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ use assert_fs::TempDir;
44
use expect_test::expect_file;
55
use indoc::indoc;
66
use std::fs;
7+
use std::iter::zip;
8+
use walkdir::WalkDir;
79

810
use scarb_test_support::command::Scarb;
11+
use scarb_test_support::fsx;
912
use scarb_test_support::project_builder::ProjectBuilder;
1013

1114
const CODE: &str = indoc! {
@@ -123,3 +126,36 @@ fn json_output() {
123126
let expected = expect_file!["./data/json_output_test_data.json"];
124127
expected.assert_eq(&serialized_crates);
125128
}
129+
130+
#[test]
131+
fn markdown_output() {
132+
let t = TempDir::new().unwrap();
133+
ProjectBuilder::start()
134+
.name("hello_world")
135+
.lib_cairo(CODE)
136+
.build(&t);
137+
138+
Scarb::quick_snapbox()
139+
.arg("doc")
140+
.args(["--output-format", "markdown"])
141+
.current_dir(&t)
142+
.assert()
143+
.success();
144+
145+
for (dir_entry_1, dir_entry_2) in zip(
146+
WalkDir::new("tests/data/hello_world").sort_by_file_name(),
147+
WalkDir::new(t.path().join("target/doc/hello_world")).sort_by_file_name(),
148+
) {
149+
let dir_entry_1 = dir_entry_1.unwrap();
150+
let dir_entry_2 = dir_entry_2.unwrap();
151+
152+
if dir_entry_1.file_type().is_file() {
153+
assert!(dir_entry_2.file_type().is_file());
154+
155+
let content = fs::read_to_string(dir_entry_2.path()).unwrap();
156+
157+
let expect_file = expect_file![fsx::canonicalize(dir_entry_1.path()).unwrap()];
158+
expect_file.assert_eq(&content);
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)