v2 / vlib / v / tests / imported_symbols_test.v
51 lines · 45 sloc · 779 bytes · 94a36c5ca42f6ebeaddf3bf1b84840249aea0fe3
Raw
1import geometry { Line, Point, PointCond, Shape, point_str }
2
3fn point_is(p Point, cond PointCond) bool {
4 return cond(p)
5}
6
7fn 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
29fn 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
40fn vertex_count(s Shape) int {
41 return match s {
42 .circle { 0 }
43 .triangle { 3 }
44 .rectangle { 4 }
45 }
46}
47
48fn test_imported_symbols_enums() {
49 assert vertex_count(.triangle) == 3
50 assert vertex_count(Shape.triangle) == 3
51}
52