| 1 | import strconv |
| 2 | |
| 3 | fn value(n int) int { |
| 4 | return n |
| 5 | } |
| 6 | |
| 7 | struct Foo { |
| 8 | n int |
| 9 | } |
| 10 | |
| 11 | fn (foo Foo) value() int { |
| 12 | return foo.n |
| 13 | } |
| 14 | |
| 15 | fn test_negative() { |
| 16 | one := 1 |
| 17 | negative_one := -1 |
| 18 | assert -one == negative_one |
| 19 | assert one == -negative_one |
| 20 | |
| 21 | assert -value(1) == -1 |
| 22 | |
| 23 | // issue #9643 |
| 24 | foo := Foo{1} |
| 25 | assert -foo.value() == -1 |
| 26 | assert -(foo.value()) == -1 |
| 27 | |
| 28 | arr := [1, 2, 3] |
| 29 | assert -arr[0] == -1 |
| 30 | assert -arr[1] == -2 |
| 31 | } |
| 32 | |
| 33 | fn test_positive() { |
| 34 | two := 2 |
| 35 | assert +two == 2 |
| 36 | assert +(two - 1) == 1 |
| 37 | } |
| 38 | |
| 39 | fn test_prefix_expr_in_assert_comparison() ! { |
| 40 | i := 2 |
| 41 | assert strconv.atoi('1')! == 1 |
| 42 | assert strconv.atoi('-2')! == -2 |
| 43 | assert strconv.atoi('+2')! == i - 1 + 1 |
| 44 | assert strconv.atoi('+2')! == -(-2) |
| 45 | assert strconv.atoi('+2')! == +2 |
| 46 | } |
| 47 | |