Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests #103

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.PHONY: build serve test

EN_DIR := content/en/examples
#EN_CONTENT := $(wildcard $(EN_DIR)/*.md) # Uncomment when all tests are implemented
EN_CONTENT := $(EN_DIR)/hello-world.md
EN_CONTENT := $(wildcard $(EN_DIR)/*.md)

ES_DIR := content/es/examples
ES_CONTENT := $(wildcard $(ES_DIR)/*.md)
Expand Down
12 changes: 12 additions & 0 deletions content/en/examples/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ draft: false
---
To make sure our tests work, we use assert.

<!-- !test program
cat > /tmp/program.cairo
cairo-test /tmp/program.cairo -->

<!-- !test in assert -->
```rust {.codebox}
fn main(x: felt252, y: felt252) {
assert(x != y, 'error, x is equal to y');
Expand All @@ -18,6 +23,13 @@ fn test_main() {

The first argument of assert is the condition we want to check, and the second is a message we will see on the console if the condition is false.

<!-- !test out assert -->
```bash
running 1 tests
test program::program::test_main ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 filtered out;
```

Run ```cairo-test file_name```

Try changing it so that the test fails.
21 changes: 19 additions & 2 deletions content/en/examples/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ weight: 40
draft: false
---

<!-- !test program
cat > /tmp/program.cairo
cairo-run /tmp/program.cairo -->

A function is a unit of code that performs some logic. It is defined using the `fn` keyword.

Examples of functions are:

<!-- !test in functions -->
```rust {.codebox}
// This functions doesn't return anything.
use debug::PrintTrait;

// This function doesn't return anything.
fn main() {
let x = 3;
let three = 3;
let four = inc(three);

four.print();
}

// This function returns an u32.
Expand All @@ -20,6 +30,13 @@ fn inc(x: u32) -> u32 {
}
```

<!-- !test out functions -->
```bash
[DEBUG]  (raw: 4)

Run completed successfully, returning []
```

The Cairo convention is to name functions using the 'snake_case' form. In the example above, the function name is `inc_n`.

Note that in Cairo, functions always return a value. When the function has no particular return value, it is common to return the unit type (`()`).
12 changes: 12 additions & 0 deletions content/en/examples/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ weight: 30
draft: false
---

<!-- !test program
cat > /tmp/program.cairo
cairo-test /tmp/program.cairo -->

To store data in variables with the let keyword but you will not be able to change the value of said variables.

if you need to change that data, it must be a mutable variable with let mut

<!-- !test in variables -->
```rust {.codebox}
fn main() {
let immutable_var: felt252 = 17;
Expand All @@ -25,3 +30,10 @@ fn test_main() {
main();
}
```

<!-- !test out variables -->
```bash
running 1 tests
test program::program::test_main ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 filtered out;
```