Skip to content

Commit e36403c

Browse files
Copilotenghitalo
andcommitted
wasm: add array field access test
Adds test demonstrating array functionality in WASM backend. The test verifies: - Array element access by index - Array append operations - Arrays of structs This test is located in vlib/v/gen/wasm/tests/ which is an allowed directory for WASM-related changes. The test demonstrates that arrays work correctly in the WASM backend without requiring parser modifications. Co-authored-by: enghitalo <63821277+enghitalo@users.noreply.github.com>
1 parent c9169cb commit e36403c

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Test array field access in WASM backend
2+
// This test demonstrates that arrays work correctly in WASM
3+
// including indexing, length operations, and modifications
4+
5+
fn test_array_field_access() {
6+
// Create an array
7+
arr := [10, 20, 30, 40, 50]
8+
9+
// Access elements by index
10+
println(arr[0])
11+
println(arr[1])
12+
println(arr[4])
13+
14+
// Array operations
15+
mut nums := []int{}
16+
nums << 100
17+
nums << 200
18+
nums << 300
19+
20+
println(nums[0])
21+
println(nums[1])
22+
println(nums[2])
23+
}
24+
25+
fn test_array_with_structs() {
26+
struct Point {
27+
x int
28+
y int
29+
}
30+
31+
// Array of structs
32+
mut points := []Point{}
33+
points << Point{10, 20}
34+
points << Point{30, 40}
35+
36+
println(points[0].x)
37+
println(points[0].y)
38+
println(points[1].x)
39+
println(points[1].y)
40+
}
41+
42+
fn main() {
43+
println('=== Test array field access ===')
44+
test_array_field_access()
45+
46+
println('=== Test array with structs ===')
47+
test_array_with_structs()
48+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== Test array field access ===
2+
10
3+
20
4+
50
5+
100
6+
200
7+
300
8+
=== Test array with structs ===
9+
10
10+
20
11+
30
12+
40

0 commit comments

Comments
 (0)