| 1 | const start = 1 |
| 2 | const start_2 = 4 |
| 3 | const end = 3 |
| 4 | const end_2 = 8 |
| 5 | // |
| 6 | const start_rune = `a` |
| 7 | const start_2_rune = `d` |
| 8 | const end_rune = `c` |
| 9 | const end_2_rune = `i` |
| 10 | // |
| 11 | const start_cast_expr = u16(1) |
| 12 | const end_cast_expr = u16(5) |
| 13 | |
| 14 | fn test_match_int_const_ranges() { |
| 15 | mut results := []int{} |
| 16 | for x in 0 .. 10 { |
| 17 | match x { |
| 18 | start...end { results << 1 } |
| 19 | start_2...5 { results << 2 } |
| 20 | 6...end_2 { results << 3 } |
| 21 | else { results << 4 } |
| 22 | } |
| 23 | } |
| 24 | assert results == [4, 1, 1, 1, 2, 2, 3, 3, 3, 4] |
| 25 | } |
| 26 | |
| 27 | fn test_match_rune_const_ranges() { |
| 28 | mut results := []int{} |
| 29 | for x in `a` .. `l` { |
| 30 | match x { |
| 31 | start_rune...end_rune { results << 1 } |
| 32 | start_2_rune...`e` { results << 2 } |
| 33 | `f`...end_2_rune { results << 3 } |
| 34 | else { results << 4 } |
| 35 | } |
| 36 | } |
| 37 | assert results == [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4] |
| 38 | } |
| 39 | |
| 40 | fn test_match_expr_int_const_ranges() { |
| 41 | mut results := []int{} |
| 42 | for x in 0 .. 10 { |
| 43 | result := match x { |
| 44 | start...end { 1 } |
| 45 | start_2...5 { 2 } |
| 46 | 6...end_2 { 3 } |
| 47 | else { 4 } |
| 48 | } |
| 49 | |
| 50 | results << result |
| 51 | } |
| 52 | assert results == [4, 1, 1, 1, 2, 2, 3, 3, 3, 4] |
| 53 | } |
| 54 | |
| 55 | fn test_match_expr_rune_const_ranges() { |
| 56 | mut results := []int{} |
| 57 | for x in `a` .. `l` { |
| 58 | result := match x { |
| 59 | start_rune...end_rune { 1 } |
| 60 | start_2_rune...`e` { 2 } |
| 61 | `f`...end_2_rune { 3 } |
| 62 | else { 4 } |
| 63 | } |
| 64 | |
| 65 | results << result |
| 66 | } |
| 67 | assert results == [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4] |
| 68 | } |
| 69 | |
| 70 | fn test_match_expr_integer_cast_const_ranges() { |
| 71 | c := u16(3) |
| 72 | match c { |
| 73 | start_cast_expr...end_cast_expr { |
| 74 | assert c == u16(3) |
| 75 | } |
| 76 | else {} |
| 77 | } |
| 78 | } |
| 79 | |