From 5a64fbdf9f9cc632bb7f415460febf45a84140db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Est=C3=A9fano=20Bargas?= Date: Fri, 21 Jul 2023 11:38:59 -0300 Subject: [PATCH 1/4] Added en/assert test --- content/en/examples/assert.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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. From cf58eba717d704ff1c83ac5ca09cf3d9e19162f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Est=C3=A9fano=20Bargas?= Date: Fri, 21 Jul 2023 11:42:24 -0300 Subject: [PATCH 2/4] Added en/variables test --- content/en/examples/variables.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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; +``` From b368b752229757a36b94cec8f7c03a8e68e25952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Est=C3=A9fano=20Bargas?= Date: Fri, 21 Jul 2023 11:54:05 -0300 Subject: [PATCH 3/4] Added en/functions test --- content/en/examples/functions.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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 (`()`). From a0c737fc438bc3834f1646bea2f9af0617dcc5e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Est=C3=A9fano=20Bargas?= Date: Mon, 24 Jul 2023 10:47:44 -0300 Subject: [PATCH 4/4] Update makefile --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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)