Skip to content

Commit

Permalink
Tests for md generation
Browse files Browse the repository at this point in the history
commit-id:3a7ce9d5
  • Loading branch information
piotmag769 committed Jul 17, 2024
1 parent d25c193 commit ddde663
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions extensions/scarb-doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ smol_str.workspace = true
[dev-dependencies]
assert_fs.workspace = true
scarb-test-support = { path = "../../utils/scarb-test-support" }
walkdir.workspace = true
16 changes: 16 additions & 0 deletions extensions/scarb-doc/tests/data/hello_world/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[book]
authors = ["<unknown>"]
language = "en"
multilingual = false
src = "src"
title = "hello_world - Cairo"

[output.html]
no-section-label = true

[output.html.playground]
runnable = false

[output.html.fold]
enable = true
level = 0
46 changes: 46 additions & 0 deletions extensions/scarb-doc/tests/data/hello_world/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Summary

# Modules

- [hello_world](./hello_world.md)

- [tests](./hello_world-tests.md)

# Constants

- [FOO](./hello_world-FOO.md)

# Free functions

- [main](./hello_world-main.md)

- [fib](./hello_world-fib.md)

- [it_works](./hello_world-tests-it_works.md)

# Structs

- [Circle](./hello_world-Circle.md)

# Enums

- [Color](./hello_world-Color.md)

# Type Aliases

- [Pair](./hello_world-Pair.md)

# Traits

- [Shape](./hello_world-Shape.md)

# Impls

- [CircleShape](./hello_world-CircleShape.md)

- [CircleDrop](./hello_world-CircleDrop.md)

- [CircleSerde](./hello_world-CircleSerde.md)

- [CirclePartialEq](./hello_world-CirclePartialEq.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Circle

Circle struct with radius field


Fully qualified path: `hello_world::Circle`

## Members

### radius

Radius of the circle

Fully qualified path: `hello_world::Circle::radius`


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CircleDrop

Fully qualified path: `hello_world::CircleDrop`

```rust
impl CircleDrop of core::traits::Drop<Circle>;
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CirclePartialEq

Fully qualified path: `hello_world::CirclePartialEq`

```rust
impl CirclePartialEq of core::traits::PartialEq<Circle>
```

## Impl Functions

### eq

Fully qualified path: `hello_world::CirclePartialEq::eq`

```rust
fn eq(lhs: @Circle, rhs: @Circle) -> bool
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# CircleSerde

Fully qualified path: `hello_world::CircleSerde`

```rust
impl CircleSerde of core::serde::Serde<Circle>
```

## Impl Functions

### serialize

Fully qualified path: `hello_world::CircleSerde::serialize`

```rust
fn serialize(self: @Circle, ref output: core::array::Array<felt252>)
```


### deserialize

Fully qualified path: `hello_world::CircleSerde::deserialize`

```rust
fn deserialize(ref serialized: core::array::Span<felt252>) -> core::option::Option<Circle>
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# CircleShape

Implementation of the Shape trait for Circle


Fully qualified path: `hello_world::CircleShape`

```rust
impl CircleShape of Shape<Circle>
```

## Impl Constants

### SHAPE_CONST

Shape constant


Fully qualified path: `hello_world::CircleShape::SHAPE_CONST`

```rust
const SHAPE_CONST: felt252 = 'xyz';
```


## Impl Functions

### area

Implementation of the area method for Circle


Fully qualified path: `hello_world::CircleShape::area`

```rust
fn area(self: Circle) -> u32
```


## Impl Types

### ShapePair

Type alias for a pair of circles


Fully qualified path: `hello_world::CircleShape::ShapePair`

```rust
type ShapePair = (Circle, Circle);
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Color

Color enum with Red, Green, and Blue variants


Fully qualified path: `hello_world::Color`

## Variants

### Red

Red color

Fully qualified path: `hello_world::Color::Red`


### Green

Green color

Fully qualified path: `hello_world::Color::Green`


### Blue

Blue color

Fully qualified path: `hello_world::Color::Blue`


11 changes: 11 additions & 0 deletions extensions/scarb-doc/tests/data/hello_world/src/hello_world-FOO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# FOO

FOO constant with value 42


Fully qualified path: `hello_world::FOO`

```rust
const FOO: u32 = 42;
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Pair

Pair type alias for a tuple of two u32 values


Fully qualified path: `hello_world::Pair`

```rust
type Pair = (u32, u32);
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Shape

Shape trait for objects that have an area


Fully qualified path: `hello_world::Shape`

```rust
trait Shape<T>
```

## Trait Constants

### SHAPE_CONST

Constant for the shape type


Fully qualified path: `hello_world::Shape::SHAPE_CONST`


## Trait Functions

### area

Calculate the area of the shape


Fully qualified path: `Shape::area`

```rust
fn area(self: T) -> u32
```


## Trait Types

### ShapePair

Type alias for a pair of shapes


Fully qualified path: `hello_world::Shape::ShapePair`


14 changes: 14 additions & 0 deletions extensions/scarb-doc/tests/data/hello_world/src/hello_world-fib.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# fib

Calculate the nth Fibonacci number

# Arguments
* `n` - The index of the Fibonacci number to calculate


Fully qualified path: `hello_world::fib`

```rust
fn fib(mut n: u32) -> u32
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# main

Fibonacci sequence calculator
Main function that calculates the 16th Fibonacci number


Fully qualified path: `hello_world::main`

```rust
fn main() -> u32
```

12 changes: 12 additions & 0 deletions extensions/scarb-doc/tests/data/hello_world/src/hello_world.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# it_works

Really
works.


Fully qualified path: `hello_world::tests::it_works`

```rust
fn it_works()
```

36 changes: 36 additions & 0 deletions extensions/scarb-doc/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ use assert_fs::TempDir;
use expect_test::expect_file;
use indoc::indoc;
use std::fs;
use std::iter::zip;
use walkdir::WalkDir;

use scarb_test_support::command::Scarb;
use scarb_test_support::fsx;
use scarb_test_support::project_builder::ProjectBuilder;

const CODE: &str = indoc! {
Expand Down Expand Up @@ -123,3 +126,36 @@ fn json_output() {
let expected = expect_file!["./data/json_output_test_data.json"];
expected.assert_eq(&serialized_crates);
}

#[test]
fn markdown_output() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("hello_world")
.lib_cairo(CODE)
.build(&t);

Scarb::quick_snapbox()
.arg("doc")
.args(["--output-format", "markdown"])
.current_dir(&t)
.assert()
.success();

for (dir_entry_1, dir_entry_2) in zip(
WalkDir::new("tests/data/hello_world").sort_by_file_name(),
WalkDir::new(t.path().join("target/doc/hello_world")).sort_by_file_name(),
) {
let dir_entry_1 = dir_entry_1.unwrap();
let dir_entry_2 = dir_entry_2.unwrap();

if dir_entry_1.file_type().is_file() {
assert!(dir_entry_2.file_type().is_file());

let content = fs::read_to_string(dir_entry_2.path()).unwrap();

let expect_file = expect_file![fsx::canonicalize(dir_entry_1.path()).unwrap()];
expect_file.assert_eq(&content);
}
}
}

0 comments on commit ddde663

Please sign in to comment.