diff --git a/Makefile b/Makefile index e6b279e..1e22fec 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/content/en/examples/assert.md b/content/en/examples/assert.md index 4e96ef3..7813222 100644 --- a/content/en/examples/assert.md +++ b/content/en/examples/assert.md @@ -5,6 +5,11 @@ draft: false --- To make sure our tests work, we use assert. + + + ```rust {.codebox} fn main(x: felt252, y: felt252) { assert(x != y, 'error, x is equal to y'); @@ -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. + +```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. diff --git a/content/en/examples/functions.md b/content/en/examples/functions.md index 6ca6f6b..d2a588b 100644 --- a/content/en/examples/functions.md +++ b/content/en/examples/functions.md @@ -4,14 +4,24 @@ weight: 40 draft: false --- + + A function is a unit of code that performs some logic. It is defined using the `fn` keyword. Examples of functions are: + ```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. @@ -20,6 +30,13 @@ fn inc(x: u32) -> u32 { } ``` + +```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 (`()`). diff --git a/content/en/examples/variables.md b/content/en/examples/variables.md index 76da4f3..9cfc5b7 100644 --- a/content/en/examples/variables.md +++ b/content/en/examples/variables.md @@ -4,10 +4,15 @@ weight: 30 draft: false --- + + 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 + ```rust {.codebox} fn main() { let immutable_var: felt252 = 17; @@ -25,3 +30,10 @@ fn test_main() { main(); } ``` + + +```bash +running 1 tests +test program::program::test_main ... ok +test result: ok. 1 passed; 0 failed; 0 ignored; 0 filtered out; +```