diff --git a/vlib/v/tests/generic_fn_assign_generics_struct_test.v b/vlib/v/tests/generic_fn_assign_generics_struct_test.v index a27ee1a758..3f23aef188 100644 --- a/vlib/v/tests/generic_fn_assign_generics_struct_test.v +++ b/vlib/v/tests/generic_fn_assign_generics_struct_test.v @@ -9,9 +9,21 @@ fn get_test(v T) Test { } fn test_generics_assign_generics_struct() { - x := get_test(1) - println('$x.v') - assert x.v == 1 + x1 := get_test(1) + println('$x1.v') + assert x1.v == 1 + + x2 := get_test(2.2) + println('$x2.v') + assert x2.v == 2.2 + + x3 := get_test('aaa') + println('$x3.v') + assert x3.v == 'aaa' + + x4 := get_test(true) + println('$x4.v') + assert x4.v == true } // test generics assign generics struct_init @@ -31,8 +43,23 @@ fn (mut n Node) add(val T) { } fn test_generic_fn_assign_generic_struct_init() { - mut list := new() - list.add(100) - println(list.next) - assert list.next.val == 100 + mut list1 := new() + list1.add(100) + println(list1.next) + assert list1.next.val == 100 + + mut list2 := new() + list2.add(2.22) + println(list2.next) + assert list2.next.val == 2.22 + + mut list3 := new() + list3.add(false) + println(list3.next) + assert list3.next.val == false + + mut list4 := new() + list4.add('aaa') + println(list4.next) + assert list4.next.val == 'aaa' } diff --git a/vlib/v/tests/generics_return_multiple_generics_struct_test.v b/vlib/v/tests/generics_return_multiple_generics_struct_test.v index f143d86398..3b30a564e7 100644 --- a/vlib/v/tests/generics_return_multiple_generics_struct_test.v +++ b/vlib/v/tests/generics_return_multiple_generics_struct_test.v @@ -25,14 +25,36 @@ fn set(mut opt Foo, a A, b B) { } fn test_generics_return_multiple_generics_struct() { - mut o := new_foo(23, 'aaa') - println(get_a(o)) - assert get_a(o) == 23 - println(get_b(o)) - assert get_b(o) == 'aaa' - set(mut o, 42, 'bbb') - println(get_a(o)) - assert get_a(o) == 42 - println(get_b(o)) - assert get_b(o) == 'bbb' + mut o1 := new_foo(23, 'aaa') + println(get_a(o1)) + assert get_a(o1) == 23 + println(get_b(o1)) + assert get_b(o1) == 'aaa' + set(mut o1, 42, 'bbb') + println(get_a(o1)) + assert get_a(o1) == 42 + println(get_b(o1)) + assert get_b(o1) == 'bbb' + + mut o2 := new_foo('bbb', 22) + println(get_a(o2)) + assert get_a(o2) == 'bbb' + println(get_b(o2)) + assert get_b(o2) == 22 + set(mut o2, 'bbb', 42) + println(get_a(o2)) + assert get_a(o2) == 'bbb' + println(get_b(o2)) + assert get_b(o2) == 42 + + mut o3 := new_foo(23, true) + println(get_a(o3)) + assert get_a(o3) == 23 + println(get_b(o3)) + assert get_b(o3) == true + set(mut o3, 42, false) + println(get_a(o3)) + assert get_a(o3) == 42 + println(get_b(o3)) + assert get_b(o3) == false } diff --git a/vlib/v/tests/generics_return_recursive_generics_struct_test.v b/vlib/v/tests/generics_return_recursive_generics_struct_test.v index ab0f723d3f..34b22767ff 100644 --- a/vlib/v/tests/generics_return_recursive_generics_struct_test.v +++ b/vlib/v/tests/generics_return_recursive_generics_struct_test.v @@ -12,7 +12,19 @@ fn make_node(val []T) Node { } fn test_generics_return_recursive_generics_struct() { - n := make_node([1, 2, 3]) - println(n.val) - assert n.val == 1 + n1 := make_node([1, 2, 3]) + println(n1.val) + assert n1.val == 1 + + n2 := make_node([1.1, 2.2, 3.3]) + println(n2.val) + assert n2.val == 1.1 + + n3 := make_node([true, false, true]) + println(n3.val) + assert n3.val == true + + n4 := make_node(['aa', 'bb', 'cc']) + println(n4.val) + assert n4.val == 'aa' } diff --git a/vlib/v/tests/generics_return_reference_generics_struct_test.v b/vlib/v/tests/generics_return_reference_generics_struct_test.v index 35717777a2..500b64f8f2 100644 --- a/vlib/v/tests/generics_return_reference_generics_struct_test.v +++ b/vlib/v/tests/generics_return_reference_generics_struct_test.v @@ -9,7 +9,15 @@ fn new_foo(len int) &Foo { } fn test_generics_return_reference_generics_struct() { - f := new_foo(4) - println(f) - assert f.data == [0, 0, 0, 0] + f1 := new_foo(4) + println(f1) + assert f1.data == [0, 0, 0, 0] + + f2 := new_foo(4) + println(f2) + assert f2.data == [false, false, false, false] + + f3 := new_foo(4) + println(f3) + assert f3.data == [0.0, 0.0, 0.0, 0.0] } diff --git a/vlib/v/tests/generics_struct_anon_fn_fields_test.v b/vlib/v/tests/generics_struct_anon_fn_fields_test.v index a20e1630cc..5f4b0c4f33 100644 --- a/vlib/v/tests/generics_struct_anon_fn_fields_test.v +++ b/vlib/v/tests/generics_struct_anon_fn_fields_test.v @@ -5,10 +5,31 @@ struct Scope { } fn test_generics_struct_anon_fn_fields() { - s := Scope{} - println(s) - ts := '$s' - assert ts.contains('before: fn () u32') - assert ts.contains('specs: []') - assert ts.contains('after: fn (u32)') + s1 := Scope{} + println(s1) + ts1 := '$s1' + assert ts1.contains('before: fn () u32') + assert ts1.contains('specs: []') + assert ts1.contains('after: fn (u32)') + + s2 := Scope{} + println(s2) + ts2 := '$s2' + assert ts2.contains('before: fn () f64') + assert ts2.contains('specs: []') + assert ts2.contains('after: fn (f64)') + + s3 := Scope{} + println(s3) + ts3 := '$s3' + assert ts3.contains('before: fn () string') + assert ts3.contains('specs: []') + assert ts3.contains('after: fn (string)') + + s4 := Scope{} + println(s4) + ts4 := '$s4' + assert ts4.contains('before: fn () bool') + assert ts4.contains('specs: []') + assert ts4.contains('after: fn (bool)') } diff --git a/vlib/v/tests/generics_with_embed_generics_test.v b/vlib/v/tests/generics_with_embed_generics_test.v index d7d15fae5c..3ca713f61e 100644 --- a/vlib/v/tests/generics_with_embed_generics_test.v +++ b/vlib/v/tests/generics_with_embed_generics_test.v @@ -28,9 +28,27 @@ fn (mut it Group) next() ?T { } fn test_generics_with_embed_generics() { - gx := group_new(1, 2, 3) - for x in gx.val { + gx1 := group_new(1, 2, 3) + for x in gx1.val { println(x) } - assert gx.val == [1, 2, 3] + assert gx1.val == [1, 2, 3] + + gx2 := group_new(1.1, 2.2, 3.3) + for x in gx2.val { + println(x) + } + assert gx2.val == [1.1, 2.2, 3.3] + + gx3 := group_new(true, true, false) + for x in gx3.val { + println(x) + } + assert gx3.val == [true, true, false] + + gx4 := group_new('aa', 'bb', 'cc') + for x in gx4.val { + println(x) + } + assert gx4.val == ['aa', 'bb', 'cc'] } diff --git a/vlib/v/tests/generics_with_generics_struct_receiver_test.v b/vlib/v/tests/generics_with_generics_struct_receiver_test.v index ddedd391a3..72c74dad43 100644 --- a/vlib/v/tests/generics_with_generics_struct_receiver_test.v +++ b/vlib/v/tests/generics_with_generics_struct_receiver_test.v @@ -7,7 +7,19 @@ fn (num Num) is_autom() bool { } fn test_generics_with_generic_struct_receiver() { - num := Num{3} - println(num.is_autom()) - assert num.is_autom() + num1 := Num{3} + println(num1.is_autom()) + assert num1.is_autom() + + num2 := Num{3.3} + println(num2.is_autom()) + assert num2.is_autom() + + num3 := Num{'aaa'} + println(num3.is_autom()) + assert num3.is_autom() + + num4 := Num{true} + println(num4.is_autom()) + assert num4.is_autom() }