v2 / vlib / v / tests / printing / print_smartcast_variable_test.v
33 lines · 27 sloc · 507 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Point {
2 x int
3 y int
4}
5
6struct Line {
7 p1 Point
8 p2 Point
9}
10
11// Sum type
12type ObjSumType = Line | Point
13
14fn test_print_smartcast_variable() {
15 // Type checking and casts
16 mut point := ObjSumType(Point{2, 5})
17
18 if point is Point {
19 println('Point')
20 }
21
22 if point !is Point {
23 println('Not Point')
24 }
25
26 if mut point is Point {
27 println(point)
28 assert point.str().contains('x: 2')
29 assert point.str().contains('y: 5')
30 assert '${point}'.contains('x: 2')
31 assert '${point}'.contains('y: 5')
32 }
33}
34