v2 / vlib / v / tests / structs / struct_auto_eq_gen_interface_test.v
43 lines · 35 sloc · 595 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1interface IExample {
2 thing() bool
3}
4
5struct Foo {}
6
7fn (n Foo) thing() bool {
8 return true
9}
10
11struct Test {
12 a IExample
13}
14
15fn new() Test {
16 return Test{Foo{}}
17}
18
19fn test_struct_auto_eq_gen_interface_case() {
20 w1 := new()
21 w2 := new()
22 assert w1 == w2
23}
24
25// For https://github.com/vlang/v/issues/16074
26pub interface Logger {
27mut:
28 info(s string)
29}
30
31struct LogContainer {
32 name string
33mut:
34 logger &Logger = unsafe { nil }
35}
36
37fn test_comparing_struct_with_pointers_to_interface_values_autogenerates_working_eq_method() {
38 assert LogContainer{
39 name: 'abc'
40 } == LogContainer{
41 name: 'abc'
42 }
43}
44