| 1 | import geometry { Line, Point, PointCond, Shape, point_str } |
| 2 | |
| 3 | fn point_is(p Point, cond PointCond) bool { |
| 4 | return cond(p) |
| 5 | } |
| 6 | |
| 7 | fn test_imported_symbols_types() { |
| 8 | // struct init |
| 9 | p0 := Point{ |
| 10 | x: 10 |
| 11 | y: 20 |
| 12 | } |
| 13 | p1 := Point{ |
| 14 | x: 40 |
| 15 | y: 60 |
| 16 | } |
| 17 | // array init |
| 18 | l0 := Line{ |
| 19 | ps: [p0, p1] |
| 20 | } |
| 21 | assert l0.ps[0].y == 20 |
| 22 | |
| 23 | cond := fn (p Point) bool { |
| 24 | return p.x == 10 |
| 25 | } |
| 26 | assert point_is(p0, cond) |
| 27 | } |
| 28 | |
| 29 | fn test_imported_symbols_functions() { |
| 30 | p0 := Point{ |
| 31 | x: 20 |
| 32 | y: 40 |
| 33 | } |
| 34 | // method |
| 35 | assert p0.str() == '20 40' |
| 36 | // function |
| 37 | assert point_str(p0) == '20 40' |
| 38 | } |
| 39 | |
| 40 | fn vertex_count(s Shape) int { |
| 41 | return match s { |
| 42 | .circle { 0 } |
| 43 | .triangle { 3 } |
| 44 | .rectangle { 4 } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | fn test_imported_symbols_enums() { |
| 49 | assert vertex_count(.triangle) == 3 |
| 50 | assert vertex_count(Shape.triangle) == 3 |
| 51 | } |
| 52 | |