You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `test_example_program.leo` contains two tests to ensure that the function logic returns a correct output and fails when the output does not match the sum of the input values.
58
58
59
-
```Leo
59
+
```leo
60
60
@test
61
61
fn test_simple_addition() {
62
62
let result: u32 = example_program.aleo::simple_addition(2u32, 3u32);
@@ -66,7 +66,7 @@ fn test_simple_addition() {
66
66
67
67
The `@should_fail` annotation should be added after the `@test` annotation for tests that are expected to fail.
Developers can test that record and struct fields match their expected values. In `example_program.leo`, a record is minted by an entry function shown here:
81
81
82
-
```Leo
82
+
```leo
83
83
record Example {
84
84
owner: address,
85
85
x: field,
@@ -95,7 +95,7 @@ fn mint_record(x: field) -> Example {
95
95
96
96
The corresponding test in `test_example_program.leo` checks that the Record field contains the correct value:
97
97
98
-
```Leo
98
+
```leo
99
99
@test
100
100
fn test_record_maker() {
101
101
let r: example_program.aleo::Example = example_program.aleo::mint_record(0field);
Copy file name to clipboardExpand all lines: documentation/language/02_structure.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,7 +169,7 @@ The visibility qualifier may be specified as `constant`, `public`, or `private`.
169
169
170
170
Record data structures must always contain a component named `owner` of type `address`, as shown below. When passing a record as input to a program function, the `_nonce: group` and `_version: u8` components are also required but do not need to be declared in the Leo program. They are inserted automatically by the compiler.
Arrays only support constant accesses. The accessor expression must be a constant expression (known at compile-time).
178
181
179
182
```leo
180
183
// Access the field of a struct within an array
181
-
fn foo(a: [Bar; 8]) -> u8 {
184
+
fn foo(a: [Bar; 8]) -> [u8; 8] {
182
185
return a[0u8].data;
183
186
}
184
187
```
@@ -207,10 +210,10 @@ Leo supports tuples. Tuple types are declared as `(type1, type2, ...)` and canno
207
210
Tuples can contain primitive data types, structs, arrays, or nested tuples. Structs and records can also contain tuples.
208
211
209
212
```leo
210
-
// Initialize a boolean array of length 4
213
+
// Initialize a tuple of mixed types
211
214
let tup: (u8,u8,bool) = (1u8,1u8,true);
212
215
213
-
// Nested array
216
+
// Nested tuple
214
217
let nested: [[bool; 2]; 2] = [[true, false], [true, false]];
215
218
```
216
219
@@ -226,7 +229,7 @@ struct Bar {
226
229
data: (u8,u8),
227
230
}
228
231
229
-
// Tuple of structs
232
+
// Array of structs with tuple fields
230
233
let tup_of_structs: [Bar; 2] = [Bar { data: (1u8,1u8) }, Bar { data: (2u8,2u8) }];
231
234
```
232
235
@@ -293,7 +296,7 @@ Records contain component declarations `{visibility} {name}: {type},`. Names of
293
296
294
297
Record data structures must always contain a component named `owner` of type `address`, as shown below. When passing a record as input to a program function, the `_nonce: group` and `_version: u8` components are also required but do not need to be declared in the Leo program. They are inserted automatically by the compiler.
0 commit comments