v2 / vlib / v / tests / indexexpr_with_assign_test.v
34 lines · 33 sloc · 425 bytes · 8db23006d21a55f97d86bc9536ac6442671c6e43
Raw
1fn test_1() {
2 mut test := []f64{}
3 test << 0
4 test[0] = if true {
5 sum := 1.2
6 sum
7 } else {
8 0
9 }
10 assert test == [1.2]
11}
12
13fn test_2() {
14 check := true
15 mut test := []f64{len: 100}
16 for i in 0 .. 100 {
17 test[i] = if check {
18 mut sum := 0.0
19 for x in 0 .. 100 {
20 if check {
21 sum += 1
22 }
23 if i <= x {
24 break
25 }
26 }
27 sum
28 } else {
29 0
30 }
31 }
32 assert test[0] == 1.0
33 assert test[99] == 100.0
34}
35