| 1 | // vtest vflags: -autofree |
| 2 | // vtest build: !sanitize-address-gcc && !sanitize-address-clang |
| 3 | // Test for memory leak fix when using generics with math.min/max and autofree |
| 4 | module main |
| 5 | |
| 6 | import math |
| 7 | import time |
| 8 | |
| 9 | fn test_math_min_with_time_and_int() { |
| 10 | // Test with time.Time |
| 11 | t1 := time.Time{ |
| 12 | year: 2022 |
| 13 | day: 1 |
| 14 | } |
| 15 | t2 := time.Time{ |
| 16 | year: 2021 |
| 17 | day: 1 |
| 18 | } |
| 19 | t3 := math.min(t1, t2) |
| 20 | assert t3.year == 2021 |
| 21 | |
| 22 | // Test with int |
| 23 | a := 10 |
| 24 | b := 5 |
| 25 | c := math.min(a, b) |
| 26 | assert c == 5 |
| 27 | } |
| 28 | |
| 29 | fn test_math_max_with_time_and_int() { |
| 30 | // Test with time.Time |
| 31 | t1 := time.Time{ |
| 32 | year: 2022 |
| 33 | day: 1 |
| 34 | } |
| 35 | t2 := time.Time{ |
| 36 | year: 2021 |
| 37 | day: 1 |
| 38 | } |
| 39 | t3 := math.max(t1, t2) |
| 40 | assert t3.year == 2022 |
| 41 | |
| 42 | // Test with int |
| 43 | a := 10 |
| 44 | b := 5 |
| 45 | c := math.max(a, b) |
| 46 | assert c == 10 |
| 47 | } |
| 48 | |