From 4a10514081939b08917684d06df3c47e3f359fc1 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Sat, 27 Mar 2021 18:29:57 +0100 Subject: [PATCH] tests: run vfmt over some of the tests in vlib/v/tests (#9455) --- cmd/tools/vtest-cleancode.v | 9 +- vlib/v/tests/anon_fn_call_test.v | 4 +- vlib/v/tests/anon_fn_in_containers_test.v | 12 +- .../v/tests/anon_fn_returning_question_test.v | 10 +- vlib/v/tests/anon_fn_test.v | 2 +- vlib/v/tests/array_append_short_struct_test.v | 16 +- vlib/v/tests/array_cast_test.v | 2 +- vlib/v/tests/array_equality_test.v | 17 +- vlib/v/tests/array_map_or_test.v | 21 ++- vlib/v/tests/array_map_ref_test.v | 4 +- vlib/v/tests/array_methods_test.v | 4 +- vlib/v/tests/array_slice_test.v | 12 +- vlib/v/tests/array_to_string_test.v | 10 +- .../as_cast_is_expr_sumtype_fn_result_test.v | 16 +- vlib/v/tests/assert_sumtype_test.v | 3 +- vlib/v/tests/attribute_test.v | 7 +- vlib/v/tests/backtrace_test.v | 2 +- vlib/v/tests/complex_assign_test.v | 54 +++---- vlib/v/tests/comptime_call_test.v | 12 +- vlib/v/tests/comptime_if_is_test.v | 1 - vlib/v/tests/comptime_method_args_test.v | 4 +- vlib/v/tests/const_test.v | 4 +- vlib/v/tests/conversions_test.v | 2 +- vlib/v/tests/cross_assign_test.v | 58 +++++-- vlib/v/tests/cstrings_test.v | 6 +- vlib/v/tests/defer_test.v | 2 +- .../tests/enum_default_value_in_struct_test.v | 2 +- vlib/v/tests/fixed_array_test.v | 20 ++- vlib/v/tests/fn_assignment_test.v | 28 ++-- vlib/v/tests/fn_cross_assign_test.v | 17 +- ..._expecting_ref_but_returning_struct_test.v | 6 +- vlib/v/tests/fn_high_test.v | 46 +++--- vlib/v/tests/fn_index_direct_call_test.v | 32 ++-- vlib/v/tests/fn_multiple_returns_test.v | 16 +- vlib/v/tests/fn_mut_args_test.v | 8 +- vlib/v/tests/fn_shared_return_test.v | 36 +++-- .../fn_with_fixed_array_function_args_test.v | 2 +- vlib/v/tests/for_c_multi_vars_test.v | 4 +- .../for_in_containers_of_fixed_array_test.v | 18 ++- vlib/v/tests/for_in_iterator_test.v | 2 +- vlib/v/tests/for_in_mut_val_test.v | 34 ++-- vlib/v/tests/for_label_continue_break_test.v | 9 +- vlib/v/tests/for_loops_test.v | 8 +- vlib/v/tests/for_smartcast_test.v | 7 +- .../generic_fn_returning_type_with_T_test.v | 38 +++-- .../v/tests/generic_fn_upper_name_type_test.v | 8 +- ...eric_functions_with_normal_function_test.v | 4 +- .../generics_from_modules/inference_test.v | 2 +- vlib/v/tests/generics_test.v | 75 +++++---- vlib/v/tests/go_array_wait_test.v | 20 +-- vlib/v/tests/if_expr_of_optional_test.v | 6 +- vlib/v/tests/if_guard_test.v | 15 +- vlib/v/tests/if_smartcast_test.v | 46 +++--- vlib/v/tests/imported_symbols_test.v | 31 ++-- vlib/v/tests/in_expression_test.v | 11 +- vlib/v/tests/inout/compiler_test.v | 12 +- vlib/v/tests/interface_auto_str_gen_test.v | 17 +- vlib/v/tests/interface_struct_test.v | 6 +- vlib/v/tests/interface_test.v | 6 +- vlib/v/tests/local/local.v | 2 - vlib/v/tests/map_alias_key_test.v | 20 ++- vlib/v/tests/map_and_array_with_fns_test.v | 28 +++- vlib/v/tests/map_complex_fixed_array_test.v | 29 +++- vlib/v/tests/map_equality_test.v | 34 +++- vlib/v/tests/map_high_order_assign_test.v | 2 +- vlib/v/tests/map_key_expr_test.v | 15 +- vlib/v/tests/map_to_string_test.v | 19 ++- vlib/v/tests/map_type_alias_test.v | 6 +- vlib/v/tests/maps_equal_test.v | 8 +- .../v/tests/match_expression_for_types_test.v | 18 ++- vlib/v/tests/match_in_map_init_test.v | 6 +- vlib/v/tests/match_interface_test.v | 28 ++-- vlib/v/tests/match_smartcast_test.v | 11 +- .../match_sumtype_var_shadow_and_as_test.v | 21 ++- vlib/v/tests/method_call_chain_test.v | 22 ++- vlib/v/tests/methods_on_interfaces_test.v | 4 +- vlib/v/tests/module_test.v | 2 +- vlib/v/tests/module_type_cast_test.v | 4 +- .../modules/acommentedmodule/commentedfile.v | 2 - vlib/v/tests/modules/geometry/geometry.v | 20 +-- .../methods_struct_test.v | 19 ++- .../modules/simplemodule/importing_test.v | 6 +- .../multiple_paths_in_vmodules/path1/xxx/m.v | 1 + .../multiple_paths_in_vmodules/path2/yyy/m.v | 3 +- .../multiple_paths_in_vmodules/path3/zzz/m.v | 3 +- vlib/v/tests/mut_test.v | 136 +++++++++------- vlib/v/tests/nested_option_call_test.v | 4 +- vlib/v/tests/offsetof_test.v | 16 +- vlib/v/tests/operator_overloading_cmp_test.v | 10 +- ...erloading_with_string_interpolation_test.v | 2 +- vlib/v/tests/option_2_test.v | 7 +- vlib/v/tests/option_default_values_test.v | 60 ++----- vlib/v/tests/option_print_errors_test.v | 9 +- vlib/v/tests/option_test.v | 2 +- vlib/v/tests/orm_sub_struct_test.v | 4 +- vlib/v/tests/project_with_c_code/main.v | 2 +- vlib/v/tests/project_with_c_code/main_test.v | 6 +- .../tests/project_with_c_code/mod1/wrapper.v | 2 +- vlib/v/tests/project_with_c_code_2/main.v | 2 +- .../tests/project_with_c_code_2/main2_test.v | 2 +- .../project_with_c_code_2/modc/wrapper.v | 1 + .../a_program_under_bin_can_find_mod1_test.v | 2 +- .../bin/main.vsh | 8 +- .../mod1/submodule/m.v | 11 +- .../tests/submodule_test.v | 4 +- vlib/v/tests/ref_struct_test.v | 26 +++- vlib/v/tests/repl/repl_test.v | 4 +- vlib/v/tests/semaphore_timed_test.v | 2 +- vlib/v/tests/shared_arg_test.v | 28 +++- vlib/v/tests/shared_autolock_test.v | 8 +- vlib/v/tests/shared_elem_test.v | 66 ++++++-- vlib/v/tests/shared_fn_return_test.v | 36 ++++- vlib/v/tests/shared_lock_5_test.v | 2 +- vlib/v/tests/shared_lock_6_test.v | 2 +- vlib/v/tests/shared_lock_expr_test.v | 48 ++++-- vlib/v/tests/shared_map_test.v | 25 ++- vlib/v/tests/shared_unordered_mixed_test.v | 43 ++++-- vlib/v/tests/short_struct_param_syntax_test.v | 4 +- vlib/v/tests/sizeof_test.v | 1 + .../sorting_by_different_criteria_test.v | 2 +- vlib/v/tests/sorting_by_references_test.v | 20 ++- vlib/v/tests/str_gen_test.v | 80 +++++++--- .../v/tests/string_interpolation_alias_test.v | 11 +- .../v/tests/string_interpolation_array_test.v | 26 ++-- .../string_interpolation_custom_str_test.v | 6 +- .../string_interpolation_function_test.v | 26 +++- .../string_interpolation_multi_return_test.v | 17 +- .../tests/string_interpolation_shared_test.v | 23 ++- .../string_interpolation_string_args_test.v | 20 +-- .../tests/string_interpolation_struct_test.v | 5 +- vlib/v/tests/string_interpolation_test.v | 35 ++--- .../tests/string_struct_interpolation_test.v | 2 +- ...w_both_field_defaults_and_skip_flag_test.v | 10 +- .../struct_chained_fields_correct_test.v | 35 ++++- vlib/v/tests/struct_embed_test.v | 18 ++- vlib/v/tests/struct_eq_op_only_test.v | 2 +- ..._field_default_value_interface_cast_test.v | 4 +- ...ct_field_default_value_sumtype_cast_test.v | 6 +- vlib/v/tests/struct_test.v | 99 ++++++------ vlib/v/tests/struct_transmute_test.v | 12 +- vlib/v/tests/sum_type_common_fields_test.v | 1 - vlib/v/tests/sum_type_test.v | 146 +++++++++++++----- vlib/v/tests/sumtype_equality_test.v | 10 +- .../sumtype_str_for_subtypes_with_str_test.v | 2 +- vlib/v/tests/sumtype_str_test.v | 14 +- vlib/v/tests/tmpl_test.v | 1 - vlib/v/tests/type_alias_test.v | 3 +- vlib/v/tests/type_name_test.v | 14 +- vlib/v/tests/type_promotion_test.v | 16 +- vlib/v/tests/unsafe_test.v | 10 +- vlib/v/tests/valgrind/option_reassigned.v | 4 +- vlib/v/tests/valgrind/option_simple.v | 4 +- vlib/v/tests/vmod_parser_test.v | 20 +-- vlib/v/tests/voidptr_to_u64_cast_a_test.v | 2 +- vlib/v/tests/voidptr_to_u64_cast_b_test.v | 2 +- .../tests/working_with_an_empty_struct_test.v | 6 +- 156 files changed, 1573 insertions(+), 945 deletions(-) mode change 100755 => 100644 vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh diff --git a/cmd/tools/vtest-cleancode.v b/cmd/tools/vtest-cleancode.v index 8de3526dc0..4bd58eac34 100644 --- a/cmd/tools/vtest-cleancode.v +++ b/cmd/tools/vtest-cleancode.v @@ -21,6 +21,13 @@ const ( 'vlib/gg/m4/graphic.v' /* has hand crafted meaningful formatting of matrices */, 'vlib/gg/m4/m4_test.v' /* has hand crafted meaningful formatting of matrices */, 'vlib/gg/m4/matrix.v' /* has hand crafted meaningful formatting of matrices */, + 'vlib/v/tests/array_append_short_struct_test.v', /* extra empty line */ + 'vlib/v/tests/fixed_array_const_size_test.v', /* fixed arr type is changed */ + 'vlib/v/tests/fn_high_test.v', /* param name removed */ + 'vlib/v/tests/fn_test.v', /* bad comment formatting */ + 'vlib/v/tests/generics_return_generics_struct_test.v', /* generic fn param removed */ + 'vlib/v/tests/interop_test.v', /* bad comment formatting */ + 'vlib/v/tests/generics_test.v', /* some silent error */ ] vfmt_verify_list = [ 'cmd/', @@ -58,7 +65,7 @@ const ( 'vlib/v/preludes', 'vlib/v/scanner/', 'vlib/v/table/', - //'vlib/v/tests/', + 'vlib/v/tests/', 'vlib/v/token/', 'vlib/v/util/', 'vlib/v/vcache/', diff --git a/vlib/v/tests/anon_fn_call_test.v b/vlib/v/tests/anon_fn_call_test.v index 4ba7cf41ec..5591e0054a 100644 --- a/vlib/v/tests/anon_fn_call_test.v +++ b/vlib/v/tests/anon_fn_call_test.v @@ -1,10 +1,10 @@ fn test_anon_fn_call() { - anon_fn := fn() string { + anon_fn := fn () string { return test() } assert anon_fn() == 'Test' } fn test() string { - return "Test" + return 'Test' } diff --git a/vlib/v/tests/anon_fn_in_containers_test.v b/vlib/v/tests/anon_fn_in_containers_test.v index 0a2e80b9bf..808838afab 100644 --- a/vlib/v/tests/anon_fn_in_containers_test.v +++ b/vlib/v/tests/anon_fn_in_containers_test.v @@ -1,36 +1,36 @@ fn test_anon_fn_in_map() { mut woop := map{ - 'what': fn() string { + 'what': fn () string { return 'whoopity whoop' } } assert woop['what']() == 'whoopity whoop' - woop['shat'] = fn() string { + woop['shat'] = fn () string { return 'shoopity shoop' } assert woop['shat']() == 'shoopity shoop' } fn test_anon_fn_in_array() { - mut woop := [fn() string { + mut woop := [fn () string { return 'whoopity whoop' }] assert woop[0]() == 'whoopity whoop' - woop[0] = fn() string { + woop[0] = fn () string { return 'shoopity shoop' } assert woop[0]() == 'shoopity shoop' } fn test_anon_fn_in_fixed_array() { - mut woop := [fn() string { + mut woop := [fn () string { return 'whoopity whoop' }]! assert woop[0]() == 'whoopity whoop' - woop[0] = fn() string { + woop[0] = fn () string { return 'shoopity shoop' } assert woop[0]() == 'shoopity shoop' diff --git a/vlib/v/tests/anon_fn_returning_question_test.v b/vlib/v/tests/anon_fn_returning_question_test.v index 36cd2732d8..b92e036650 100644 --- a/vlib/v/tests/anon_fn_returning_question_test.v +++ b/vlib/v/tests/anon_fn_returning_question_test.v @@ -7,11 +7,11 @@ fn test_calling_an_anon_function_returning_question() { fn create_and_call_anon_function() ? { x := fn (a string, b int) ? { println('test') - // NB: the anon function does NOT return explicitly, - // so V should generate an implicit "OK" value and - // return it. Previously, it created an implicit optional - // filled with 0s => .ok was false, and that was treated - // as a failure, triggering or blocks. + // NB: the anon function does NOT return explicitly, + // so V should generate an implicit "OK" value and + // return it. Previously, it created an implicit optional + // filled with 0s => .ok was false, and that was treated + // as a failure, triggering or blocks. } should_not_call_block(x) ? assert true diff --git a/vlib/v/tests/anon_fn_test.v b/vlib/v/tests/anon_fn_test.v index b570c32ec4..9337e422b2 100644 --- a/vlib/v/tests/anon_fn_test.v +++ b/vlib/v/tests/anon_fn_test.v @@ -2,7 +2,7 @@ import sync fn test_go_anon_fn() { mut wg := sync.new_waitgroup() - wg.add(1) + wg.add(1) go fn (mut wg sync.WaitGroup) { wg.done() }(mut wg) diff --git a/vlib/v/tests/array_append_short_struct_test.v b/vlib/v/tests/array_append_short_struct_test.v index 4bf90d451c..293e9d5683 100644 --- a/vlib/v/tests/array_append_short_struct_test.v +++ b/vlib/v/tests/array_append_short_struct_test.v @@ -1,5 +1,5 @@ struct Page { - contents int + contents int } fn test_array_append_short_struct() { @@ -8,7 +8,9 @@ fn test_array_append_short_struct() { contents: 3 } println(pages) - assert pages == [Page{contents: 3}] + assert pages == [Page{ + contents: 3 + }] } struct Container { @@ -18,8 +20,12 @@ pub mut: fn test_array_insert_or_prepend_short_struct() { mut a := []Container{} - a.prepend({name: 'a'}) - a.insert(0, {name: 'b'}) + a.prepend(name: 'a') + a.insert(0, name: 'b') println(a) - assert a == [Container{name: 'b'}, Container{name: 'a'}] + assert a == [Container{ + name: 'b' + }, Container{ + name: 'a' + }] } diff --git a/vlib/v/tests/array_cast_test.v b/vlib/v/tests/array_cast_test.v index 6882912570..072e6a5321 100644 --- a/vlib/v/tests/array_cast_test.v +++ b/vlib/v/tests/array_cast_test.v @@ -10,7 +10,7 @@ fn test_array_cast() { } fn test_int() { - mut arr := [2.3,3] + mut arr := [2.3, 3] unsafe { vp := voidptr(&arr) p := &[]f64(vp) diff --git a/vlib/v/tests/array_equality_test.v b/vlib/v/tests/array_equality_test.v index caf77fc000..128cd46337 100644 --- a/vlib/v/tests/array_equality_test.v +++ b/vlib/v/tests/array_equality_test.v @@ -4,7 +4,9 @@ struct Tester { } enum Color { - red green blue + red + green + blue } fn test_array_equality() { @@ -52,15 +54,15 @@ fn test_nested_array_equality() { a2 := [[[[1]]]] assert a2 == [[[[1]]]] assert a2 != [[[[2]]]] - a3 := [[[1,2,3]]] - assert a3 == [[[1,2,3]]] - assert a3 != [[[1,0,3]]] + a3 := [[[1, 2, 3]]] + assert a3 == [[[1, 2, 3]]] + assert a3 != [[[1, 0, 3]]] a4 := [[1.1], [2.2]] assert a4 == [[1.1], [2.2]] assert a4 != [[2.1], [3.2]] - a5 := [[[[1,2], [2,3], [3,4]]]] - assert a5 == [[[[1,2], [2,3], [3,4]]]] - assert a5 != [[[[2,2], [2,4], [3,4]]]] + a5 := [[[[1, 2], [2, 3], [3, 4]]]] + assert a5 == [[[[1, 2], [2, 3], [3, 4]]]] + assert a5 != [[[[2, 2], [2, 4], [3, 4]]]] a6 := [[['aa', 'bb'], ['cc', 'dd']]] assert a6 == [[['aa', 'bb'], ['cc', 'dd']]] assert a6 != [[['a', 'b'], ['cc', 'dd']]] @@ -76,6 +78,7 @@ fn test_nested_array_equality() { } type Literal = string + type Literals = []Literal fn (l1 Literal) concat(l2 Literal) Literals { diff --git a/vlib/v/tests/array_map_or_test.v b/vlib/v/tests/array_map_or_test.v index f7c73eaae9..6c46382edc 100644 --- a/vlib/v/tests/array_map_or_test.v +++ b/vlib/v/tests/array_map_or_test.v @@ -32,7 +32,7 @@ fn test_array_or_direct() { } fn test_map_or() { - m := { + m := map{ 'as': 3 'qw': 4 'kl': 5 @@ -51,9 +51,12 @@ fn test_map_or() { assert good == 5 } - fn get_map_el(key string) ?int { - m := {'as': 3, 'qw': 4, 'kl': 5} + m := map{ + 'as': 3 + 'qw': 4 + 'kl': 5 + } r := m[key] ? return r } @@ -90,12 +93,8 @@ fn test_propagation() { testvar2 = 177 int(-67) } - m := get_arr_el_direct(3) or { - 17 - } - n := get_arr_el_direct(0) or { - -73 - } + m := get_arr_el_direct(3) or { 17 } + n := get_arr_el_direct(0) or { -73 } assert testvar1 == -34 assert testvar2 == 99 assert e == 7 @@ -114,8 +113,6 @@ fn get_arr_el_nested(i int) ?int { } fn test_nested_array_propagation() { - g := get_arr_el_nested(3) or { - 12 - } + g := get_arr_el_nested(3) or { 12 } assert g == 12 } diff --git a/vlib/v/tests/array_map_ref_test.v b/vlib/v/tests/array_map_ref_test.v index 19e2c4a527..42cd4eff4e 100644 --- a/vlib/v/tests/array_map_ref_test.v +++ b/vlib/v/tests/array_map_ref_test.v @@ -17,9 +17,9 @@ fn test_array_map_ref() { mut m := map[string]int{} mut m_ref := &map[string]f64{} mut a := []int{len: 10} - mut a_ref := &[]f64{cap: 12, len: 2} + mut a_ref := &[]f64{len: 2, cap: 12} shared m_shared := &map[string]f64{} - shared a_shared := &[]f64{cap: 12, len: 9} + shared a_shared := &[]f64{len: 9, cap: 12} // test usage m['a'] = 3 unsafe { diff --git a/vlib/v/tests/array_methods_test.v b/vlib/v/tests/array_methods_test.v index c3ef482e59..f6dce7cdf6 100644 --- a/vlib/v/tests/array_methods_test.v +++ b/vlib/v/tests/array_methods_test.v @@ -5,7 +5,9 @@ mut: // if this is called more than once, the test'll fail fn (mut c Counter) new_arr(msg string) []int { - if c.val > 0 { panic(msg) } + if c.val > 0 { + panic(msg) + } c.val++ return [1, 3, 2] } diff --git a/vlib/v/tests/array_slice_test.v b/vlib/v/tests/array_slice_test.v index 50141190a7..d56890988d 100644 --- a/vlib/v/tests/array_slice_test.v +++ b/vlib/v/tests/array_slice_test.v @@ -43,20 +43,20 @@ fn test_fixed_array_slice() { fixed_array1 := [1, 2, 3]! arr1 := fixed_array1[0..] assert arr1 == [1, 2, 3] - fixed_array2 := [[1, 2], [2, 3], [3, 4],[4, 5]]! + fixed_array2 := [[1, 2], [2, 3], [3, 4], [4, 5]]! arr2 := fixed_array2[0..] - assert arr2 == [[1, 2], [2, 3], [3, 4],[4, 5]] - mut arr := [1,2,3]! + assert arr2 == [[1, 2], [2, 3], [3, 4], [4, 5]] + mut arr := [1, 2, 3]! fixed_array_slice(arr) mut_fixed_array_slice(mut arr) } fn pointer_array_slice(mut a []int) { - assert a[0..] == [1,2,3] - assert a[..a.len] == [1,2,3] + assert a[0..] == [1, 2, 3] + assert a[..a.len] == [1, 2, 3] } fn test_pointer_array_slice() { - mut arr := [1,2,3] + mut arr := [1, 2, 3] pointer_array_slice(mut arr) } diff --git a/vlib/v/tests/array_to_string_test.v b/vlib/v/tests/array_to_string_test.v index 9efbbfee88..d647cb4435 100644 --- a/vlib/v/tests/array_to_string_test.v +++ b/vlib/v/tests/array_to_string_test.v @@ -45,7 +45,13 @@ fn test_interpolation_array_to_string() { fn test_interpolation_array_of_map_to_string() { mut ams := []map[string]string{} - ams << {'a': 'b', 'c': 'd'} - ams << {'e': 'f', 'g': 'h'} + ams << map{ + 'a': 'b' + 'c': 'd' + } + ams << map{ + 'e': 'f' + 'g': 'h' + } assert '$ams' == "[{'a': 'b', 'c': 'd'}, {'e': 'f', 'g': 'h'}]" } diff --git a/vlib/v/tests/as_cast_is_expr_sumtype_fn_result_test.v b/vlib/v/tests/as_cast_is_expr_sumtype_fn_result_test.v index 03c4b67660..e0fb8c2eb8 100644 --- a/vlib/v/tests/as_cast_is_expr_sumtype_fn_result_test.v +++ b/vlib/v/tests/as_cast_is_expr_sumtype_fn_result_test.v @@ -1,6 +1,16 @@ -const( str = 'abcdefghijklmnopqrstuvwxyz' num = 1234567890 ) -struct S1 { s1 string = str } -struct S2 { s2 int = num } +const ( + str = 'abcdefghijklmnopqrstuvwxyz' + num = 1234567890 +) + +struct S1 { + s1 string = str +} + +struct S2 { + s2 int = num +} + type Sum = S1 | S2 fn test_as_cast_with_sumtype_fn_result() { diff --git a/vlib/v/tests/assert_sumtype_test.v b/vlib/v/tests/assert_sumtype_test.v index ec02a692d7..b0445a2628 100644 --- a/vlib/v/tests/assert_sumtype_test.v +++ b/vlib/v/tests/assert_sumtype_test.v @@ -1,7 +1,8 @@ struct Moon {} + struct Mars {} -type World = Moon | Mars +type World = Mars | Moon fn test_assert_sumtype() { w := World(Moon{}) diff --git a/vlib/v/tests/attribute_test.v b/vlib/v/tests/attribute_test.v index 382bdda840..10dd6a682e 100644 --- a/vlib/v/tests/attribute_test.v +++ b/vlib/v/tests/attribute_test.v @@ -22,9 +22,7 @@ pub enum PubEnumAttrTest { two } - -[attrone] -[attrtwo] +[attrone; attrtwo] pub enum EnumMultiAttrTest { one two @@ -40,8 +38,7 @@ pub fn test_pub_fn_attribute() { assert true } -[attrone] -[attrtwo] +[attrone; attrtwo] fn test_fn_multi_attribute() { assert true } diff --git a/vlib/v/tests/backtrace_test.v b/vlib/v/tests/backtrace_test.v index 13614dd023..0af9f0ce05 100644 --- a/vlib/v/tests/backtrace_test.v +++ b/vlib/v/tests/backtrace_test.v @@ -1,5 +1,5 @@ /* - Test for backtrace capability +Test for backtrace capability */ fn a_method() { print_backtrace() diff --git a/vlib/v/tests/complex_assign_test.v b/vlib/v/tests/complex_assign_test.v index 875f39fa34..8095e3ed46 100644 --- a/vlib/v/tests/complex_assign_test.v +++ b/vlib/v/tests/complex_assign_test.v @@ -1,5 +1,5 @@ struct Object { - name string + name string value int } @@ -32,61 +32,51 @@ fn test_assign_multi_expr() { val2 := 2 // simple case for match - a,b,c := match false { - true { 1,2,3 } - false { 4,5,6 } + a, b, c := match false { + true { 1, 2, 3 } + false { 4, 5, 6 } } assert a == 4 assert b == 5 assert c == 6 // test with first value `literal` - d, e, f := if true { - 1, 'awesome', [13] - } else { - 0, 'bad', [0] - } + d, e, f := if true { 1, 'awesome', [13] } else { 0, 'bad', [0] } assert d == 1 assert e == 'awesome' assert f == [13] // test with first value `literal expr` and statement awesome := 'awesome' - g, h, i := if true { - 1 + val1, awesome, [13] - } else { - int(0), 'bad', [0] - } + g, h, i := if true { 1 + val1, awesome, [13] } else { int(0), 'bad', [0] } assert g == 2 assert h == 'awesome' assert i == [13] // test with first value `.name` - j, k, l := if true { - val1, 'awesome', [13] - } else { - val2, 'bad', [0] - } + j, k, l := if true { val1, 'awesome', [13] } else { val2, 'bad', [0] } assert j == 1 assert k == 'awesome' assert l == [13] // test with first value name and peek != .comma - m, n, o := if true { - val1 + 1, val1, val1 - } else { - val2, val2, val2 - } + m, n, o := if true { val1 + 1, val1, val1 } else { val2, val2, val2 } assert m == val1 + 1 assert n == val1 assert o == val1 // test practical complex expressions - val3 := Object { name: 'initial', value: 19 } + val3 := Object{ + name: 'initial' + value: 19 + } mut q, mut r, mut s := if true { - 1 + 1, 'awe' + 'some', Object{ ...val3, name: 'ok' } + 1 + 1, 'awe' + 'some', Object{ + ...val3 + name: 'ok' + } } else { - 0, '0', Object {} + 0, '0', Object{} } assert q == 2 assert r == 'awesome' @@ -95,9 +85,12 @@ fn test_assign_multi_expr() { // test assign to existing variables q, r, s = if false { - 0, '0', Object {} + 0, '0', Object{} } else { - 5, '55', Object{ ...val3, value: 555 } + 5, '55', Object{ + ...val3 + value: 555 + } } assert q == 5 assert r == '55' @@ -106,7 +99,7 @@ fn test_assign_multi_expr() { } fn test_issue_9330() { - arr := "0.1".split('.') + arr := '0.1'.split('.') a0, a1 := arr[0], arr[1].int() assert a0 == '0' assert a1 == 1 @@ -119,5 +112,4 @@ fn test_issue_9330() { d0, d1 := arr[0].int(), arr[1].f64() assert d0 == 0 assert d1 == 1.0 - } diff --git a/vlib/v/tests/comptime_call_test.v b/vlib/v/tests/comptime_call_test.v index e00d43458e..9e464c4a20 100644 --- a/vlib/v/tests/comptime_call_test.v +++ b/vlib/v/tests/comptime_call_test.v @@ -3,12 +3,15 @@ struct Test {} fn (test Test) v() { println('Test.v()') } + fn (test Test) i() int { return 4 } + fn (test Test) s() string { return 'test' } + fn (test Test) s2() string { return 'Two' } @@ -33,15 +36,13 @@ fn test_for_methods() { $if method.return_type is string { v := test.$method() r += v.str() - } - $else $if method.return_type is int { + } $else $if method.return_type is int { // TODO - //v := test.$method() + // v := test.$method() v := '?' r += v.str() assert method.name == 'i' - } - $else { + } $else { // no return type test.$method() assert method.name == 'v' @@ -64,4 +65,3 @@ fn test_methods_arg() { assert r == '!!!' } } - diff --git a/vlib/v/tests/comptime_if_is_test.v b/vlib/v/tests/comptime_if_is_test.v index e0bf7e937d..bba4936db2 100644 --- a/vlib/v/tests/comptime_if_is_test.v +++ b/vlib/v/tests/comptime_if_is_test.v @@ -26,4 +26,3 @@ fn test_is_or() { assert g(i8(1)) == 1 assert g(1) == 2 } - diff --git a/vlib/v/tests/comptime_method_args_test.v b/vlib/v/tests/comptime_method_args_test.v index 47520abaef..833658a14b 100644 --- a/vlib/v/tests/comptime_method_args_test.v +++ b/vlib/v/tests/comptime_method_args_test.v @@ -8,9 +8,11 @@ mut: fn (mut t TestStruct) one_arg(a1 string) { t.one_arg_called = true } + fn (mut t TestStruct) two_args(a2 string, b2 int) { t.two_args_called = true } + fn (mut t TestStruct) three_args(a3 string, b3 int, c3 []string) { t.three_args_called = true } @@ -43,7 +45,7 @@ fn test_comptime_call_method() { } else if method.name == 'two_args' { t.$method('two', 2) } else if method.name == 'three_args' { - t.$method('three', 3, ['th' 'ree']) + t.$method('three', 3, ['th', 'ree']) } } assert t.one_arg_called diff --git a/vlib/v/tests/const_test.v b/vlib/v/tests/const_test.v index b326ab192e..28a37f18e1 100644 --- a/vlib/v/tests/const_test.v +++ b/vlib/v/tests/const_test.v @@ -1,4 +1,4 @@ -pub const ( +pub const ( a = b c = a + b b = 1 @@ -26,7 +26,7 @@ fn foo_decode(name string) ?Foo { return Foo{name} } -pub const ( +pub const ( def = foo_decode('baz') or { Foo{} } bar = foo_decode('bar') ? ) diff --git a/vlib/v/tests/conversions_test.v b/vlib/v/tests/conversions_test.v index a8cbb5684a..9d281e2598 100644 --- a/vlib/v/tests/conversions_test.v +++ b/vlib/v/tests/conversions_test.v @@ -8,7 +8,7 @@ fn test_conv_to_bool() { assert int(b) == 1 // branchless tests (can be important for manual optimization) - arr := [7,8]! + arr := [7, 8]! e := arr[int(b)] assert e == 8 b = e < 0 diff --git a/vlib/v/tests/cross_assign_test.v b/vlib/v/tests/cross_assign_test.v index 02c2a24a3f..43014a14c7 100644 --- a/vlib/v/tests/cross_assign_test.v +++ b/vlib/v/tests/cross_assign_test.v @@ -18,7 +18,7 @@ fn foo1(mut arr []int) { } fn test_cross_assign_of_array_in_fn() { - mut arr := [1,2] + mut arr := [1, 2] foo1(mut arr) assert arr[0] == 2 assert arr[1] == 1 @@ -26,7 +26,10 @@ fn test_cross_assign_of_array_in_fn() { // Test cross assign of map values fn test_cross_assign_of_map() { - mut a := {'one':1, 'two':2} + mut a := map{ + 'one': 1 + 'two': 2 + } a['one'], a['two'] = a['two'], a['one'] println(a) assert a['one'] == 2 @@ -39,7 +42,10 @@ fn foo2(mut a map[string]int) { } fn test_cross_assign_of_map_in_fn() { - mut a := {'one':1, 'two':2} + mut a := map{ + 'one': 1 + 'two': 2 + } foo2(mut a) assert a['one'] == 2 assert a['two'] == 1 @@ -53,9 +59,12 @@ mut: } fn test_cross_assign_of_struct() { - mut x := Zoo{a:1, b:2} + mut x := Zoo{ + a: 1 + b: 2 + } x.a, x.b = x.b, x.a - //println(x) + // println(x) assert x.a == 2 assert x.b == 1 } @@ -72,7 +81,10 @@ fn foo3(mut f Foo) { } fn test_cross_assign_of_struct_in_fn() { - mut a := Foo{a:1, b:2} + mut a := Foo{ + a: 1 + b: 2 + } foo3(mut a) println(a) assert a.a == 2 @@ -82,8 +94,14 @@ fn test_cross_assign_of_struct_in_fn() { // Test cross assign of mixed types fn test_cross_assign_of_mixed_types() { mut a := [0, 1] - mut m := {'one':1, 'two':2} - mut x := Zoo{a:1, b:2} + mut m := map{ + 'one': 1 + 'two': 2 + } + mut x := Zoo{ + a: 1 + b: 2 + } a[0], m['one'], x.a, a[1], m['two'], x.b = a[1], m['two'], x.b, a[0], m['one'], x.a @@ -95,14 +113,20 @@ fn test_cross_assign_of_mixed_types() { } // Test cross assign of mixed types in function -fn foo(mut a []int, mut m map[string]int, mut x Zoo) { +fn foo(mut a []int, mut m map[string]int, mut x Zoo) { a[0], m['one'], x.a, a[1], m['two'], x.b = a[1], m['two'], x.b, a[0], m['one'], x.a } fn test_cross_assign_of_mixed_types_in_fn() { mut a := [0, 1] - mut m := {'one':1, 'two':2} - mut x := Zoo{a:1, b:2} + mut m := map{ + 'one': 1 + 'two': 2 + } + mut x := Zoo{ + a: 1 + b: 2 + } foo(mut a, mut m, mut x) @@ -116,10 +140,16 @@ fn test_cross_assign_of_mixed_types_in_fn() { // Test cross assign of complex types fn test_cross_assign_of_complex_types() { mut a := [0, 1] - mut m := {'one':1, 'two':2} - mut x := Zoo{a:1, b:2} + mut m := map{ + 'one': 1 + 'two': 2 + } + mut x := Zoo{ + a: 1 + b: 2 + } - a[0], m['one'], x.a, a[1], m['two'], x.b = a[1]+1, -m['two'], x.b, a[0]*2, m['one']*3, x.a-x.b + a[0], m['one'], x.a, a[1], m['two'], x.b = a[1] + 1, -m['two'], x.b, a[0] * 2, m['one'] * 3, x.a - x.b assert a == [2, 0] assert m['one'] == -2 diff --git a/vlib/v/tests/cstrings_test.v b/vlib/v/tests/cstrings_test.v index f2742a4da2..8c35241950 100644 --- a/vlib/v/tests/cstrings_test.v +++ b/vlib/v/tests/cstrings_test.v @@ -1,8 +1,8 @@ fn test_cstring() { w := c'world' - hlen := unsafe{ C.strlen(c'hello') } - hlen2 := unsafe{ C.strlen('hello') } - wlen := unsafe{ C.strlen(w) } + hlen := unsafe { C.strlen(c'hello') } + hlen2 := unsafe { C.strlen('hello') } + wlen := unsafe { C.strlen(w) } assert hlen == 5 assert hlen2 == 5 assert wlen == 5 diff --git a/vlib/v/tests/defer_test.v b/vlib/v/tests/defer_test.v index 32e85ea6df..d01e6b7b39 100644 --- a/vlib/v/tests/defer_test.v +++ b/vlib/v/tests/defer_test.v @@ -59,7 +59,7 @@ fn test_defer_early_exit() { fn test_defer_option() { mut ok := Num{0} - set_num_opt(mut ok) or { } + set_num_opt(mut ok) or {} assert ok.val == 1 } diff --git a/vlib/v/tests/enum_default_value_in_struct_test.v b/vlib/v/tests/enum_default_value_in_struct_test.v index b59be58176..1d29154820 100644 --- a/vlib/v/tests/enum_default_value_in_struct_test.v +++ b/vlib/v/tests/enum_default_value_in_struct_test.v @@ -27,7 +27,7 @@ fn test_enum_non_default_value() { assert 't.e: $t.e | int(t.e): ${int(t.e).str()}' == 't.e: third | int(t.e): 22' } -fn test_generation_of_string_interpolation_method_for_pointer_to_struct_containing_enum_fields(){ +fn test_generation_of_string_interpolation_method_for_pointer_to_struct_containing_enum_fields() { t := &MyStruct{ e: .third } diff --git a/vlib/v/tests/fixed_array_test.v b/vlib/v/tests/fixed_array_test.v index 843a2c3ead..5fea6caac2 100644 --- a/vlib/v/tests/fixed_array_test.v +++ b/vlib/v/tests/fixed_array_test.v @@ -2,7 +2,7 @@ fn test_fixed_array_can_be_assigned() { x := 2.32 mut v := [8]f64{} assert v[1] == 0 - v = [1.0, x, 3.0,4.0,5.0,6.0,7.0,8.0]! + v = [1.0, x, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]! assert v[1] == x v[1] = 2.0 for i, e in v { @@ -41,14 +41,13 @@ fn test_fixed_array_assignment() { fn test_fixed_array_can_be_used_in_declaration() { x := 2.32 - v := [1.0, x, 3.0,4.0,5.0,6.0,7.0,8.0]! + v := [1.0, x, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]! assert v.len == 8 assert v[1] == x } - struct Context { - pub mut: +pub mut: vb [8]f64 } @@ -72,7 +71,7 @@ fn test_fixed_array_can_be_assigned_to_a_struct_field() { } fn multiply_by_two(mut arr [3]int) { - for i in 0..arr.len { + for i in 0 .. arr.len { arr[i] *= 2 } } @@ -82,12 +81,12 @@ fn change_first_element(mut arr [3][3]int) { } fn test_fixed_array_can_be_passed_as_mut_arg() { - mut arr := [1,2,3]! + mut arr := [1, 2, 3]! multiply_by_two(mut arr) - assert arr == [2,4,6]! - mut arr2 := [[1,2,3]!, [4,5,6]!, [7,8,9]!]! + assert arr == [2, 4, 6]! + mut arr2 := [[1, 2, 3]!, [4, 5, 6]!, [7, 8, 9]!]! change_first_element(mut arr2) - assert arr2 == [[0,2,3]!, [4,5,6]!, [7,8,9]!]! + assert arr2 == [[0, 2, 3]!, [4, 5, 6]!, [7, 8, 9]!]! } fn test_iteration_over_fixed_array() { @@ -117,7 +116,6 @@ fn calc_size(a [3]int) { } fn test_for_in_fixed_array() { - arr := [1,2,3]! + arr := [1, 2, 3]! calc_size(arr) } - diff --git a/vlib/v/tests/fn_assignment_test.v b/vlib/v/tests/fn_assignment_test.v index 10abb61cdb..d61c4e5ca2 100644 --- a/vlib/v/tests/fn_assignment_test.v +++ b/vlib/v/tests/fn_assignment_test.v @@ -9,9 +9,9 @@ fn test1() int { fn test_fn_assignment_var() { mut a := 0 mut b := 0 - a , b = test(), test1() - - assert a == 10 + a, b = test(), test1() + + assert a == 10 assert b == 11 a, b = test(), test() @@ -20,13 +20,13 @@ fn test_fn_assignment_var() { a, b = test(), 12 - assert a == 10 + assert a == 10 assert b == 12 a, b = 12, test() assert a == 12 - assert b == 10 + assert b == 10 } fn test_fn_assignment_array() { @@ -34,22 +34,20 @@ fn test_fn_assignment_array() { a[0], a[1] = test(), test1() - assert a[0] == 10 + assert a[0] == 10 assert a[1] == 11 - a[0], a[1] = test() , test() + a[0], a[1] = test(), test() - assert a[0] == 10 - assert a[1] == 10 + assert a[0] == 10 + assert a[1] == 10 a[0], a[1] = test(), 12 - assert a[0] == 10 - assert a[1] == 12 + assert a[0] == 10 + assert a[1] == 12 - a[0], a[1] = 12 , test() - assert a[0] == 12 + a[0], a[1] = 12, test() + assert a[0] == 12 assert a[1] == 10 } - - diff --git a/vlib/v/tests/fn_cross_assign_test.v b/vlib/v/tests/fn_cross_assign_test.v index 7b1e708510..d286308379 100644 --- a/vlib/v/tests/fn_cross_assign_test.v +++ b/vlib/v/tests/fn_cross_assign_test.v @@ -1,9 +1,8 @@ - -fn cross_assign_anon_fn_one (a int, b bool) string { +fn cross_assign_anon_fn_one(a int, b bool) string { return 'one' } -fn cross_assign_anon_fn_two (a int, b bool) string { +fn cross_assign_anon_fn_two(a int, b bool) string { return 'two' } @@ -23,11 +22,11 @@ fn cross_assign_anon_fn_six(a ...int) string { return 'six' } -fn cross_assign_anon_fn_seven (a int, b bool) string { +fn cross_assign_anon_fn_seven(a int, b bool) string { return 'seven' } -fn cross_assign_anon_fn_eight (a int, b bool) string { +fn cross_assign_anon_fn_eight(a int, b bool) string { return 'eight' } @@ -37,7 +36,7 @@ fn test_cross_assign_anon_fn() { one, two = two, one foo := two(0, true) + one(0, true) assert foo == 'onetwo' - + mut three := cross_assign_anon_fn_three mut four := cross_assign_anon_fn_four three, four = four, three @@ -47,20 +46,20 @@ fn test_cross_assign_anon_fn() { foo3 += foo5 assert foo2 == 'threefour' assert foo3 == 'threefour' - + mut five := cross_assign_anon_fn_five mut six := cross_assign_anon_fn_six five, six = six, five foo6 := six(1, 2, 3) + five(1, 2, 3) assert foo6 == 'fivesix' - + one, two, three, four, five, six = two, one, four, three, six, five mut foo7, _ := three() foo8, _ := four() foo7 += foo8 foo9 := one(0, true) + two(0, true) + foo7 + five(1, 2, 3) + six(1, 2, 3) assert foo9 == 'onetwothreefourfivesix' - + mut seven := cross_assign_anon_fn_seven mut eight := cross_assign_anon_fn_eight one, two, seven, eight = two, seven, eight, one diff --git a/vlib/v/tests/fn_expecting_ref_but_returning_struct_test.v b/vlib/v/tests/fn_expecting_ref_but_returning_struct_test.v index 19dc0fb0b7..98c5c71855 100644 --- a/vlib/v/tests/fn_expecting_ref_but_returning_struct_test.v +++ b/vlib/v/tests/fn_expecting_ref_but_returning_struct_test.v @@ -2,10 +2,12 @@ struct Foo { x int } -pub fn (f Foo) str() string { return 'Foo{}' } +pub fn (f Foo) str() string { + return 'Foo{}' +} fn process_foo(foo &Foo) { - println('>process_foo, called for ${foo} === ${*foo}') + println('>process_foo, called for $foo === ${*foo}') } fn get_foo() Foo { diff --git a/vlib/v/tests/fn_high_test.v b/vlib/v/tests/fn_high_test.v index ac06b9f826..20e49f950d 100644 --- a/vlib/v/tests/fn_high_test.v +++ b/vlib/v/tests/fn_high_test.v @@ -3,50 +3,51 @@ fn sqr(x int) int { return x * x } -fn high_fn(f fn(int) int) { +fn high_fn(f fn (int) int) { x := f(111) println('x == $x') } -fn high_fn_no_ret(f fn(int)) { +fn high_fn_no_ret(f fn (int)) { f(111) } fn high_fn_array(f fn(a []int) []int) { - } fn high_fn_multi_return(a int, b fn (c []int, d []string) ([]int, []string)) { - } -fn high_fn_return_single_anon() (fn(int)f32) { +fn high_fn_return_single_anon() fn (int) f32 { _ = 1 - correct := fn(n int)f32 { + correct := fn (n int) f32 { return f32(n * n) } return correct } -fn high_fn_return_multi_anons() (fn(int)f32, fn(int)string) { + +fn high_fn_return_multi_anons() (fn (int) f32, fn (int) string) { // parsing trap - _ = fn(n int)byte { + _ = fn (n int) byte { return 0x00 } - correct_second := fn(n int)string { + correct_second := fn (n int) string { return '$n' } - correct_first := fn(n int)f32 { + correct_first := fn (n int) f32 { return f32(n * n) } // parsing trap - _ = fn(n int)[]int { + _ = fn (n int) []int { return [n] } return correct_first, correct_second } -fn high_fn_return_named_fn() (fn(int)int) { + +fn high_fn_return_named_fn() fn (int) int { return sqr } + fn test_high_fn_ret_anons() { param := 13 func_sqr1 := high_fn_return_single_anon() @@ -63,6 +64,7 @@ fn test_high_fn_ret_anons() { fn high_fn_applier(arg int, func fn(a int)string) string { return func(arg) } + fn test_high_fn_applier() { arg := 13 expect := '$arg $arg' @@ -78,12 +80,12 @@ fn test_fns() { } fn test_anon_fn() { - f1 := fn(a int){ + f1 := fn (a int) { println('hello from f1') } f1(1) - f2 := fn(a int) int { + f2 := fn (a int) int { println('hello from f2') return 10 } @@ -102,12 +104,12 @@ fn test_anon_fn() { } fn test_anon_fn_direct_call() { - fn(name string) { + fn (name string) { println('hello $name') }('from anon') - - b := fn(n int) int { - return 11+n + + b := fn (n int) int { + return 11 + n }(100) assert b == 111 } @@ -121,7 +123,7 @@ fn simple_fn1() int { } fn simple_fn2(n f32) (int, string) { - return int(1 + n), "fish" + return int(1 + n), 'fish' } fn test_assigning_fns() { @@ -131,13 +133,13 @@ fn test_assigning_fns() { func2 := simple_fn2 res2_1, res2_2 := func2(13.0) assert res2_1 == 14.0 - assert res2_2 == "fish" + assert res2_2 == 'fish' - anon_func1 := fn(s string)int { + anon_func1 := fn (s string) int { return s.len } func3 := anon_func1 - res3 := func3("fish") + res3 := func3('fish') assert res3 == 4 } diff --git a/vlib/v/tests/fn_index_direct_call_test.v b/vlib/v/tests/fn_index_direct_call_test.v index ab0b26f8d5..bef34a404a 100644 --- a/vlib/v/tests/fn_index_direct_call_test.v +++ b/vlib/v/tests/fn_index_direct_call_test.v @@ -1,29 +1,33 @@ struct Placeholder { - name string + name string } struct FnStruct { mut: - array_of_fn []fn(int, &Placeholder, string)bool + array_of_fn []fn (int, &Placeholder, string) bool } fn test_fn_array_direct_call() { - mut fs := FnStruct{} - fs.array_of_fn << fn(x int, y &Placeholder, z string) bool { - return false - } + mut fs := FnStruct{} + fs.array_of_fn << fn (x int, y &Placeholder, z string) bool { + return false + } - println(fs.array_of_fn[0](1, &Placeholder{name: 'Bob'}, 'Builder')) - assert fs.array_of_fn[0](1, &Placeholder{name: 'Bob'}, 'Builder') == false + println(fs.array_of_fn[0](1, &Placeholder{ name: 'Bob' }, 'Builder')) + assert fs.array_of_fn[0](1, &Placeholder{ name: 'Bob' }, 'Builder') == false } fn test_fn_map_direct_call() { - a := { - 'aaa': fn()string {return 'aaa'}, - 'bbb': fn()string {return 'bbb'}, + a := map{ + 'aaa': fn () string { + return 'aaa' + } + 'bbb': fn () string { + return 'bbb' + } } println(a['aaa']()) - println(a['bbb']()) - assert a['aaa']() == 'aaa' - assert a['bbb']() == 'bbb' + println(a['bbb']()) + assert a['aaa']() == 'aaa' + assert a['bbb']() == 'bbb' } diff --git a/vlib/v/tests/fn_multiple_returns_test.v b/vlib/v/tests/fn_multiple_returns_test.v index 407094923c..eaac1338e1 100644 --- a/vlib/v/tests/fn_multiple_returns_test.v +++ b/vlib/v/tests/fn_multiple_returns_test.v @@ -14,7 +14,9 @@ fn test_fn_multiple_returns() { fn fn_mr_get_user() (string, int, []string, UserData) { groups := ['admins', 'users'] - data := UserData{test: 'Test Data'} + data := UserData{ + test: 'Test Data' + } return 'joe', 34, groups, data } @@ -30,9 +32,7 @@ fn split_to_two(s string) ?(string, string) { } fn returnable_fail() string { - _,_ := split_to_two('bad') or { - return 'ok' - } + _, _ := split_to_two('bad') or { return 'ok' } return 'nok' } @@ -41,7 +41,7 @@ fn test_multiple_ret() { assert returnable_fail() == 'ok' // good case - res1_1, res1_2 := split_to_two("fish house") or { + res1_1, res1_2 := split_to_two('fish house') or { assert false return } @@ -49,8 +49,8 @@ fn test_multiple_ret() { assert res1_2 == 'house' // none case - wrapper1 := fn()(string, string){ - res2_1, res2_2 := split_to_two("") or { + wrapper1 := fn () (string, string) { + res2_1, res2_2 := split_to_two('') or { assert err.msg == '' return 'replaced', 'val' } @@ -61,7 +61,7 @@ fn test_multiple_ret() { assert res2_2 == 'val' // error case - wrapper2 := fn()(string, string){ + wrapper2 := fn () (string, string) { res3_1, res3_2 := split_to_two('fishhouse') or { assert err.msg == 'error' return 'replaced', 'val' diff --git a/vlib/v/tests/fn_mut_args_test.v b/vlib/v/tests/fn_mut_args_test.v index d6dfa7ddf9..9f41b19461 100644 --- a/vlib/v/tests/fn_mut_args_test.v +++ b/vlib/v/tests/fn_mut_args_test.v @@ -12,12 +12,16 @@ fn test_fn_mut_args_of_array() { } fn init_map(mut n map[string]int) { - n = {'one': 1} + n = map{ + 'one': 1 + } } fn test_fn_mut_args_of_map() { mut m := map[string]int{} init_map(mut m) println(m) - assert m == {'one': 1} + assert m == map{ + 'one': 1 + } } diff --git a/vlib/v/tests/fn_shared_return_test.v b/vlib/v/tests/fn_shared_return_test.v index 99391f06dc..4df897f977 100644 --- a/vlib/v/tests/fn_shared_return_test.v +++ b/vlib/v/tests/fn_shared_return_test.v @@ -4,7 +4,9 @@ mut: } fn f() shared St { - shared x := St{ x: 3.25 } + shared x := St{ + x: 3.25 + } return x } @@ -12,19 +14,25 @@ fn g(good bool) ?shared St { if !good { return error('no shared St created') } - shared x := St{ x: 12.75 } + shared x := St{ + x: 12.75 + } return x } fn test_shared_fn_return() { shared x := f() - val := rlock x { x.x } + val := rlock x { + x.x + } assert val == 3.25 } fn shared_opt_propagate(good bool) ?f64 { shared x := g(good) ? - ret := rlock x { x.x } + ret := rlock x { + x.x + } return ret } @@ -37,18 +45,26 @@ fn test_shared_opt_propagate() { fn test_shared_opt_good() { shared yy := g(true) or { - shared my_default := St{ x: 37.5 } - my_default + shared my_default := St{ + x: 37.5 + } + my_default + } + val := rlock yy { + yy.x } - val := rlock yy { yy.x } assert val == 12.75 } fn test_shared_opt_bad() { shared yy := g(false) or { - shared my_default := St{ x: 37.5 } - my_default + shared my_default := St{ + x: 37.5 + } + my_default + } + val := rlock yy { + yy.x } - val := rlock yy { yy.x } assert val == 37.5 } diff --git a/vlib/v/tests/fn_with_fixed_array_function_args_test.v b/vlib/v/tests/fn_with_fixed_array_function_args_test.v index 9ae80b975a..7b3439a353 100644 --- a/vlib/v/tests/fn_with_fixed_array_function_args_test.v +++ b/vlib/v/tests/fn_with_fixed_array_function_args_test.v @@ -7,7 +7,7 @@ fn foo2(a string) int { } fn bar1(mut a [1]fn (string) int) int { - a[0] = foo2 + a[0] = foo2 return a[0]('hello') } diff --git a/vlib/v/tests/for_c_multi_vars_test.v b/vlib/v/tests/for_c_multi_vars_test.v index 7e02fedf5e..aa53ffd94b 100644 --- a/vlib/v/tests/for_c_multi_vars_test.v +++ b/vlib/v/tests/for_c_multi_vars_test.v @@ -1,6 +1,6 @@ fn test_for_c_multi_init_vars() { mut rets := []string{} - for a,b := 0,1; a < 5; a++ { + for a, b := 0, 1; a < 5; a++ { if a == 3 { continue } @@ -18,7 +18,7 @@ fn test_for_c_multi_init_vars() { fn test_for_c_multi_inc_vars() { mut rets := []string{} mut b := 1 - for a := 0; a < 10; a,b = b,a+b { + for a := 0; a < 10; a, b = b, a + b { if a in [2, 3] { continue } diff --git a/vlib/v/tests/for_in_containers_of_fixed_array_test.v b/vlib/v/tests/for_in_containers_of_fixed_array_test.v index e40ebe782b..2971140a55 100644 --- a/vlib/v/tests/for_in_containers_of_fixed_array_test.v +++ b/vlib/v/tests/for_in_containers_of_fixed_array_test.v @@ -64,7 +64,11 @@ fn test_for_in_fixed_array_of_fixed_array_literal() { fn test_for_in_map_of_fixed_array() { mut rets := []string{} - m := map{'aa': [1, 2]!, 'bb': [3, 4]!, 'cc': [5, 6]!} + m := map{ + 'aa': [1, 2]! + 'bb': [3, 4]! + 'cc': [5, 6]! + } for k, v in m { println('$k, $v') @@ -78,7 +82,11 @@ fn test_for_in_map_of_fixed_array() { fn test_for_in_map_of_fixed_array_literal() { mut rets := []string{} - for k, v in map{'aa': [1, 2]!, 'bb': [3, 4]!, 'cc': [5, 6]!} { + for k, v in map{ + 'aa': [1, 2]! + 'bb': [3, 4]! + 'cc': [5, 6]! + } { println('$k, $v') rets << '$k, $v' } @@ -89,7 +97,11 @@ fn test_for_in_map_of_fixed_array_literal() { fn test_for_mut_in_map_of_fixed_array() { mut rets := []string{} - mut m := map{'aa': [1, 2]!, 'bb': [3, 4]!, 'cc': [5, 6]!} + mut m := map{ + 'aa': [1, 2]! + 'bb': [3, 4]! + 'cc': [5, 6]! + } for k, mut v in m { println('$k, $v') diff --git a/vlib/v/tests/for_in_iterator_test.v b/vlib/v/tests/for_in_iterator_test.v index 80f4af5827..03f546e480 100644 --- a/vlib/v/tests/for_in_iterator_test.v +++ b/vlib/v/tests/for_in_iterator_test.v @@ -1,6 +1,6 @@ struct Doubler { mut: - val int + val int until int } diff --git a/vlib/v/tests/for_in_mut_val_test.v b/vlib/v/tests/for_in_mut_val_test.v index a7f35ae9e4..b89b317f48 100644 --- a/vlib/v/tests/for_in_mut_val_test.v +++ b/vlib/v/tests/for_in_mut_val_test.v @@ -18,40 +18,47 @@ fn foo2(mut arr [3]int) { } fn test_for_in_mut_val_of_fixed_array() { - mut arr := [1,2,3]! + mut arr := [1, 2, 3]! foo2(mut arr) println(arr) assert arr == [2, 4, 6]! } -fn foo3(mut m map[string][3]int){ - for i in 0..m['hello'].len { +fn foo3(mut m map[string][3]int) { + for i in 0 .. m['hello'].len { m['hello'][i] *= 2 } } fn test_fn_mut_val_of_map() { - mut m := {'hello': [1,2,3]!} + mut m := map{ + 'hello': [1, 2, 3]! + } foo3(mut m) println(m) assert '$m' == "{'hello': [2, 4, 6]}" } -fn foo4(mut m map[string][3]int){ +fn foo4(mut m map[string][3]int) { for _, mut j in m['hello'] { j *= 2 } } fn test_for_in_mut_val_of_map() { - mut m := {'hello':[1,2,3]!} + mut m := map{ + 'hello': [1, 2, 3]! + } foo4(mut m) println(m) assert '$m' == "{'hello': [2, 4, 6]}" } fn test_for_in_mut_val_of_map_direct() { - mut m := {'foo': 1, 'bar': 2} + mut m := map{ + 'foo': 1 + 'bar': 2 + } for _, mut j in m { j = 3 } @@ -60,9 +67,18 @@ fn test_for_in_mut_val_of_map_direct() { } fn test_for_in_mut_val_of_map_fixed_array() { - mut m := {'foo': [{'a': 1}]!, 'bar': [{'b': 2}]!} + mut m := map{ + 'foo': [map{ + 'a': 1 + }]! + 'bar': [map{ + 'b': 2 + }]! + } for _, mut j in m { - j = [{'c': 3}]! + j = [map{ + 'c': 3 + }]! } println(m) assert '$m' == "{'foo': [{'c': 3}], 'bar': [{'c': 3}]}" diff --git a/vlib/v/tests/for_label_continue_break_test.v b/vlib/v/tests/for_label_continue_break_test.v index 098124ee79..f7f01f2cd3 100644 --- a/vlib/v/tests/for_label_continue_break_test.v +++ b/vlib/v/tests/for_label_continue_break_test.v @@ -62,7 +62,14 @@ fn test_for_in_fixed_array_label_continue_break() { fn test_for_in_map_label_continue_break() { mut rets := []string{} - m := map{'a': 4, 'b': 5, 'c': 6, 'd': 7, 'e': 8, 'f': 9} + m := map{ + 'a': 4 + 'b': 5 + 'c': 6 + 'd': 7 + 'e': 8 + 'f': 9 + } outer: for k, v in m { println('$k, $v') rets << '$k, $v' diff --git a/vlib/v/tests/for_loops_test.v b/vlib/v/tests/for_loops_test.v index 75e0250596..b09bd2819a 100644 --- a/vlib/v/tests/for_loops_test.v +++ b/vlib/v/tests/for_loops_test.v @@ -44,7 +44,7 @@ fn test_for_char_in_string() { } fn test_for_string_in_map() { - m := { + m := map{ 'a': 'b' 'c': 'd' } @@ -54,7 +54,11 @@ fn test_for_string_in_map() { } assert acc == 'a: b, c: d, ' - mut m2 := {'a': 3, 'b': 4, 'c': 5} + mut m2 := map{ + 'a': 3 + 'b': 4 + 'c': 5 + } m2.delete('b') acc = '' for k, v in m2 { diff --git a/vlib/v/tests/for_smartcast_test.v b/vlib/v/tests/for_smartcast_test.v index 1e2d66c0bd..ea327cb925 100644 --- a/vlib/v/tests/for_smartcast_test.v +++ b/vlib/v/tests/for_smartcast_test.v @@ -2,6 +2,7 @@ type Node = Expr | string type Expr = IfExpr | IntegerLiteral struct IntegerLiteral {} + struct IfExpr { pos int } @@ -11,7 +12,9 @@ struct NodeWrapper { } fn test_nested_sumtype_selector() { - c := NodeWrapper{Node(Expr(IfExpr{pos: 1}))} + c := NodeWrapper{Node(Expr(IfExpr{ + pos: 1 + }))} for c.node is Expr { assert typeof(c.node).name == 'Expr' break @@ -28,7 +31,7 @@ mut: name string } -type Food = Milk | Eggs +type Food = Eggs | Milk struct FoodWrapper { mut: diff --git a/vlib/v/tests/generic_fn_returning_type_with_T_test.v b/vlib/v/tests/generic_fn_returning_type_with_T_test.v index 5685f86c82..d7a144a1ba 100644 --- a/vlib/v/tests/generic_fn_returning_type_with_T_test.v +++ b/vlib/v/tests/generic_fn_returning_type_with_T_test.v @@ -1,32 +1,40 @@ -struct BuildData { x int } -struct Tensor { x int } +struct BuildData { + x int +} + +struct Tensor { + x int +} + fn new_tensor(data BuildData) Tensor { println('data: $data') x := T(data.x) - println(x) - return Tensor{ data.x } + println(x) + return Tensor{data.x} } + fn test_generic_function_returning_type_starting_with_t() { - ft := new_tensor(x:123) + ft := new_tensor(x: 123) println(ft) - assert typeof(ft).name == 'Tensor' - assert '$ft' == 'Tensor{\n x: 123\n}' - // - it := new_tensor(x:456) + assert typeof(ft).name == 'Tensor' + assert '$ft' == 'Tensor{\n x: 123\n}' + // + it := new_tensor(x: 456) println(it) - assert typeof(it).name == 'Tensor' - assert '$it' == 'Tensor{\n x: 456\n}' + assert typeof(it).name == 'Tensor' + assert '$it' == 'Tensor{\n x: 456\n}' } // the following verifies that returning a generic type T // works at the same time as returning a type starting with T fn new_t(o T) T { x := T(o) - return x + return x } + fn test_generic_function_returning_t_type() { f := new_t(1.23) - i := new_t(456) - assert '$f' == '1.23' - assert '$i' == '456' + i := new_t(456) + assert '$f' == '1.23' + assert '$i' == '456' } diff --git a/vlib/v/tests/generic_fn_upper_name_type_test.v b/vlib/v/tests/generic_fn_upper_name_type_test.v index 77952e9733..c2da577386 100644 --- a/vlib/v/tests/generic_fn_upper_name_type_test.v +++ b/vlib/v/tests/generic_fn_upper_name_type_test.v @@ -11,8 +11,8 @@ fn show_result(x T, y U) bool { } fn test_generic_fn_upper_name_type() { - assert show_result(1, false) - assert show_result( "s", XX{}) - assert show_result< XX, string>(XX{}, "s") - assert show_result< XX, YY>(XX{}, YY{}) + assert show_result(1, false) + assert show_result('s', XX{}) + assert show_result(XX{}, 's') + assert show_result(XX{}, YY{}) } diff --git a/vlib/v/tests/generic_functions_with_normal_function_test.v b/vlib/v/tests/generic_functions_with_normal_function_test.v index 45ab2c42b2..aa1543df13 100644 --- a/vlib/v/tests/generic_functions_with_normal_function_test.v +++ b/vlib/v/tests/generic_functions_with_normal_function_test.v @@ -1,9 +1,9 @@ fn get(typ T) T { - return typ + return typ } fn get_string(typ string) string { - return 'boom' + return 'boom' } fn test_generic_with_same_type() { diff --git a/vlib/v/tests/generics_from_modules/inference_test.v b/vlib/v/tests/generics_from_modules/inference_test.v index e2c49dbc56..e18a7707b4 100644 --- a/vlib/v/tests/generics_from_modules/inference_test.v +++ b/vlib/v/tests/generics_from_modules/inference_test.v @@ -1,6 +1,6 @@ module main -import genericmodule +import v.tests.generics_from_modules.genericmodule fn test_generic_function_from_another_module() { v1 := genericmodule.take(true, 10, 20) diff --git a/vlib/v/tests/generics_test.v b/vlib/v/tests/generics_test.v index fa4d629dd9..dc28b214d2 100644 --- a/vlib/v/tests/generics_test.v +++ b/vlib/v/tests/generics_test.v @@ -11,9 +11,11 @@ fn test_identity() { assert simple('g') + 'h' == 'gh' assert simple<[]int>([1])[0] == 1 - assert simple({'a':'b'})['a'] == 'b' + assert simple(map{ + 'a': 'b' + })['a'] == 'b' - assert simple(simplemodule.Data{value: 0}).value == 0 + assert simple(simplemodule.Data{ value: 0 }).value == 0 } fn plus(xxx T, b T) T { @@ -118,16 +120,18 @@ fn test_return_array() { } fn opt(v T) ?T { - if sizeof(T) > 1 {return v} + if sizeof(T) > 1 { + return v + } return none } fn test_optional() { s := opt('hi') or { '' } assert s == 'hi' - i := opt(5) or {0} + i := opt(5) or { 0 } assert i == 5 - b := opt(s[0]) or {99} + b := opt(s[0]) or { 99 } assert b == 99 } @@ -141,7 +145,7 @@ fn test_ptr() { assert *ptr('aa') == 'aa' } -fn map_f(l []T, f fn(T)U) []U { +fn map_f(l []T, f fn (T) U) []U { mut r := []U{} for e in l { r << f(e) @@ -159,11 +163,11 @@ fn foldl(l []T, nil T, f fn(T,T)T) T { } */ fn square(x int) int { - return x*x + return x * x } fn mul_int(x int, y int) int { - return x*y + return x * y } fn assert_eq(a T, b T) { @@ -173,21 +177,21 @@ fn assert_eq(a T, b T) { fn print_nice(x T, indent int) string { mut space := '' - for _ in 0..indent { + for _ in 0 .. indent { space = space + ' ' } return '$space$x' } fn test_generic_fn() { - assert_eq(simple(0+1), 1) + assert_eq(simple(0 + 1), 1) assert_eq(simple('g') + 'h', 'gh') - assert_eq(sum([5.1,6.2,7.0]), 18.3) + assert_eq(sum([5.1, 6.2, 7.0]), 18.3) assert_eq(plus(i64(4), i64(6)), i64(10)) - a := [1,2,3,4] + a := [1, 2, 3, 4] b := map_f(a, square) assert_eq(sum(b), 30) // 1+4+9+16 = 30 - //assert_eq(foldl(b, 1, mul_int), 576) // 1*4*9*16 = 576 + // assert_eq(foldl(b, 1, mul_int), 576) // 1*4*9*16 = 576 assert print_nice('str', 8) == ' str' } @@ -243,7 +247,7 @@ pub mut: } struct Repo { - db DB + db DB pub mut: model T permission U @@ -254,13 +258,13 @@ pub mut: // return Repo{db: db} // } fn test_generic_struct() { - mut a := Repo{ + mut a := Repo{ model: User{ name: 'joe' } } assert a.model.name == 'joe' - mut b := Repo{ + mut b := Repo{ permission: Permission{ name: 'superuser' } @@ -292,11 +296,10 @@ fn test_struct_from_other_module() { } fn test_generic_struct_print_array_as_field() { - foo := Foo<[]string>{ - data: []string{} - } + foo := Foo<[]string>{ + data: []string{} + } assert foo.str() == 'Foo{\n data: []\n}' - } /* @@ -338,7 +341,7 @@ fn test(mut app T) { } fn nested_test(mut app T) { - app.context = Context {} + app.context = Context{} } fn test_pass_generic_to_nested_function() { @@ -361,10 +364,13 @@ fn method_test(mut app T) { fn test_pass_generic_to_nested_method() { mut app := App{} method_test(mut app) -}*/ +} +*/ fn generic_return_map() map[string]M { - return {'': M{}} + return map{ + '': M{} + } } fn test_generic_return_map() { @@ -372,7 +378,11 @@ fn test_generic_return_map() { } fn generic_return_nested_map() map[string]map[string]M { - return {'': {'': M{}}} + return map{ + '': map{ + '': M{} + } + } } fn test_generic_return_nested_map() { @@ -383,10 +393,13 @@ fn multi_return() (A, B) { return A{}, B{} } -struct Foo1{} -struct Foo2{} -struct Foo3{} -struct Foo4{} +struct Foo1 {} + +struct Foo2 {} + +struct Foo3 {} + +struct Foo4 {} fn test_multi_return() { // compiles @@ -399,7 +412,7 @@ fn multi_generic_args(t T, v V) bool { } fn test_multi_generic_args() { - assert multi_generic_args("Super", 2021) + assert multi_generic_args('Super', 2021) } fn new() T { @@ -429,9 +442,9 @@ fn test_generic_detection() { v1, v2 := -1, 1 // not generic - a1, a2 := v1 v1 + a1, a2 := v1 < v2, v2 > v1 assert a1 && a2 - b1, b2 := v1 v1 + b1, b2 := v1 < simplemodule.zero, v2 > v1 assert b1 && b2 // generic diff --git a/vlib/v/tests/go_array_wait_test.v b/vlib/v/tests/go_array_wait_test.v index af630ad3bb..d5513ca53c 100644 --- a/vlib/v/tests/go_array_wait_test.v +++ b/vlib/v/tests/go_array_wait_test.v @@ -5,7 +5,7 @@ fn f(x f64) f64 { fn test_array_thread_f64_wait() { mut r := []thread f64{cap: 10} - for i in 0 .. 10 { + for i in 0 .. 10 { r << go f(f64(i) + 0.5) } x := r.wait() @@ -19,15 +19,15 @@ fn g(shared a []int, i int) { } fn test_array_thread_void_wait() { - shared a := [2 3 5 7 11 13 17] + shared a := [2, 3, 5, 7, 11, 13, 17] t := [ - go g(shared a, 0) - go g(shared a, 3) - go g(shared a, 6) - go g(shared a, 2) - go g(shared a, 1) - go g(shared a, 5) - go g(shared a, 4) + go g(shared a, 0), + go g(shared a, 3), + go g(shared a, 6), + go g(shared a, 2), + go g(shared a, 1), + go g(shared a, 5), + go g(shared a, 4), ] println('threads started') t.wait() @@ -37,7 +37,7 @@ fn test_array_thread_void_wait() { } fn test_void_thread_decl() { - shared a := [2 3 9] + shared a := [2, 3, 9] mut t1 := thread(0) mut tarr := []thread{len: 2} t1 = go g(shared a, 0) diff --git a/vlib/v/tests/if_expr_of_optional_test.v b/vlib/v/tests/if_expr_of_optional_test.v index dad9b36d5c..724d83c9d9 100644 --- a/vlib/v/tests/if_expr_of_optional_test.v +++ b/vlib/v/tests/if_expr_of_optional_test.v @@ -1,13 +1,13 @@ fn foo1() ?int { - return if true { 0 } else { none } + return if true { 0 } else { none } } fn foo2() ?int { - return if true { 1 } else { error('foo2 error') } + return if true { 1 } else { error('foo2 error') } } fn foo3() ?int { - return if false { 1 } else { error('foo3 error') } + return if false { 1 } else { error('foo3 error') } } fn foo4() ?int { diff --git a/vlib/v/tests/if_guard_test.v b/vlib/v/tests/if_guard_test.v index 77f8ae11e1..7d5fcf7664 100644 --- a/vlib/v/tests/if_guard_test.v +++ b/vlib/v/tests/if_guard_test.v @@ -6,7 +6,7 @@ fn f(n int) ?f64 { } fn test_fn_return() { - mut res := []f64{cap:2} + mut res := []f64{cap: 2} for m in [-3, 5] { if x := f(m) { res << x @@ -18,8 +18,11 @@ fn test_fn_return() { } fn test_map_get() { - mut m := {'xy': 5, 'zu': 7} - mut res := []int{cap:2} + mut m := map{ + 'xy': 5 + 'zu': 7 + } + mut res := []int{cap: 2} for k in ['jk', 'zu'] { if x := m[k] { res << x @@ -32,7 +35,7 @@ fn test_map_get() { fn test_array_get() { mut a := [12.5, 6.5, -17.25] - mut res := []f64{cap:2} + mut res := []f64{cap: 2} for i in [1, 4] { if x := a[i] { res << x @@ -44,13 +47,13 @@ fn test_array_get() { } fn test_chan_pop() { - mut res := []f64{cap:3} + mut res := []f64{cap: 3} ch := chan f64{cap: 10} ch <- 6.75 ch <- -3.25 ch.close() for _ in 0 .. 3 { - if x:= <-ch { + if x := <-ch { res << x } else { res << -37.5 diff --git a/vlib/v/tests/if_smartcast_test.v b/vlib/v/tests/if_smartcast_test.v index 14b6306bb8..5a46729c7d 100644 --- a/vlib/v/tests/if_smartcast_test.v +++ b/vlib/v/tests/if_smartcast_test.v @@ -38,11 +38,11 @@ fn test_nested_if_smartcast() { } } -type Bar = string | Test +type Bar = Test | string type Xya = int | string struct Test { - x string + x string xya Xya } @@ -69,10 +69,12 @@ fn test_nested_selector_smartcast() { } type Inner = int | string + struct InnerStruct { x Inner } -type Outer = string | InnerStruct + +type Outer = InnerStruct | string fn test_nested_if_is() { b := Outer(InnerStruct{Inner(0)}) @@ -168,11 +170,13 @@ fn test_mutability() { } } -type Expr = CallExpr | CTempVarExpr +type Expr = CTempVarExpr | CallExpr + struct ExprWrapper { mut: expr Expr } + struct CallExpr { y int x string @@ -196,21 +200,21 @@ fn test_reassign_from_function_with_parameter_selector() { type Node = Expr | string fn test_nested_sumtype() { - c := Node(Expr(CallExpr{y: 1})) + c := Node(Expr(CallExpr{ + y: 1 + })) if c is Expr { if c is CallExpr { assert c.y == 1 - } - else { + } else { assert false } - } - else { + } else { assert false } } -type Food = Milk | Eggs +type Food = Eggs | Milk struct FoodWrapper { mut: @@ -240,16 +244,16 @@ struct NodeWrapper { } fn test_nested_sumtype_selector() { - c := NodeWrapper{Node(Expr(CallExpr{y: 1}))} + c := NodeWrapper{Node(Expr(CallExpr{ + y: 1 + }))} if c.node is Expr { if c.node is CallExpr { assert c.node.y == 1 - } - else { + } else { assert false } - } - else { + } else { assert false } } @@ -279,13 +283,17 @@ type SumAll = Sum1 | Sum2 struct All_in_one { pub mut: ptrs []&SumAll - ptr &SumAll + ptr &SumAll } fn test_nested_pointer_smartcast() { mut s := All_in_one{ - ptr: &Sum1(Foo1{a: 1}) - ptrs: [&SumAll(Sum2(Bar1{a: 3}))] + ptr: &Sum1(Foo1{ + a: 1 + }) + ptrs: [&SumAll(Sum2(Bar1{ + a: 3 + }))] } if mut s.ptr is Sum1 { @@ -296,7 +304,7 @@ fn test_nested_pointer_smartcast() { a := s.ptrs[0] if a is Sum1 { - if a is Foo1{ + if a is Foo1 { assert a.a == 3 } } diff --git a/vlib/v/tests/imported_symbols_test.v b/vlib/v/tests/imported_symbols_test.v index 17ec16952e..3ffb09b244 100644 --- a/vlib/v/tests/imported_symbols_test.v +++ b/vlib/v/tests/imported_symbols_test.v @@ -1,24 +1,33 @@ module main -import geometry { Point, Line, Shape, point_str, module_name } +import geometry { Line, Point, Shape, module_name, point_str } fn test_imported_symbols_types() { - // struct init - p0 := Point{x: 10 y: 20} - p1 := Point{x: 40 y: 60} - // array init - l0 := Line { - ps: [p0, p1] - } - assert l0.ps[0].y == 20 + // struct init + p0 := Point{ + x: 10 + y: 20 + } + p1 := Point{ + x: 40 + y: 60 + } + // array init + l0 := Line{ + ps: [p0, p1] + } + assert l0.ps[0].y == 20 } fn test_imported_symbols_functions() { - p0 := Point{x: 20 y: 40} + p0 := Point{ + x: 20 + y: 40 + } // method assert p0.str() == '20 40' // function - assert point_str(p0) == '20 40' + assert point_str(p0) == '20 40' } fn test_imported_symbols_constants() { diff --git a/vlib/v/tests/in_expression_test.v b/vlib/v/tests/in_expression_test.v index 8ad2f37475..9a4d363087 100644 --- a/vlib/v/tests/in_expression_test.v +++ b/vlib/v/tests/in_expression_test.v @@ -1,5 +1,8 @@ enum Colors { - red green blue yellow + red + green + blue + yellow } fn test_in_expression() { @@ -105,9 +108,9 @@ fn test_in_expression_with_string() { } fn test_in_expression_in_map() { - m := { - 'one': 1 - 'two': 2 + m := map{ + 'one': 1 + 'two': 2 'three': 3 } assert 'one' in m diff --git a/vlib/v/tests/inout/compiler_test.v b/vlib/v/tests/inout/compiler_test.v index 9e8aea8870..7545db39ea 100644 --- a/vlib/v/tests/inout/compiler_test.v +++ b/vlib/v/tests/inout/compiler_test.v @@ -21,9 +21,7 @@ fn test_all() { println('no compiler tests found') assert false } - paths := vtest.filter_vtest_only(tests, - basepath: dir - ) + paths := vtest.filter_vtest_only(tests, basepath: dir) for path in paths { print(path + ' ') program := path @@ -40,13 +38,13 @@ fn test_all() { panic(res.output) } $if windows { - os.rm('./test.exe') or { } + os.rm('./test.exe') or {} $if msvc { - os.rm('./test.ilk') or { } - os.rm('./test.pdb') or { } + os.rm('./test.ilk') or {} + os.rm('./test.pdb') or {} } } $else { - os.rm('./test') or { } + os.rm('./test') or {} } // println('============') // println(res.output) diff --git a/vlib/v/tests/interface_auto_str_gen_test.v b/vlib/v/tests/interface_auto_str_gen_test.v index 46a787391e..134f2e3d2e 100644 --- a/vlib/v/tests/interface_auto_str_gen_test.v +++ b/vlib/v/tests/interface_auto_str_gen_test.v @@ -1,5 +1,10 @@ -struct Dog { breed string } -struct Cat { breed string } +struct Dog { + breed string +} + +struct Cat { + breed string +} interface Animal { breed string @@ -19,15 +24,17 @@ struct Holder { } struct Holder2 { - x map[string]Holder + x map[string]Holder breed string } fn test_auto_str_gen_for_complex_interface_types() { a := Animal(Dog{'hi'}) h := Holder{a} - m := map{'dsa': h} - h2 := Holder2{ m, 'N/A' } + m := map{ + 'dsa': h + } + h2 := Holder2{m, 'N/A'} a2 := Animal(h2) assert '$a2' == r" diff --git a/vlib/v/tests/interface_struct_test.v b/vlib/v/tests/interface_struct_test.v index 7af23cae0f..b1478d1fba 100644 --- a/vlib/v/tests/interface_struct_test.v +++ b/vlib/v/tests/interface_struct_test.v @@ -39,7 +39,7 @@ fn test_interface_struct() { name: 'Richard' } } - assert bz1.sp.say_hello() == "Hello, My name is Richard and I\'m the bawz" + assert bz1.sp.say_hello() == "Hello, My name is Richard and I'm the bawz" print('Test Boss inside Baz struct: ') bz1.sp.speak('Hello world!') bz2 := Baz{ @@ -59,7 +59,7 @@ fn test_interface_mut_struct() { name: 'Derek' } } - assert mbaz.sp.say_hello() == "Hello, My name is Derek and I\'m the bawz" + assert mbaz.sp.say_hello() == "Hello, My name is Derek and I'm the bawz" mbaz.sp = Cat{ name: 'Dog' breed: 'Not a dog' @@ -82,7 +82,7 @@ fn test_interface_struct_from_array() { }, ] assert bazs[0].sp.say_hello() == 'Meow meow Kitty the Catty Koo meow' - assert bazs[1].sp.say_hello() == "Hello, My name is Bob and I\'m the bawz" + assert bazs[1].sp.say_hello() == "Hello, My name is Bob and I'm the bawz" } /* diff --git a/vlib/v/tests/interface_test.v b/vlib/v/tests/interface_test.v index 18adc6489d..317f510a9b 100644 --- a/vlib/v/tests/interface_test.v +++ b/vlib/v/tests/interface_test.v @@ -308,17 +308,17 @@ fn animal_match(a Animal) { interface II { mut: - my_field int + my_field int } struct AA { - BB + BB } struct BB { pad [10]byte mut: - my_field int + my_field int } fn main() { diff --git a/vlib/v/tests/local/local.v b/vlib/v/tests/local/local.v index 2acd61c0fa..98a82813fb 100644 --- a/vlib/v/tests/local/local.v +++ b/vlib/v/tests/local/local.v @@ -1,7 +1,5 @@ - module local pub fn local_fn() bool { return true } - diff --git a/vlib/v/tests/map_alias_key_test.v b/vlib/v/tests/map_alias_key_test.v index 91c750aea0..8c1ac0a307 100644 --- a/vlib/v/tests/map_alias_key_test.v +++ b/vlib/v/tests/map_alias_key_test.v @@ -2,21 +2,33 @@ type Type = int type RType = rune fn test_map_key_alias() { - mut m_int := map{12: '12', 2: '2'} + mut m_int := map{ + 12: '12' + 2: '2' + } m_int[14] = '14' m_int[Type(15)] = '15' assert m_int.str() == "{12: '12', 2: '2', 14: '14', 15: '15'}" //// /// ///// // - mut m_rune := map{`a`: '12', `l`: '14'} + mut m_rune := map{ + `a`: '12' + `l`: '14' + } m_rune[`g`] = '12' m_rune[RType(`$`)] = '16' assert m_rune.str() == "{`a`: '12', `l`: '14', `g`: '12', `$`: '16'}" } fn test_map_alias_key_init() { - m_int := map{Type(12): '12', Type(2): '2'} + m_int := map{ + Type(12): '12' + Type(2): '2' + } assert m_int.str() == "{12: '12', 2: '2'}" //// // ///// // - m_rune := map{RType(`a`): '12', RType(`l`): '14'} + m_rune := map{ + RType(`a`): '12' + RType(`l`): '14' + } assert m_rune.str() == "{`a`: '12', `l`: '14'}" } diff --git a/vlib/v/tests/map_and_array_with_fns_test.v b/vlib/v/tests/map_and_array_with_fns_test.v index 7e1cc4f5a0..b657dc8a52 100644 --- a/vlib/v/tests/map_and_array_with_fns_test.v +++ b/vlib/v/tests/map_and_array_with_fns_test.v @@ -37,9 +37,15 @@ fn test_array_with_fns() { } fn test_map_with_fns() { - mut a := {'one':foo, 'two':foo2} + mut a := map{ + 'one': foo + 'two': foo2 + } assert a.len == 2 - assert (a == {'one':foo, 'two':foo2}) == true + assert (a == map{ + 'one': foo + 'two': foo2 + }) == true f0 := a['one'] assert f0('xx', '') == 12 f1 := a['two'] @@ -49,7 +55,9 @@ fn test_map_with_fns() { assert f2('zzzz', '') == 24 f3 := a['two'] assert f3('aaaaa', '') == 15 - mut b := {'one':foo} + mut b := map{ + 'one': foo + } b['one'] = a['one'] f4 := b['one'] assert f4('bbbbbb', '') == 26 @@ -70,7 +78,9 @@ fn test_map_and_array_with_fns_typeof_and_direct_call() { a := [foo3] assert typeof(a).name == '[]fn (string) int' assert a[0]('hello') == 15 - b := {'one': foo3} + b := map{ + 'one': foo3 + } assert typeof(b).name == 'map[string]fn (string) int' assert b['one']('hi') == 12 } @@ -96,13 +106,17 @@ fn bar3(m map[string]fn (string) int) int { } fn bar4(mut m map[string]fn (string) int) int { - m['fn'] = foo4 + m['fn'] = foo4 return m['fn']('hi') } fn test_map_of_fns_as_argument() { - m1 := {'fn': foo3} + m1 := map{ + 'fn': foo3 + } assert bar3(m1) == 12 - mut m2 := {'fn': foo3} + mut m2 := map{ + 'fn': foo3 + } assert bar4(mut m2) == 22 } diff --git a/vlib/v/tests/map_complex_fixed_array_test.v b/vlib/v/tests/map_complex_fixed_array_test.v index 68db45af84..5dc95ec9d4 100644 --- a/vlib/v/tests/map_complex_fixed_array_test.v +++ b/vlib/v/tests/map_complex_fixed_array_test.v @@ -1,17 +1,25 @@ fn foo(mut m map[string][1][2]map[string]int) { - m['foo'] = [[{'bar': 1}, {'baz':3}]!]! + m['foo'] = [[map{ + 'bar': 1 + }, map{ + 'baz': 3 + }]!]! } fn test_complex_map_fixed_array() { - mut m := map[string][1][2]map[string]int + mut m := map[string][1][2]map[string]int{} foo(mut m) println(m) assert '$m' == "{'foo': [[{'bar': 1}, {'baz': 3}]]}" } fn test_innermost_value_of_map_fixed_array() { - mut m := map[string][1][2]map[string]int - m['foo'] = [[{'bar': 1}, {'baz': 3}]!]! + mut m := map[string][1][2]map[string]int{} + m['foo'] = [[map{ + 'bar': 1 + }, map{ + 'baz': 3 + }]!]! println(m['foo'][0][0]['bar']) println(m['foo'][0][0]['bar'] == 1) assert m['foo'][0][0]['bar'] == 1 @@ -19,9 +27,18 @@ fn test_innermost_value_of_map_fixed_array() { } fn test_complex_map_high_order_fixed_array() { - mut m := {'foo': [[{'a': 1}]!]!, 'bar': [[{'b': 2}]!]!} + mut m := map{ + 'foo': [[map{ + 'a': 1 + }]!]! + 'bar': [[map{ + 'b': 2 + }]!]! + } for _, mut j in m { - j = [[{'c': 3}]!]! + j = [[map{ + 'c': 3 + }]!]! } println(m) assert '$m' == "{'foo': [[{'c': 3}]], 'bar': [[{'c': 3}]]}" diff --git a/vlib/v/tests/map_equality_test.v b/vlib/v/tests/map_equality_test.v index 9c95a01aa2..d0864f2c13 100644 --- a/vlib/v/tests/map_equality_test.v +++ b/vlib/v/tests/map_equality_test.v @@ -1,18 +1,38 @@ fn test_map_equality() { - a1 := {'a':1, 'b':2} - b1 := {'b':2, 'a':1} - c1 := {'a':2, 'b':1} + a1 := map{ + 'a': 1 + 'b': 2 + } + b1 := map{ + 'b': 2 + 'a': 1 + } + c1 := map{ + 'a': 2 + 'b': 1 + } assert a1 == b1 assert a1 != c1 - a2 := {'a':1} - b2 := {'a':1, 'b':2} + a2 := map{ + 'a': 1 + } + b2 := map{ + 'a': 1 + 'b': 2 + } assert a2 != b2 - a3 := {'a':'1', 'b':'2'} - b3 := {'b':'2', 'a':'1'} + a3 := map{ + 'a': '1' + 'b': '2' + } + b3 := map{ + 'b': '2' + 'a': '1' + } assert a3 == b3 } diff --git a/vlib/v/tests/map_high_order_assign_test.v b/vlib/v/tests/map_high_order_assign_test.v index 024d7ef59d..1a5e679dba 100644 --- a/vlib/v/tests/map_high_order_assign_test.v +++ b/vlib/v/tests/map_high_order_assign_test.v @@ -1,5 +1,5 @@ fn test_high_order_map_assign() { - mut m := map[string]map[string]int + mut m := map[string]map[string]int{} m['hello']['hi'] = 1 println(m) assert '$m' == "{'hello': {'hi': 1}}" diff --git a/vlib/v/tests/map_key_expr_test.v b/vlib/v/tests/map_key_expr_test.v index 21bc17db8c..afa149b600 100644 --- a/vlib/v/tests/map_key_expr_test.v +++ b/vlib/v/tests/map_key_expr_test.v @@ -1,9 +1,9 @@ const ( alpha = 'a' - beta = 'b' - m = map{ - alpha : 'Alpha' - beta : 'Beta' + beta = 'b' + m = map{ + alpha: 'Alpha' + beta: 'Beta' } ) @@ -13,13 +13,14 @@ fn test_const_keys() { } enum Enum { - a b + a + b } const ( m2 = map{ - Enum.a.str() : 'first' - Enum.b.str() : 'second' + Enum.a.str(): 'first' + Enum.b.str(): 'second' } ) diff --git a/vlib/v/tests/map_to_string_test.v b/vlib/v/tests/map_to_string_test.v index c5a9859e0d..cbb8b39bd2 100644 --- a/vlib/v/tests/map_to_string_test.v +++ b/vlib/v/tests/map_to_string_test.v @@ -5,28 +5,33 @@ struct Test { } fn test_interpolation_map_to_string() { - mut a := map[string]string + mut a := map[string]string{} a['1'] = 'one' a['2'] = 'two' a['3'] = 'three' assert '$a' == "{'1': 'one', '2': 'two', '3': 'three'}" - mut b := map[string]int + mut b := map[string]int{} b['1'] = 1 b['2'] = 2 b['3'] = 3 assert '$b' == "{'1': 1, '2': 2, '3': 3}" - mut c := map[string]bool + mut c := map[string]bool{} c['1'] = true c['2'] = false assert '$c' == "{'1': true, '2': false}" - d := {'f1': 1.1, 'f2': 2.2, 'f3': 3.3, 'f4': 4.4} + d := map{ + 'f1': 1.1 + 'f2': 2.2 + 'f3': 3.3 + 'f4': 4.4 + } println('d: $d') assert '$d' == "{'f1': 1.1, 'f2': 2.2, 'f3': 3.3, 'f4': 4.4}" - mut e := map[string]Test + mut e := map[string]Test{} e['1'] = Test{true, 0, 'abc'} e['2'] = Test{true, 1, 'def'} e['3'] = Test{false, 2, 'ghi'} @@ -37,6 +42,8 @@ fn test_interpolation_map_to_string() { assert s.contains("}, '2': Test{") assert s.contains("y: 'def'") - f := {'hello': [1,2,3]!} + f := map{ + 'hello': [1, 2, 3]! + } assert '$f' == "{'hello': [1, 2, 3]}" } diff --git a/vlib/v/tests/map_type_alias_test.v b/vlib/v/tests/map_type_alias_test.v index 3c6d63b076..d55a542166 100644 --- a/vlib/v/tests/map_type_alias_test.v +++ b/vlib/v/tests/map_type_alias_test.v @@ -1,6 +1,8 @@ type Test = map[string]string fn test_index() { - t := Test({'c': 'abc'}) - assert t['c'] == 'abc' + t := Test(map{ + 'c': 'abc' + }) + assert t['c'] == 'abc' } diff --git a/vlib/v/tests/maps_equal_test.v b/vlib/v/tests/maps_equal_test.v index adcb14e8ec..fbbf8e5ffc 100644 --- a/vlib/v/tests/maps_equal_test.v +++ b/vlib/v/tests/maps_equal_test.v @@ -1,6 +1,10 @@ fn test_string_int() { - mut m := {'hi':4} - m2:= {'hi':5} + mut m := map{ + 'hi': 4 + } + m2 := map{ + 'hi': 5 + } assert m != m2 m['hi']++ assert m == m2 diff --git a/vlib/v/tests/match_expression_for_types_test.v b/vlib/v/tests/match_expression_for_types_test.v index a2b282f1a0..56bd4b4d0b 100644 --- a/vlib/v/tests/match_expression_for_types_test.v +++ b/vlib/v/tests/match_expression_for_types_test.v @@ -1,9 +1,10 @@ - type SumType = int | string -fn s2s(s SumType) SumType { return s } +fn s2s(s SumType) SumType { + return s +} -fn test_match_expression_on_sumtype_ordinary_branch(){ +fn test_match_expression_on_sumtype_ordinary_branch() { // tests whether an ordinary branch supports multiple statements, // followed by a default expression mut c := 0 @@ -13,7 +14,8 @@ fn test_match_expression_on_sumtype_ordinary_branch(){ c = 1 eprintln('hi') 'a string' - }else{ + } + else { 'unknown' } } @@ -21,8 +23,7 @@ fn test_match_expression_on_sumtype_ordinary_branch(){ assert c == 1 } - -fn test_match_expression_on_sumtype_else(){ +fn test_match_expression_on_sumtype_else() { // tests whether else branches support multiple statements, // when the other branches are simple default expressions mut c := 0 @@ -30,7 +31,8 @@ fn test_match_expression_on_sumtype_else(){ res := match s { string { 'a string' - }else{ + } + else { c = 3 eprintln('hi') 'unknown' @@ -40,7 +42,7 @@ fn test_match_expression_on_sumtype_else(){ assert c == 3 } -fn test_match_expression_on_sumtype_full(){ +fn test_match_expression_on_sumtype_full() { // tests whether all branches can have multiple statements, // followed by a default expression mut c := 0 diff --git a/vlib/v/tests/match_in_map_init_test.v b/vlib/v/tests/match_in_map_init_test.v index 0ef88623db..30eda3e2af 100644 --- a/vlib/v/tests/match_in_map_init_test.v +++ b/vlib/v/tests/match_in_map_init_test.v @@ -1,7 +1,11 @@ fn test_match_in_map_init() { ret := foo() println(ret) - assert ret == map{'token': 'a', 'sleep': '30', 'every': '1'} + assert ret == map{ + 'token': 'a' + 'sleep': '30' + 'every': '1' + } } fn foo() map[string]string { diff --git a/vlib/v/tests/match_interface_test.v b/vlib/v/tests/match_interface_test.v index a33a7bb9e4..d7b6822140 100644 --- a/vlib/v/tests/match_interface_test.v +++ b/vlib/v/tests/match_interface_test.v @@ -1,12 +1,22 @@ -interface Animal { name string } -struct Dog { name string } -struct Cat { name string } +interface Animal { + name string +} + +struct Dog { + name string +} + +struct Cat { + name string +} fn test_interface_match() { - a := Animal(Dog{name: 'Jet'}) - match a { - Dog { assert true } - Cat { assert false } - else { assert false } - } + a := Animal(Dog{ + name: 'Jet' + }) + match a { + Dog { assert true } + Cat { assert false } + else { assert false } + } } diff --git a/vlib/v/tests/match_smartcast_test.v b/vlib/v/tests/match_smartcast_test.v index a5194b9c54..23d66334af 100644 --- a/vlib/v/tests/match_smartcast_test.v +++ b/vlib/v/tests/match_smartcast_test.v @@ -2,6 +2,7 @@ type Node = Expr | string type Expr = IfExpr | IntegerLiteral struct IntegerLiteral {} + struct IfExpr { pos int } @@ -11,7 +12,9 @@ struct NodeWrapper { } fn test_nested_sumtype_match_selector() { - c := NodeWrapper{Node(Expr(IfExpr{pos: 1}))} + c := NodeWrapper{Node(Expr(IfExpr{ + pos: 1 + }))} match c.node { Expr { match c.node { @@ -30,7 +33,9 @@ fn test_nested_sumtype_match_selector() { } fn test_nested_sumtype_match() { - c := Node(Expr(IfExpr{pos: 1})) + c := Node(Expr(IfExpr{ + pos: 1 + })) match c { Expr { match c { @@ -58,7 +63,7 @@ mut: name string } -type Food = Milk | Eggs +type Food = Eggs | Milk struct FoodWrapper { mut: diff --git a/vlib/v/tests/match_sumtype_var_shadow_and_as_test.v b/vlib/v/tests/match_sumtype_var_shadow_and_as_test.v index 7a49c979fd..eaf9b12df1 100644 --- a/vlib/v/tests/match_sumtype_var_shadow_and_as_test.v +++ b/vlib/v/tests/match_sumtype_var_shadow_and_as_test.v @@ -1,11 +1,20 @@ -struct Cat{name string} -struct Dog{name string} +struct Cat { + name string +} + +struct Dog { + name string +} type Animal = Cat | Dog const ( - cat = Cat{name: 'cat'} - dog = Dog{name: 'dog'} + cat = Cat{ + name: 'cat' + } + dog = Dog{ + name: 'dog' + } ) fn test_shadow() { @@ -15,7 +24,7 @@ fn test_shadow() { Cat { assert animal.name == cat.name } - else{ + else { assert false } } @@ -28,7 +37,7 @@ fn test_as() { Dog { assert animal.name == dog.name } - else{ + else { assert false } } diff --git a/vlib/v/tests/method_call_chain_test.v b/vlib/v/tests/method_call_chain_test.v index 90c055d6c3..844c36117a 100644 --- a/vlib/v/tests/method_call_chain_test.v +++ b/vlib/v/tests/method_call_chain_test.v @@ -5,10 +5,24 @@ mut: // this must return a reference, or else you'll get a C error // TODO: add a proper checker check for that case -fn new(x int) &Test { return &Test{ x } } -fn (mut t Test) inc() &Test { t.val++ return t } -fn (mut t Test) add(x int) &Test { t.val += x return t } -fn (mut t Test) div(x int) &Test { t.val /= x return t } +fn new(x int) &Test { + return &Test{x} +} + +fn (mut t Test) inc() &Test { + t.val++ + return t +} + +fn (mut t Test) add(x int) &Test { + t.val += x + return t +} + +fn (mut t Test) div(x int) &Test { + t.val /= x + return t +} fn test_method_call_chains() { mut x := new(4).inc().inc().inc().inc().add(4).div(2).inc() diff --git a/vlib/v/tests/methods_on_interfaces_test.v b/vlib/v/tests/methods_on_interfaces_test.v index b5c9aae025..f3d61dbea1 100644 --- a/vlib/v/tests/methods_on_interfaces_test.v +++ b/vlib/v/tests/methods_on_interfaces_test.v @@ -7,11 +7,11 @@ interface Animal { } fn (a Animal) info() string { - return "I'm a ${a.breed} ${typeof(a).name}" + return "I'm a $a.breed ${typeof(a).name}" } fn new_animal(breed string) Animal { - return &Cat{ breed } + return &Cat{breed} } fn test_methods_on_interfaces() { diff --git a/vlib/v/tests/module_test.v b/vlib/v/tests/module_test.v index 419ca03e4f..bb4ba72242 100644 --- a/vlib/v/tests/module_test.v +++ b/vlib/v/tests/module_test.v @@ -3,7 +3,7 @@ import crypto.sha256 import term { white } import crypto.md5 { sum } import log as l -import time as t { now, utc, Time } +import time as t { Time, utc } import math import crypto.sha512 import cli { Command } diff --git a/vlib/v/tests/module_type_cast_test.v b/vlib/v/tests/module_type_cast_test.v index 525ef2260c..ff8c5f9fcc 100644 --- a/vlib/v/tests/module_type_cast_test.v +++ b/vlib/v/tests/module_type_cast_test.v @@ -3,6 +3,6 @@ import time fn test_module_type_cast() { a := time.Duration(5) b := time.Duration(6) - //println(a+b) - assert a+b == 11 + // println(a+b) + assert a + b == 11 } diff --git a/vlib/v/tests/modules/acommentedmodule/commentedfile.v b/vlib/v/tests/modules/acommentedmodule/commentedfile.v index 6e7af6f77e..bd5bf0bd74 100644 --- a/vlib/v/tests/modules/acommentedmodule/commentedfile.v +++ b/vlib/v/tests/modules/acommentedmodule/commentedfile.v @@ -1,5 +1,3 @@ /* module acommentedmodule - - */ diff --git a/vlib/v/tests/modules/geometry/geometry.v b/vlib/v/tests/modules/geometry/geometry.v index e4a26e0f29..8995dc4ebd 100644 --- a/vlib/v/tests/modules/geometry/geometry.v +++ b/vlib/v/tests/modules/geometry/geometry.v @@ -1,6 +1,6 @@ module geometry -const( +const ( module_name = 'geometry' ) @@ -12,24 +12,24 @@ pub enum Shape { pub struct Point { pub mut: - x int - y int + x int + y int } pub struct Line { pub mut: - ps []Point + ps []Point } -pub fn (a Point) +(b Point) Point { - return Point { - x: a.x + b.x - y: a.y + b.y - } +pub fn (a Point) + (b Point) Point { + return Point{ + x: a.x + b.x + y: a.y + b.y + } } pub fn (a Point) str() string { - return '${a.x} ${a.y}' + return '$a.x $a.y' } pub fn point_str(a Point) string { diff --git a/vlib/v/tests/modules/methods_struct_another_module/methods_struct_test.v b/vlib/v/tests/modules/methods_struct_another_module/methods_struct_test.v index dd2fc8b7d7..90c6e3e0ca 100644 --- a/vlib/v/tests/modules/methods_struct_another_module/methods_struct_test.v +++ b/vlib/v/tests/modules/methods_struct_another_module/methods_struct_test.v @@ -3,14 +3,23 @@ module main import geometry { Point } fn test_operator_overloading() { - one := Point {x:1, y:2} - two := Point {x:5, y:1} - sum := one + two + one := Point{ + x: 1 + y: 2 + } + two := Point{ + x: 5 + y: 1 + } + sum := one + two assert sum.x == 6 assert sum.y == 3 } fn test_str_method() { - one := Point {x:1, y:2} - assert '$one' == '1 2' + one := Point{ + x: 1 + y: 2 + } + assert '$one' == '1 2' } diff --git a/vlib/v/tests/modules/simplemodule/importing_test.v b/vlib/v/tests/modules/simplemodule/importing_test.v index 6cc3a00a2b..a81982ae19 100644 --- a/vlib/v/tests/modules/simplemodule/importing_test.v +++ b/vlib/v/tests/modules/simplemodule/importing_test.v @@ -2,10 +2,10 @@ import simplemodule // this tests whether the tests can import the same module without any special // custom paths setup on the CLI -fn test_iadd(){ +fn test_iadd() { assert simplemodule.iadd(10, 20) == 30 } -fn test_imul(){ - assert simplemodule.imul(5,8) == 40 +fn test_imul() { + assert simplemodule.imul(5, 8) == 40 } diff --git a/vlib/v/tests/multiple_paths_in_vmodules/path1/xxx/m.v b/vlib/v/tests/multiple_paths_in_vmodules/path1/xxx/m.v index 0ff85a26d8..dbb4109389 100644 --- a/vlib/v/tests/multiple_paths_in_vmodules/path1/xxx/m.v +++ b/vlib/v/tests/multiple_paths_in_vmodules/path1/xxx/m.v @@ -1,4 +1,5 @@ module xxx + pub fn f() string { return 'x' } diff --git a/vlib/v/tests/multiple_paths_in_vmodules/path2/yyy/m.v b/vlib/v/tests/multiple_paths_in_vmodules/path2/yyy/m.v index f596280bd6..66c9b219d4 100644 --- a/vlib/v/tests/multiple_paths_in_vmodules/path2/yyy/m.v +++ b/vlib/v/tests/multiple_paths_in_vmodules/path2/yyy/m.v @@ -1,4 +1,5 @@ module yyy -pub fn f() string { + +pub fn f() string { return 'y' } diff --git a/vlib/v/tests/multiple_paths_in_vmodules/path3/zzz/m.v b/vlib/v/tests/multiple_paths_in_vmodules/path3/zzz/m.v index 975dd4bdc8..42dbe33056 100644 --- a/vlib/v/tests/multiple_paths_in_vmodules/path3/zzz/m.v +++ b/vlib/v/tests/multiple_paths_in_vmodules/path3/zzz/m.v @@ -1,4 +1,5 @@ module zzz + pub fn f() string { return 'z' -} +} diff --git a/vlib/v/tests/mut_test.v b/vlib/v/tests/mut_test.v index 3a3d56d059..fa8c1fc347 100644 --- a/vlib/v/tests/mut_test.v +++ b/vlib/v/tests/mut_test.v @@ -49,15 +49,15 @@ fn test_mut_2() { } fn test_mut_3() { - mut indices := []int{len: 3} + mut indices := []int{len: 3} mut results := []string{} - for i, mut v in indices { - v = i - a := v - println('$i $v $a') + for i, mut v in indices { + v = i + a := v + println('$i $v $a') results << '$i $v $a' - } + } assert results[0] == '0 0 0' assert results[1] == '1 1 1' assert results[2] == '2 2 2' @@ -65,42 +65,46 @@ fn test_mut_3() { struct St { mut: - n int + n int } fn f(mut x St) { - mut y := St{n: 2} - a := x - b := y - x.n = 3 - y.n = 4 - println('$a.n $b.n') + mut y := St{ + n: 2 + } + a := x + b := y + x.n = 3 + y.n = 4 + println('$a.n $b.n') assert '$a.n $b.n' == '1 2' } fn test_mut_4() { - mut x := St{ n: 1 } - f(mut x) + mut x := St{ + n: 1 + } + f(mut x) } fn test_mut_5() { - mut arr1 := []int{len:2} - mut arr2 := []int{len:2} + mut arr1 := []int{len: 2} + mut arr2 := []int{len: 2} mut results := []string{} - for i, mut v in arr1 { - for ii, mut vv in arr2 { - v = i - a := v - println('$i $v $a') + for i, mut v in arr1 { + for ii, mut vv in arr2 { + v = i + a := v + println('$i $v $a') results << '$i $v $a' - vv = ii - aa := vv - println('$ii $vv $aa') - results << "$ii $vv $aa" - } - } + vv = ii + aa := vv + println('$ii $vv $aa') + results << '$ii $vv $aa' + } + } assert results[0] == '0 0 0' assert results[1] == '0 0 0' @@ -114,21 +118,21 @@ fn test_mut_5() { fn test_mut_6() { mut results := []int{} - mut arr := []int{len:3} - for _, mut v in arr { + mut arr := []int{len: 3} + for _, mut v in arr { v = v + 1 println(v) results << v - } + } assert results[0] == 1 assert results[1] == 1 assert results[2] == 1 } fn test_mut_7() { - mut arr := []int{len:3} + mut arr := []int{len: 3} mut results := []int{} - for _, mut v in arr { + for _, mut v in arr { v = v + 1 // v: 1 mut vv := v // vv: 1, v: 1 vv = vv + v // vv: 2, v: 1 @@ -136,7 +140,7 @@ fn test_mut_7() { println(vv) results << v results << vv - } + } assert results[0] == 1 assert results[1] == 2 assert results[2] == 1 @@ -146,37 +150,40 @@ fn test_mut_7() { } fn test_mut_8() { - mut indices := []int{len: 1} - for i, mut v in indices { - v = i - mut b := v - println(typeof(i).name) - println(typeof(v).name) - println(typeof(b).name) - u := [v, 5, 6] - println(typeof(u).name) + mut indices := []int{len: 1} + for i, mut v in indices { + v = i + mut b := v + println(typeof(i).name) + println(typeof(v).name) + println(typeof(b).name) + u := [v, 5, 6] + println(typeof(u).name) println(u) assert typeof(b).name == 'int' assert typeof(u).name == '[]int' assert u == [0, 5, 6] - } + } } fn test_mut_9() { - mut arr := [0,0,0] + mut arr := [0, 0, 0] mut results := []string{} for _, mut v in arr { v = v + 1 // v: 1 mut vv := v // vv: 1, v: 1 vv = vv + v // vv: 2, v: 1 - foo := {'a': v, 'b': vv} // or use new syntax foo := map{'a': v, 'b': vv}, results are the same + foo := map{ + 'a': v + 'b': vv + } println(v) println(vv) println(foo) results << '$v' results << '$vv' results << '$foo' - } + } assert results[0] == '1' assert results[1] == '2' assert results[2] == "{'a': 1, 'b': 2}" @@ -210,7 +217,7 @@ fn foo1(mut arr [][]int) { } fn test_mut_10() { - mut arr := [[0,0]] + mut arr := [[0, 0]] foo1(mut arr) } @@ -236,7 +243,7 @@ fn foo2(mut arr [][]int) { } fn test_mut_11() { - mut arr := [[0,0]] + mut arr := [[0, 0]] foo2(mut arr) } @@ -251,7 +258,7 @@ fn foo3(mut arr [][]int) { } fn test_mut_12() { - mut arr := [[0, 0]] + mut arr := [[0, 0]] foo3(mut arr) } @@ -270,7 +277,9 @@ fn foo4(mut f Foo) { } fn test_mut_13() { - mut f := Foo{foo: 1} + mut f := Foo{ + foo: 1 + } foo4(mut f) } @@ -286,7 +295,7 @@ fn foo5(mut arr []int) { } fn test_mut_14() { - mut arr := [1,2,3] + mut arr := [1, 2, 3] foo5(mut arr) } @@ -302,7 +311,7 @@ fn foo6(mut arr [3]int) { } fn test_mut_15() { - mut arr := [1,2,3]! + mut arr := [1, 2, 3]! foo6(mut arr) } @@ -318,20 +327,31 @@ fn foo7(mut m map[string]int) { } fn test_mut_16() { - mut m := map{'one': 100, 'two': 2} + mut m := map{ + 'one': 100 + 'two': 2 + } foo7(mut m) } fn test_mut_17() { - mut arr := [map{'foo':1}] + mut arr := [map{ + 'foo': 1 + }] for _, mut j in arr { mut k := j.clone() j['foo'] = 0 - unsafe {k['foo'] = 10} + unsafe { + k['foo'] = 10 + } println(j) println(k) - assert j == {'foo': 0} - assert k == {'foo': 10} + assert j == map{ + 'foo': 0 + } + assert k == map{ + 'foo': 10 + } } } diff --git a/vlib/v/tests/nested_option_call_test.v b/vlib/v/tests/nested_option_call_test.v index 2f53e56aee..f2857f295e 100644 --- a/vlib/v/tests/nested_option_call_test.v +++ b/vlib/v/tests/nested_option_call_test.v @@ -62,8 +62,6 @@ fn test_nested_propagation_method() { mut x := St{ z: 2.25 } - x.aa_propagate() or { - x.z = 13.0625 - } + x.aa_propagate() or { x.z = 13.0625 } assert x.z == 13.0625 } diff --git a/vlib/v/tests/offsetof_test.v b/vlib/v/tests/offsetof_test.v index ac90bcda59..6ae8acb24c 100644 --- a/vlib/v/tests/offsetof_test.v +++ b/vlib/v/tests/offsetof_test.v @@ -1,15 +1,19 @@ import math.complex struct Cat { - name string + name string breed string - age int + age int } type Feline = Cat fn test_offsetof() { - cat := Cat{name: 'Cthulhu' breed: 'Great Old One' age: 2147483647} + cat := Cat{ + name: 'Cthulhu' + breed: 'Great Old One' + age: 2147483647 + } unsafe { assert *(&string(byteptr(&cat) + __offsetof(Cat, name))) == 'Cthulhu' assert *(&string(byteptr(&cat) + __offsetof(Cat, breed))) == 'Great Old One' @@ -26,7 +30,11 @@ fn test_offsetof_struct_from_another_module() { } fn test_offsetof_alias() { - fel := Feline{name: 'Cthulhu' breed: 'Great Old One' age: 2147483647} + fel := Feline{ + name: 'Cthulhu' + breed: 'Great Old One' + age: 2147483647 + } unsafe { assert *(&string(byteptr(&fel) + __offsetof(Feline, name))) == 'Cthulhu' assert *(&string(byteptr(&fel) + __offsetof(Feline, breed))) == 'Great Old One' diff --git a/vlib/v/tests/operator_overloading_cmp_test.v b/vlib/v/tests/operator_overloading_cmp_test.v index 10129f9958..ccf06738c0 100644 --- a/vlib/v/tests/operator_overloading_cmp_test.v +++ b/vlib/v/tests/operator_overloading_cmp_test.v @@ -11,12 +11,16 @@ fn (a Foo) == (b Foo) bool { } fn test_operator_overloading_cmp() { - a := Foo{i: 38} - b := Foo{i: 38} + a := Foo{ + i: 38 + } + b := Foo{ + i: 38 + } mut arr := [a, b] assert (a > b) == false - assert (a < b) == false + assert (a < b) == false //// /// // assert a >= b assert a <= b diff --git a/vlib/v/tests/operator_overloading_with_string_interpolation_test.v b/vlib/v/tests/operator_overloading_with_string_interpolation_test.v index ccd412bb53..4ed5871779 100644 --- a/vlib/v/tests/operator_overloading_with_string_interpolation_test.v +++ b/vlib/v/tests/operator_overloading_with_string_interpolation_test.v @@ -79,5 +79,5 @@ fn test_operator_overloading_with_string_interpolation() { ad *= Vec{2, 2} assert ad.str() == '{8, 18}' ad /= Vec{2, 2} - assert ad.str() == '{4, 9}' + assert ad.str() == '{4, 9}' } diff --git a/vlib/v/tests/option_2_test.v b/vlib/v/tests/option_2_test.v index 7404fd265c..40db899fa4 100644 --- a/vlib/v/tests/option_2_test.v +++ b/vlib/v/tests/option_2_test.v @@ -41,9 +41,9 @@ fn test_channel_push() { fn test_thread_wait() { thrs := [ - go f(3) - go f(-7) - go f(12) + go f(3), + go f(-7), + go f(12), ] mut res := []int{cap: 3} for t in thrs { @@ -56,4 +56,3 @@ fn test_nested_opt() { a := f(f(f(-3) or { -7 }) or { 4 }) or { 17 } assert a == 4 } - diff --git a/vlib/v/tests/option_default_values_test.v b/vlib/v/tests/option_default_values_test.v index 8c103df281..2abd546fa9 100644 --- a/vlib/v/tests/option_default_values_test.v +++ b/vlib/v/tests/option_default_values_test.v @@ -36,13 +36,9 @@ fn return_a_string() string { // fn test_optional_int() { - a := i_0(0) or { - 4999 - } + a := i_0(0) or { 4999 } assert a == 4999 - b := i_0(4123) or { - 4999 - } + b := i_0(4123) or { 4999 } assert b == 4123 } @@ -59,13 +55,9 @@ fn test_optional_bool() { } */ fn test_optional_struct() { - sa := struct_0(0) or { - Abc{7999} - } + sa := struct_0(0) or { Abc{7999} } assert sa.x == 7999 - sb := struct_0(3456) or { - Abc{7999} - } + sb := struct_0(3456) or { Abc{7999} } assert sb.x == 3456 } @@ -75,16 +67,12 @@ fn test_optional_with_statements_before_last_expression() { Abc{12345} } assert s.x == 12345 - b := b_0(true) or { - false - } + b := b_0(true) or { false } assert b == true } fn test_optional_with_fn_call_as_last_expression() { - s := string_0(0) or { - return_a_string() - } + s := string_0(0) or { return_a_string() } assert s == 'abcdef' } @@ -99,46 +87,28 @@ fn test_optional_with_fn_call_last_expr_and_preceding_statements() { fn test_nested_optional() { a := i_0(1) or { - b := i_0(0) or { - 3 - } + b := i_0(0) or { 3 } b } assert a == 1 b := i_0(0) or { - c := i_0(1) or { - 3 - } + c := i_0(1) or { 3 } c } assert b == 1 c := i_0(0) or { - d := i_0(0) or { - 3 - } + d := i_0(0) or { 3 } d } assert c == 3 } fn test_nested_optional_with_opt_fn_call_as_last_value() { - a := i_0(1) or { - i_0(0) or { - 3 - } - } + a := i_0(1) or { i_0(0) or { 3 } } assert a == 1 - b := i_0(0) or { - i_0(1) or { - 3 - } - } + b := i_0(0) or { i_0(1) or { 3 } } assert b == 1 - c := i_0(0) or { - i_0(0) or { - 3 - } - } + c := i_0(0) or { i_0(0) or { 3 } } assert c == 3 // TODO Enable once optional in boolean expressions are working // d := b_0(true) or { @@ -156,9 +126,9 @@ fn test_nested_optional_with_opt_fn_call_as_last_value() { } fn remove_suffix1(s string) string { - n := s.len - i := s.last_index('.') or { n } - return s[0..i] + n := s.len + i := s.last_index('.') or { n } + return s[0..i] } fn test_var_inside_or_block() { diff --git a/vlib/v/tests/option_print_errors_test.v b/vlib/v/tests/option_print_errors_test.v index 3992c0a75a..b59d792aef 100644 --- a/vlib/v/tests/option_print_errors_test.v +++ b/vlib/v/tests/option_print_errors_test.v @@ -1,20 +1,19 @@ - -fn test_error_can_be_converted_to_string(){ +fn test_error_can_be_converted_to_string() { assert 'Option{ error: "an error" }' == error('an error').str() } -fn test_error_can_be_assigned_to_a_variable(){ +fn test_error_can_be_assigned_to_a_variable() { f := error('an error') assert 'Option{ error: "an error" }' == f.str() } -fn test_error_can_be_printed(){ +fn test_error_can_be_printed() { f := error('an error') println(f) assert true } -fn test_error_can_be_interpolated_in_a_string(){ +fn test_error_can_be_interpolated_in_a_string() { f := error('an error') s := 'hi $f' assert s == 'hi Option{ error: "an error" }' diff --git a/vlib/v/tests/option_test.v b/vlib/v/tests/option_test.v index d48237060a..e73934b44b 100644 --- a/vlib/v/tests/option_test.v +++ b/vlib/v/tests/option_test.v @@ -269,7 +269,7 @@ fn test_multi_return_opt() { */ fn test_optional_val_with_empty_or() { - ret_none() or { } + ret_none() or {} assert true } diff --git a/vlib/v/tests/orm_sub_struct_test.v b/vlib/v/tests/orm_sub_struct_test.v index 938fd888ee..81c0035fa1 100644 --- a/vlib/v/tests/orm_sub_struct_test.v +++ b/vlib/v/tests/orm_sub_struct_test.v @@ -1,12 +1,12 @@ import sqlite struct Upper { - id int + id int sub SubStruct } struct SubStruct { - id int + id int name string } diff --git a/vlib/v/tests/project_with_c_code/main.v b/vlib/v/tests/project_with_c_code/main.v index 370b423e21..87266710b3 100644 --- a/vlib/v/tests/project_with_c_code/main.v +++ b/vlib/v/tests/project_with_c_code/main.v @@ -1,6 +1,6 @@ module main -import mod1 +import v.tests.project_with_c_code.mod1 fn main() { res := mod1.vadd(1, 2) diff --git a/vlib/v/tests/project_with_c_code/main_test.v b/vlib/v/tests/project_with_c_code/main_test.v index 4dfd809e86..47fe71407f 100644 --- a/vlib/v/tests/project_with_c_code/main_test.v +++ b/vlib/v/tests/project_with_c_code/main_test.v @@ -1,5 +1,5 @@ -import mod1 +import v.tests.project_with_c_code.mod1 -fn test_using_c_code_in_the_same_module_works(){ - assert 1003 == mod1.vadd(1,2) +fn test_using_c_code_in_the_same_module_works() { + assert 1003 == mod1.vadd(1, 2) } diff --git a/vlib/v/tests/project_with_c_code/mod1/wrapper.v b/vlib/v/tests/project_with_c_code/mod1/wrapper.v index 93ebd21242..16a04a52a5 100644 --- a/vlib/v/tests/project_with_c_code/mod1/wrapper.v +++ b/vlib/v/tests/project_with_c_code/mod1/wrapper.v @@ -12,6 +12,6 @@ struct C.MyStruct { fn C.cadd(int, int) int pub fn vadd(a int, b int) int { - x := C.MyStruct{ 100 } + x := C.MyStruct{100} return 900 + x.UppercaseField + C.cadd(a, b) } diff --git a/vlib/v/tests/project_with_c_code_2/main.v b/vlib/v/tests/project_with_c_code_2/main.v index 926f56a0ee..e16284a54d 100644 --- a/vlib/v/tests/project_with_c_code_2/main.v +++ b/vlib/v/tests/project_with_c_code_2/main.v @@ -1,6 +1,6 @@ module main -import modc +import v.tests.project_with_c_code_2.modc // passing array of Vtype to C // Vtype wraps a C type diff --git a/vlib/v/tests/project_with_c_code_2/main2_test.v b/vlib/v/tests/project_with_c_code_2/main2_test.v index 6281cb7f81..c039858009 100644 --- a/vlib/v/tests/project_with_c_code_2/main2_test.v +++ b/vlib/v/tests/project_with_c_code_2/main2_test.v @@ -1,4 +1,4 @@ -import modc +import v.tests.project_with_c_code_2.modc fn test_using_c_code_in_the_same_module_works() { x := modc.new_vtype(123) diff --git a/vlib/v/tests/project_with_c_code_2/modc/wrapper.v b/vlib/v/tests/project_with_c_code_2/modc/wrapper.v index 1109196c38..1bdaf8cd95 100644 --- a/vlib/v/tests/project_with_c_code_2/modc/wrapper.v +++ b/vlib/v/tests/project_with_c_code_2/modc/wrapper.v @@ -3,6 +3,7 @@ module modc #flag -I @VROOT #flag @VROOT/impl.o #include "header.h" + struct C.Atype { } diff --git a/vlib/v/tests/project_with_modules_having_submodules/bin/a_program_under_bin_can_find_mod1_test.v b/vlib/v/tests/project_with_modules_having_submodules/bin/a_program_under_bin_can_find_mod1_test.v index 81285119b7..cbc3fa04f1 100644 --- a/vlib/v/tests/project_with_modules_having_submodules/bin/a_program_under_bin_can_find_mod1_test.v +++ b/vlib/v/tests/project_with_modules_having_submodules/bin/a_program_under_bin_can_find_mod1_test.v @@ -1,4 +1,4 @@ -import mod1.submodule as m +import v.tests.project_with_modules_having_submodules.mod1.submodule as m fn test_mod1_can_still_be_found_through_parent_project_vmod() { assert 1051 == m.f() diff --git a/vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh b/vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh old mode 100755 new mode 100644 index 6470923aa2..ef643ce804 --- a/vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh +++ b/vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh @@ -1,12 +1,12 @@ #!/usr/local/bin/v run -import mod1.submodule as m + +import v.tests.project_with_modules_having_submodules.mod1.submodule as m println('This script is located inside: ' + resource_abs_path('')) -println('The result of calling m.f is: ' + m.f().str() ) +println('The result of calling m.f is: ' + m.f().str()) - -/* +/* NB: this main program v script is under bin/ , but it *still* can find mod1, because the parent project has v.mod, so v module lookup for this bin/main.vsh file will find mod1 through diff --git a/vlib/v/tests/project_with_modules_having_submodules/mod1/submodule/m.v b/vlib/v/tests/project_with_modules_having_submodules/mod1/submodule/m.v index 2afa4b95d8..e1bfe37da4 100644 --- a/vlib/v/tests/project_with_modules_having_submodules/mod1/submodule/m.v +++ b/vlib/v/tests/project_with_modules_having_submodules/mod1/submodule/m.v @@ -1,15 +1,14 @@ module submodule -/* +/* This submodule just imports its sibling submodules. Note that they are NOT under 'submodule' itself, but are in its parent mod1 , and mod1 has a 'v.mod' file. */ - -import mod11 -import mod12 -import mod13 -import mod14 +import v.tests.project_with_modules_having_submodules.mod1.mod11 +import v.tests.project_with_modules_having_submodules.mod1.mod12 +import v.tests.project_with_modules_having_submodules.mod1.mod13 +import v.tests.project_with_modules_having_submodules.mod1.mod14 pub fn f() int { return 1000 + mod11.f() + mod12.f() + mod13.f() + mod14.f() diff --git a/vlib/v/tests/project_with_modules_having_submodules/tests/submodule_test.v b/vlib/v/tests/project_with_modules_having_submodules/tests/submodule_test.v index 8772626365..768f8d7300 100644 --- a/vlib/v/tests/project_with_modules_having_submodules/tests/submodule_test.v +++ b/vlib/v/tests/project_with_modules_having_submodules/tests/submodule_test.v @@ -1,5 +1,5 @@ -import mod1 -import mod1.submodule +import v.tests.project_with_modules_having_submodules.mod1 +import v.tests.project_with_modules_having_submodules.mod1.submodule fn test_mod1() { assert 1 == mod1.f() diff --git a/vlib/v/tests/ref_struct_test.v b/vlib/v/tests/ref_struct_test.v index 771586bd5f..fcc4f3a677 100644 --- a/vlib/v/tests/ref_struct_test.v +++ b/vlib/v/tests/ref_struct_test.v @@ -21,27 +21,35 @@ mut: } fn test_ref() { - a := &Abc{ n: 3 } + a := &Abc{ + n: 3 + } assert a.n == 3 } fn test_shared() { - shared a := Abc{ n: 4 } - res := rlock a { a.n } + shared a := Abc{ + n: 4 + } + res := rlock a { + a.n + } assert res == 4 } fn test_embed_in_ref_struct() { - a := &St{ - Abc{ n: 5 } - } + a := &St{Abc{ + n: 5 + }} assert a.n == 5 } fn test_field_in_ref_struct() { x := &Qwe{ f: 12.25 - a: Abc{ n: 23 } + a: Abc{ + n: 23 + } } assert x.a.n == 23 } @@ -49,7 +57,9 @@ fn test_field_in_ref_struct() { fn test_ref_field() { y := Rtz{ f: -6.25 - a: &Abc{ n: 29 } + a: &Abc{ + n: 29 + } } assert y.a.n == 29 } diff --git a/vlib/v/tests/repl/repl_test.v b/vlib/v/tests/repl/repl_test.v index 0634c093c9..ba798bd935 100644 --- a/vlib/v/tests/repl/repl_test.v +++ b/vlib/v/tests/repl/repl_test.v @@ -42,9 +42,7 @@ fn test_all_v_repl_files() { panic(err) } session.bmark.set_total_expected_steps(session.options.files.len) - mut pool_repl := pool.new_pool_processor( - callback: worker_repl - ) + mut pool_repl := pool.new_pool_processor(callback: worker_repl) pool_repl.set_shared_context(session) $if windows { // See: https://docs.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes?view=vs-2019 diff --git a/vlib/v/tests/semaphore_timed_test.v b/vlib/v/tests/semaphore_timed_test.v index a7d9a243ea..5cac420a4a 100644 --- a/vlib/v/tests/semaphore_timed_test.v +++ b/vlib/v/tests/semaphore_timed_test.v @@ -22,7 +22,7 @@ fn test_semaphore() { // we should come here due to timeout elapsed = stopwatch.elapsed() } - elapsed_ms := f64(elapsed)/time.millisecond + elapsed_ms := f64(elapsed) / time.millisecond println('elapsed: ${elapsed_ms:.1f}ms') assert elapsed_ms >= 190.0 } diff --git a/vlib/v/tests/shared_arg_test.v b/vlib/v/tests/shared_arg_test.v index e9a43fb817..405f85ab32 100644 --- a/vlib/v/tests/shared_arg_test.v +++ b/vlib/v/tests/shared_arg_test.v @@ -35,10 +35,18 @@ fn a_val(a []int) int { } fn test_shared_as_value() { - shared s := St{ a: 5 } + shared s := St{ + a: 5 + } shared a := [3, 4, 6, 13, -23] - shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625} - shared r := Qr{ a: 7 } + shared m := map{ + 'qw': 12.75 + 'yxcv': -3.125 + 'poiu': 88.0625 + } + shared r := Qr{ + a: 7 + } rlock s, r { u := r.s_val(s) assert u == 35 @@ -58,10 +66,18 @@ fn test_shared_as_value() { } fn test_shared_as_mut() { - shared s := St{ a: 5 } + shared s := St{ + a: 5 + } shared a := [3, 4, 6, 13, -23] - shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625} - shared r := Qr{ a: 7 } + shared m := map{ + 'qw': 12.75 + 'yxcv': -3.125 + 'poiu': 88.0625 + } + shared r := Qr{ + a: 7 + } lock s, r { r.s_mut(mut s) x := r.a * s.a diff --git a/vlib/v/tests/shared_autolock_test.v b/vlib/v/tests/shared_autolock_test.v index f898ab4a64..e5be9ad3a6 100644 --- a/vlib/v/tests/shared_autolock_test.v +++ b/vlib/v/tests/shared_autolock_test.v @@ -23,7 +23,12 @@ fn inc_map_elem(shared b map[string]int, k string) { } fn test_autolock_map() { - shared m := &{'xy': 1, 'qwe': 2, 'asd': 7, 'iop': 5} + shared m := &map{ + 'xy': 1 + 'qwe': 2 + 'asd': 7 + 'iop': 5 + } t := go inc_map_elem(shared m, 'asd') for _ in 0 .. iterations { m['asd']++ @@ -31,4 +36,3 @@ fn test_autolock_map() { t.wait() assert m['asd'] == 2 * iterations + 7 } - diff --git a/vlib/v/tests/shared_elem_test.v b/vlib/v/tests/shared_elem_test.v index 3f62c161d9..671d42aec5 100644 --- a/vlib/v/tests/shared_elem_test.v +++ b/vlib/v/tests/shared_elem_test.v @@ -9,24 +9,36 @@ struct Abc { } fn test_shared_struct_in_struct() { - shared y := Xyz{ n: 7 } + shared y := Xyz{ + n: 7 + } z := Abc{ a: y } - u := Xyz{ n: 17 } + u := Xyz{ + n: 17 + } x := Abc{ a: u } v := Abc{ - a: Xyz{ n: 5 } + a: Xyz{ + n: 5 + } i: 3 } shared f := x.a shared g := v.a shared h := z.a - a := rlock f { f.n } - b := rlock g { g.n } - c := rlock h { h.n } + a := rlock f { + f.n + } + b := rlock g { + g.n + } + c := rlock h { + h.n + } assert a == 17 assert b == 5 assert c == 7 @@ -48,8 +60,12 @@ fn test_shared_array_in_struct() { t[2] = -1.125 } shared tt := x.a - v := rlock tt { tt[3] } - w := rlock tt { tt[2] } + v := rlock tt { + tt[3] + } + w := rlock tt { + tt[2] + } assert v == 13.0625 assert w == -1.125 assert x.i == 12 @@ -62,7 +78,11 @@ struct Hjk { fn test_shared_map_in_struct() { x := Hjk{ - m: {'st': -6.0625, 'xy': 12.125, 'rz': 2.25} + m: map{ + 'st': -6.0625 + 'xy': 12.125 + 'rz': 2.25 + } i: 23 } shared k := x.m @@ -70,8 +90,12 @@ fn test_shared_map_in_struct() { k['yxc'] = -23.5 } shared p := x.m - a := rlock p { p['xy'] } - b := rlock p { p['yxc'] } + a := rlock p { + p['xy'] + } + b := rlock p { + p['yxc'] + } assert a == 12.125 assert b == -23.5 assert x.i == 23 @@ -79,11 +103,17 @@ fn test_shared_map_in_struct() { fn test_array_of_shared() { mut a := []shared Xyz{cap: 3} - a0 := Xyz{ n: 3 } + a0 := Xyz{ + n: 3 + } a << a0 - a1 := Xyz{ n: 7 } + a1 := Xyz{ + n: 7 + } a << a1 - a2 := Xyz{ n: 13 } + a2 := Xyz{ + n: 13 + } a << a2 shared p := a[0] shared q := a[2] @@ -91,8 +121,12 @@ fn test_array_of_shared() { q.n = -17 } shared r := a[2] - e := rlock p { p.n } - f := rlock r { r.n } + e := rlock p { + p.n + } + f := rlock r { + r.n + } assert e == 3 assert f == -17 } diff --git a/vlib/v/tests/shared_fn_return_test.v b/vlib/v/tests/shared_fn_return_test.v index 3c5740abd8..70e2d8695f 100644 --- a/vlib/v/tests/shared_fn_return_test.v +++ b/vlib/v/tests/shared_fn_return_test.v @@ -4,7 +4,9 @@ mut: } fn f() St { - x := St{ x: 3.25 } + x := St{ + x: 3.25 + } return x } @@ -12,19 +14,25 @@ fn g(good bool) ?St { if !good { return error('no St created') } - x := St{ x: 12.75 } + x := St{ + x: 12.75 + } return x } fn test_shared_fn_return() { shared x := f() - val := rlock x { x.x } + val := rlock x { + x.x + } assert val == 3.25 } fn shared_opt_propagate(good bool) ?f64 { shared x := g(good) ? - ret := rlock x { x.x } + ret := rlock x { + x.x + } return ret } @@ -36,13 +44,25 @@ fn test_shared_opt_propagate() { } fn test_shared_opt_good() { - shared yy := g(true) or { St{ x: 37.5 } } - val := rlock yy { yy.x } + shared yy := g(true) or { + St{ + x: 37.5 + } + } + val := rlock yy { + yy.x + } assert val == 12.75 } fn test_shared_opt_bad() { - shared yy := g(false) or { St{ x: 37.5 } } - val := rlock yy { yy.x } + shared yy := g(false) or { + St{ + x: 37.5 + } + } + val := rlock yy { + yy.x + } assert val == 37.5 } diff --git a/vlib/v/tests/shared_lock_5_test.v b/vlib/v/tests/shared_lock_5_test.v index 8aee4b6559..08284c0511 100644 --- a/vlib/v/tests/shared_lock_5_test.v +++ b/vlib/v/tests/shared_lock_5_test.v @@ -60,7 +60,7 @@ fn test_shared_receiver_lock() { t1.wait() t2.wait() t3.wait() - rlock x, y, z{ + rlock x, y, z { assert x.a == 7 assert y.a == 1 assert z.a == 5 diff --git a/vlib/v/tests/shared_lock_6_test.v b/vlib/v/tests/shared_lock_6_test.v index f2a9b7e44a..6ed5beaad8 100644 --- a/vlib/v/tests/shared_lock_6_test.v +++ b/vlib/v/tests/shared_lock_6_test.v @@ -16,7 +16,7 @@ fn (shared x St) f(shared y St, shared z St) { fn (shared x St) g(shared y St, shared z St) { for _ in 0 .. 10000 { - rlock x; lock y, z { + lock y, z; rlock x { y.a += x.a if y.a > 1000000 { y.a /= 2 diff --git a/vlib/v/tests/shared_lock_expr_test.v b/vlib/v/tests/shared_lock_expr_test.v index 488ff9fa43..fb1edc3cf8 100644 --- a/vlib/v/tests/shared_lock_expr_test.v +++ b/vlib/v/tests/shared_lock_expr_test.v @@ -4,11 +4,19 @@ mut: } fn test_lock_expr() { - shared xx := St{ i: 173 } - shared y := St{ i: -57 } + shared xx := St{ + i: 173 + } + shared y := St{ + i: -57 + } mut m := 0 - m = lock y { y.i } - n := rlock xx { xx.i } + m = lock y { + y.i + } + n := rlock xx { + xx.i + } assert m == -57 assert n == 173 } @@ -19,10 +27,18 @@ mut: } fn test_multi_objects() { - shared x := Abc{ a: 12.5 } - shared y := Abc{ a: -7.5 } - shared z := Abc{ a: 13.125 } - a, b, c := rlock z, x, y { y.a, z.a, x.a } + shared x := Abc{ + a: 12.5 + } + shared y := Abc{ + a: -7.5 + } + shared z := Abc{ + a: 13.125 + } + a, b, c := rlock z, x, y { + y.a, z.a, x.a + } assert a == -7.5 assert b == 13.125 assert c == 12.5 @@ -33,10 +49,18 @@ fn (mut st Abc) getvals(mut a Abc, mut b Abc) (f64, f64, f64) { } fn test_mult_ret_method() { - shared x := Abc{ a: 12.5 } - shared y := Abc{ a: -7.5 } - shared z := Abc{ a: 13.125 } - a, b, c := lock z, x, y { z.getvals(mut x, mut y) } + shared x := Abc{ + a: 12.5 + } + shared y := Abc{ + a: -7.5 + } + shared z := Abc{ + a: 13.125 + } + a, b, c := lock z, x, y { + z.getvals(mut x, mut y) + } assert a == 12.5 assert b == 13.125 assert c == -7.5 diff --git a/vlib/v/tests/shared_map_test.v b/vlib/v/tests/shared_map_test.v index 2ed8a01b15..97d59ee6a5 100644 --- a/vlib/v/tests/shared_map_test.v +++ b/vlib/v/tests/shared_map_test.v @@ -10,7 +10,10 @@ fn incr(shared foo map[string]int, key string, mut sem sync.Semaphore) { } fn test_shared_array() { - shared foo := {'p': 10, 'q': 0} + shared foo := map{ + 'p': 10 + 'q': 0 + } lock foo { foo['q'] = 20 } @@ -25,7 +28,7 @@ fn test_shared_array() { foo['q'] += 3 } } - for _ in 0..4 { + for _ in 0 .. 4 { sem.wait() } rlock foo { @@ -37,8 +40,16 @@ fn test_shared_array() { } fn test_shared_init_syntax() { - shared foo := &{'p': 17, 'q': -3, 'qwertz': 10} - shared bar := {'wer': 13.75, 'cvbn': -7.25, 'asd': -0.0625} + shared foo := &map{ + 'p': 17 + 'q': -3 + 'qwertz': 10 + } + shared bar := map{ + 'wer': 13.75 + 'cvbn': -7.25 + 'asd': -0.0625 + } shared baz := &map[string]int{} shared qux := map[string]f64{} shared quux := new_map() @@ -64,6 +75,10 @@ fn test_shared_init_syntax() { } fn new_map() map[string]f64 { - m := { 'qwe': 34.25, 'yxc': 9.125, 'tzu': -7.5 } + m := map{ + 'qwe': 34.25 + 'yxc': 9.125 + 'tzu': -7.5 + } return m } diff --git a/vlib/v/tests/shared_unordered_mixed_test.v b/vlib/v/tests/shared_unordered_mixed_test.v index 3985e707d5..f8ee27c87a 100644 --- a/vlib/v/tests/shared_unordered_mixed_test.v +++ b/vlib/v/tests/shared_unordered_mixed_test.v @@ -7,7 +7,11 @@ mut: } fn (a Large) clone() Large { - r := Large{ l: a.l, m: a.m h: a.h } + r := Large{ + l: a.l + m: a.m + h: a.h + } return r } @@ -15,14 +19,18 @@ fn (mut a Large) add(b Large) { oldl := a.l a.l += b.l oldm := a.m - if a.l < oldl { a.m++ } + if a.l < oldl { + a.m++ + } a.m += b.m - if a.m < oldm || (a.l < oldl && a.m <= oldm) { a.h++ } + if a.m < oldm || (a.l < oldl && a.m <= oldm) { + a.h++ + } a.h += b.h } fn doub_large(shared a Large, shared b Large, shared c Large, shared d Large, shared e Large) { - for _ in 0..50 { + for _ in 0 .. 50 { lock a, b; rlock c, d, e { // double the sum by adding all objects to a or b old_a := a.clone() @@ -37,11 +45,27 @@ fn doub_large(shared a Large, shared b Large, shared c Large, shared d Large, sh fn test_mixed_order_lock_rlock() { // initialze objects so that their sum = 1 - shared a := Large{ l: 4 } - shared b := Large{ l: u64(-7), m: u64(-1) h: u64(-1) } - shared c := Large{ l: 17 } - shared d := Large{ l: u64(-11), m: u64(-1) h: u64(-1) } - shared e := Large{ l: u64(-2), m: u64(-1) h: u64(-1) } + shared a := Large{ + l: 4 + } + shared b := Large{ + l: u64(-7) + m: u64(-1) + h: u64(-1) + } + shared c := Large{ + l: 17 + } + shared d := Large{ + l: u64(-11) + m: u64(-1) + h: u64(-1) + } + shared e := Large{ + l: u64(-2) + m: u64(-1) + h: u64(-1) + } // spawn 3 threads for doubling with different orders of objects t1 := go doub_large(shared a, shared b, shared c, shared d, shared e) t2 := go doub_large(shared e, shared b, shared a, shared c, shared d) @@ -63,4 +87,3 @@ fn test_mixed_order_lock_rlock() { assert sum.m == 0 assert sum.h == 4194304 } - diff --git a/vlib/v/tests/short_struct_param_syntax_test.v b/vlib/v/tests/short_struct_param_syntax_test.v index f62edbdb8a..c9b810694f 100644 --- a/vlib/v/tests/short_struct_param_syntax_test.v +++ b/vlib/v/tests/short_struct_param_syntax_test.v @@ -10,9 +10,7 @@ fn t(options TOptions) bool { } fn test_short_struct_as_parameter() { - if t({ - a: 1 - }) { + if t(a: 1) { assert true return } diff --git a/vlib/v/tests/sizeof_test.v b/vlib/v/tests/sizeof_test.v index df17734036..26292ee5ec 100644 --- a/vlib/v/tests/sizeof_test.v +++ b/vlib/v/tests/sizeof_test.v @@ -4,6 +4,7 @@ import flag struct S1 { p voidptr } + struct S2 { i int } diff --git a/vlib/v/tests/sorting_by_different_criteria_test.v b/vlib/v/tests/sorting_by_different_criteria_test.v index c54d1b1a7c..9323e46f6b 100644 --- a/vlib/v/tests/sorting_by_different_criteria_test.v +++ b/vlib/v/tests/sorting_by_different_criteria_test.v @@ -8,7 +8,7 @@ struct Parent { } fn (p Parent) < (p1 Parent) bool { - return p.name < p1.name + return p.name < p1.name } fn test_sorting_by_different_criteria_in_same_function() { diff --git a/vlib/v/tests/sorting_by_references_test.v b/vlib/v/tests/sorting_by_references_test.v index d2e5434a43..78f4b5c98c 100644 --- a/vlib/v/tests/sorting_by_references_test.v +++ b/vlib/v/tests/sorting_by_references_test.v @@ -6,11 +6,21 @@ mut: fn test_array_sort_by_references() { mut a := []&Container{} - a << &Container{ name: 'a' } - a << &Container{ name: 'b' } - a << &Container{ name: 'c' } - a << &Container{ name: 'd' } - a << &Container{ name: 'e' } + a << &Container{ + name: 'a' + } + a << &Container{ + name: 'b' + } + a << &Container{ + name: 'c' + } + a << &Container{ + name: 'd' + } + a << &Container{ + name: 'e' + } a.sort(a.name > b.name) println(a) diff --git a/vlib/v/tests/str_gen_test.v b/vlib/v/tests/str_gen_test.v index dcefa26511..1cfcd2d6c3 100644 --- a/vlib/v/tests/str_gen_test.v +++ b/vlib/v/tests/str_gen_test.v @@ -55,31 +55,51 @@ fn test_array_of_strings() { } fn test_map_of_ints() { - aa := {'a': 1, 'b': 2, 'c': 3} + aa := map{ + 'a': 1 + 'b': 2 + 'c': 3 + } assert aa.str() == "{'a': 1, 'b': 2, 'c': 3}" assert '$aa' == "{'a': 1, 'b': 2, 'c': 3}" } fn test_map_of_strings() { - aa := {'a': '1', 'b': '2', 'c': '3'} + aa := map{ + 'a': '1' + 'b': '2' + 'c': '3' + } assert aa.str() == "{'a': '1', 'b': '2', 'c': '3'}" assert '$aa' == "{'a': '1', 'b': '2', 'c': '3'}" } fn test_map_of_floats() { - aa := {'a': 1.1, 'b': 2.2, 'c': 3.3} + aa := map{ + 'a': 1.1 + 'b': 2.2 + 'c': 3.3 + } assert aa.str() == "{'a': 1.1, 'b': 2.2, 'c': 3.3}" assert '$aa' == "{'a': 1.1, 'b': 2.2, 'c': 3.3}" } fn test_map_of_runes() { - aa := {'a': `a`, 'b': `b`, 'c': `c`} + aa := map{ + 'a': `a` + 'b': `b` + 'c': `c` + } assert aa.str() == "{'a': `a`, 'b': `b`, 'c': `c`}" assert '$aa' == "{'a': `a`, 'b': `b`, 'c': `c`}" } fn test_map_of_bools() { - aa := {'a': true, 'b': false, 'c': true} + aa := map{ + 'a': true + 'b': false + 'c': true + } assert aa.str() == "{'a': true, 'b': false, 'c': true}" assert '$aa' == "{'a': true, 'b': false, 'c': true}" } @@ -143,16 +163,18 @@ fn test_fixed_array_of_strings() { struct Wrapper { foo &string } + fn test_struct_with_string_pointer() { s := 'test' w := Wrapper{&s} - assert '$w' == 'Wrapper{\n foo: &\'test\'\n}' - assert w.str() == 'Wrapper{\n foo: &\'test\'\n}' + assert '$w' == "Wrapper{\n foo: &'test'\n}" + assert w.str() == "Wrapper{\n foo: &'test'\n}" } struct Wrapper2 { foo &int } + fn test_struct_with_int_pointer() { i := 5 w := Wrapper2{&i} @@ -163,6 +185,7 @@ fn test_struct_with_int_pointer() { struct Wrapper3 { foo &bool } + fn test_struct_with_bool_pointer() { b := true w := Wrapper3{&b} @@ -171,9 +194,11 @@ fn test_struct_with_bool_pointer() { } struct Foo {} + struct Wrapper4 { foo &Foo } + fn test_struct_with_struct_pointer() { b := Foo{} w := Wrapper4{&b} @@ -190,6 +215,7 @@ fn test_struct_with_nil() { struct Wrapper5 { foo &f32 } + fn test_struct_with_f32_pointer() { i := f32(5.1) w := Wrapper5{&i} @@ -197,13 +223,14 @@ fn test_struct_with_f32_pointer() { assert w.str() == 'Wrapper5{\n foo: &5.1\n}' } - struct TestStruct { x int } + struct ArrayWithStruct { foo []TestStruct } + fn test_array_with_struct() { a := ArrayWithStruct{[TestStruct{}]} assert a.str() == 'ArrayWithStruct{\n foo: [TestStruct{\n x: 0\n }]\n}' @@ -213,13 +240,17 @@ fn test_array_with_struct() { struct MapWithStruct { foo map[string]TestStruct } + fn test_map_with_struct() { - a := MapWithStruct{{'test': TestStruct{}}} - assert a.str() == 'MapWithStruct{\n foo: {\'test\': TestStruct{\n x: 0\n }}\n}' - assert '$a' == 'MapWithStruct{\n foo: {\'test\': TestStruct{\n x: 0\n }}\n}' + a := MapWithStruct{map{ + 'test': TestStruct{} + }} + assert a.str() == "MapWithStruct{\n foo: {'test': TestStruct{\n x: 0\n }}\n}" + assert '$a' == "MapWithStruct{\n foo: {'test': TestStruct{\n x: 0\n }}\n}" } struct ForGeneric {} + fn generic_fn_interpolation(p T) string { return '$p' } @@ -235,6 +266,7 @@ fn test_generic_auto_str() { } type Alias1 = int + fn test_alias_in_array() { t := [Alias1(1)] assert t.str() == '[1]' @@ -242,6 +274,7 @@ fn test_alias_in_array() { } type Alias2 = int + fn test_alias_in_fixed_array() { t := [Alias1(1)]! assert t.str() == '[1]' @@ -255,6 +288,7 @@ fn test_alias_int() { } type Alias3 = string + fn test_alias_string() { s := 'test' a := Alias3(s) @@ -263,6 +297,7 @@ fn test_alias_string() { } type TestAlias = TestStruct + fn test_alias_struct() { ts := TestStruct{} t := TestAlias(ts) @@ -286,7 +321,7 @@ struct MultiGenericStruct { } fn test_multi_generic_struct() { - x := MultiGenericStruct{} + x := MultiGenericStruct{} assert '$x' == 'MultiGenericStruct{\n t: TestStruct{\n x: 0\n }\n x: TestStruct{\n x: 0\n }\n}' assert x.str() == 'MultiGenericStruct{\n t: TestStruct{\n x: 0\n }\n x: TestStruct{\n x: 0\n }\n}' } @@ -296,7 +331,7 @@ fn create_option_err() ?string { } fn test_option_err() { - assert '$create_option_err()' == "Option(error: this is an error)" + assert '$create_option_err()' == 'Option(error: this is an error)' } fn create_option_none() ?string { @@ -312,7 +347,7 @@ fn create_option_string() ?string { } fn test_option_string() { - assert '$create_option_string()' == 'Option(\'this is a string\')' + assert '$create_option_string()' == "Option('this is a string')" } fn create_option_int() ?int { @@ -348,7 +383,8 @@ fn test_option_struct() { // assert '$w' == 'OptionWrapper{\n x: Option(error: \'\')\n}' // } -/* TODO: doesn't work yet +/* +TODO: doesn't work yet struct OptionWrapperInt { x ?int } @@ -360,11 +396,11 @@ fn test_struct_with_option() { */ struct One { - value string = "one" + value string = 'one' } struct Two { - value string = "two" + value string = 'two' } fn mr_int_int() (int, int) { @@ -377,10 +413,10 @@ fn mr_one_two() (One, Two) { return one, two } -fn mr_fn_fn() (fn(int), fn(int)) { - a := fn(a int) {} - b := fn(a int) {} - return a,b +fn mr_fn_fn() (fn (int), fn (int)) { + a := fn (a int) {} + b := fn (a int) {} + return a, b } fn test_multi_return() { @@ -391,7 +427,7 @@ fn test_multi_return() { }, Two{ value: 'two' })" - anon_a := fn() (One, Two) { + anon_a := fn () (One, Two) { one := One{} two := Two{} return one, two diff --git a/vlib/v/tests/string_interpolation_alias_test.v b/vlib/v/tests/string_interpolation_alias_test.v index cb576e07db..0f61cd3c4a 100644 --- a/vlib/v/tests/string_interpolation_alias_test.v +++ b/vlib/v/tests/string_interpolation_alias_test.v @@ -11,7 +11,10 @@ fn test_fixed_array_alias_string() { } fn test_map_alias_string() { - m := {'one': Literal('1'), 'two': Literal('2')} + m := map{ + 'one': Literal('1') + 'two': Literal('2') + } assert '$m'.contains("'one': '1'") assert '$m'.contains("'two': '2'") } @@ -19,7 +22,7 @@ fn test_map_alias_string() { type Duration = i64 fn test_i64_number_alias_string() { - x := i64(9_123_456_789) - y := Duration(x) - assert '$x' == '$y' + x := i64(9_123_456_789) + y := Duration(x) + assert '$x' == '$y' } diff --git a/vlib/v/tests/string_interpolation_array_test.v b/vlib/v/tests/string_interpolation_array_test.v index 918e2213b2..e6eb9ca6b4 100644 --- a/vlib/v/tests/string_interpolation_array_test.v +++ b/vlib/v/tests/string_interpolation_array_test.v @@ -16,7 +16,7 @@ struct Man { fn test_array_of_structs_interpolation() { people := [ - Man{'Superman', 30, ['flying','fighting evil','being nice']}, + Man{'Superman', 30, ['flying', 'fighting evil', 'being nice']}, Man{'Bilbo Baggins', 111, ['exploring', 'hiding']}, ] s := '$people' // the compiler should generate code for both a) and b) @@ -79,24 +79,30 @@ fn test_array_of_strings_interpolation() { fn test_array_of_map_interpolation() { mut a := []map[string]int{} - a << {'a': int(1), 'b': 2} - a << {'c': int(3), 'd': 4} + a << map{ + 'a': int(1) + 'b': 2 + } + a << map{ + 'c': int(3) + 'd': 4 + } assert '$a' == "[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]" } fn test_array_initialization_with_interpolation() { sysroot := '/usr' a := [ - 'abcd' - '$sysroot/xyz' - 'u$sysroot/vw' - '/rr$sysroot' - 'lmno' + 'abcd', + '$sysroot/xyz', + 'u$sysroot/vw', + '/rr$sysroot', + 'lmno', ] assert '$a' == "['abcd', '/usr/xyz', 'u/usr/vw', '/rr/usr', 'lmno']" b := [ - 'a${sysroot:5}/r' - 'ert' + 'a${sysroot:5}/r', + 'ert', ] assert '$b' == "['a /usr/r', 'ert']" c := ['xy', 'r$sysroot', '$sysroot/t', '>$sysroot<'] diff --git a/vlib/v/tests/string_interpolation_custom_str_test.v b/vlib/v/tests/string_interpolation_custom_str_test.v index 0fad50e1aa..91a2d9211d 100644 --- a/vlib/v/tests/string_interpolation_custom_str_test.v +++ b/vlib/v/tests/string_interpolation_custom_str_test.v @@ -3,16 +3,16 @@ struct Foo { } fn (f &Foo) str() string { - return '${f.bar}' + return '$f.bar' } -struct Bar { +struct Bar { foo &Foo } fn test_interpolation_with_custom_ref_str() { foo := Foo{} - bar := Bar { &foo } + bar := Bar{&foo} println(bar) assert '$bar'.contains('Bar{') assert '$bar'.contains('foo: &0') diff --git a/vlib/v/tests/string_interpolation_function_test.v b/vlib/v/tests/string_interpolation_function_test.v index c21fadd3bf..8a4f739a29 100644 --- a/vlib/v/tests/string_interpolation_function_test.v +++ b/vlib/v/tests/string_interpolation_function_test.v @@ -3,7 +3,9 @@ fn show(a string) string { } fn test_function_interpolation() { - f := fn()(string, bool) {return 'aaa', true} + f := fn () (string, bool) { + return 'aaa', true + } println(f) assert '$f' == 'fn () (string, bool)' @@ -12,13 +14,15 @@ fn test_function_interpolation() { } struct Info { - aa fn()string + aa fn () string bb int } fn test_function_interpolation_in_struct() { a := Info{ - aa: fn()string {return 'aaa'} + aa: fn () string { + return 'aaa' + } bb: 22 } println(a) @@ -26,14 +30,24 @@ fn test_function_interpolation_in_struct() { } fn test_function_interpolation_in_array() { - f := [fn()string{return 'aaa'}, fn()string{return 'bbb'}] + f := [fn () string { + return 'aaa' + }, fn () string { + return 'bbb' + }] println(f) assert '$f' == '[fn () string, fn () string]' } fn test_function_interpolation_in_map() { - m := {'aaa': fn()string{return 'aaa'}, 'bbb': fn()string{return 'bbb'}} + m := map{ + 'aaa': fn () string { + return 'aaa' + } + 'bbb': fn () string { + return 'bbb' + } + } println(m) assert '$m'.contains(': fn () string') } - diff --git a/vlib/v/tests/string_interpolation_multi_return_test.v b/vlib/v/tests/string_interpolation_multi_return_test.v index 688158f960..4c97db4a54 100644 --- a/vlib/v/tests/string_interpolation_multi_return_test.v +++ b/vlib/v/tests/string_interpolation_multi_return_test.v @@ -1,4 +1,3 @@ - struct RetTest {} fn (r RetTest) return_multi_1() (int, string) { @@ -6,7 +5,7 @@ fn (r RetTest) return_multi_1() (int, string) { } fn (r RetTest) return_multi_2() (string, bool, []int) { - return 'aaa', true, [1,2,3] + return 'aaa', true, [1, 2, 3] } fn (r RetTest) return_multi_3() (f32, bool, []string) { @@ -18,7 +17,7 @@ fn return_multi_4() (int, string) { } fn return_multi_5() (string, bool, []int) { - return 'aaa', true, [1,2,3] + return 'aaa', true, [1, 2, 3] } fn return_multi_6() (f32, bool, []string) { @@ -28,21 +27,21 @@ fn return_multi_6() (f32, bool, []string) { fn test_multi_return_interpolation() { r := RetTest{} - s1 := '${r.return_multi_1()}' + s1 := '$r.return_multi_1()' assert s1 == "(1, 'aaa')" - s2 := '${r.return_multi_2()}' + s2 := '$r.return_multi_2()' assert s2 == "('aaa', true, [1, 2, 3])" - s3 := '${r.return_multi_3()}' + s3 := '$r.return_multi_3()' assert s3 == "(2.2, false, ['a', 'b', 'c'])" - s4 := '${return_multi_4()}' + s4 := '$return_multi_4()' assert s4 == "(1, 'aaa')" - s5 := '${return_multi_5()}' + s5 := '$return_multi_5()' assert s5 == "('aaa', true, [1, 2, 3])" - s6 := '${return_multi_6()}' + s6 := '$return_multi_6()' assert s6 == "(2.2, false, ['a', 'b', 'c'])" } diff --git a/vlib/v/tests/string_interpolation_shared_test.v b/vlib/v/tests/string_interpolation_shared_test.v index fb0ba3b187..728fd25a85 100644 --- a/vlib/v/tests/string_interpolation_shared_test.v +++ b/vlib/v/tests/string_interpolation_shared_test.v @@ -8,7 +8,9 @@ struct Qwe { } fn test_shared_struct_interpolation() { - shared s := Abc{ x: 6.25 } + shared s := Abc{ + x: 6.25 + } astr := rlock s { '$s' } @@ -26,17 +28,27 @@ fn test_shared_array_interpolation() { } fn test_shared_map_interpolation() { - shared m := {'xy': 12.125, 'qwe': -6.0625, 'foo': 0.5} + shared m := map{ + 'xy': 12.125 + 'qwe': -6.0625 + 'foo': 0.5 + } mstr := rlock m { '$m' } assert mstr == "{'xy': 12.125, 'qwe': -6.0625, 'foo': 0.5}" -} +} fn test_print_shared() { - shared s := Abc{ x: 6.25 } + shared s := Abc{ + x: 6.25 + } shared a := [0.25, -6.125, 12.5] - shared m := {'xy': 12.125, 'qwe': -6.0625, 'foo': 0.5} + shared m := map{ + 'xy': 12.125 + 'qwe': -6.0625 + 'foo': 0.5 + } x, y := rlock a, s { println(s) println(a) @@ -52,4 +64,3 @@ fn test_print_shared() { assert y == '[0.25, -6.125, 12.5]' assert z == "{'xy': 12.125, 'qwe': -6.0625, 'foo': 0.5}" } - diff --git a/vlib/v/tests/string_interpolation_string_args_test.v b/vlib/v/tests/string_interpolation_string_args_test.v index 9ad701855b..0081f7279b 100644 --- a/vlib/v/tests/string_interpolation_string_args_test.v +++ b/vlib/v/tests/string_interpolation_string_args_test.v @@ -7,25 +7,25 @@ fn show_more_info(a string, b string) string { } fn test_interpolation_string_args() { - assert '${show_info("abc")}' == 'abc' + assert '${show_info('abc')}' == 'abc' assert '${show_info('abc')}' == 'abc' - assert '1_${show_info("aaa")} 2_${show_info("bbb")}' == '1_aaa 2_bbb' + assert '1_${show_info('aaa')} 2_${show_info('bbb')}' == '1_aaa 2_bbb' assert '1_${show_info('aaa')} 2_${show_info('bbb')}' == '1_aaa 2_bbb' - assert '${"aaa"}' == 'aaa' + assert '${'aaa'}' == 'aaa' assert '${'aaa'}' == 'aaa' - assert '${"aaa" + "bbb"}' == 'aaabbb' assert '${'aaa' + 'bbb'}' == 'aaabbb' - assert '${"aaa" + 'bbb'}' == 'aaabbb' - assert '${'aaa' + "bbb"}' == 'aaabbb' + assert '${'aaa' + 'bbb'}' == 'aaabbb' + assert '${'aaa' + 'bbb'}' == 'aaabbb' + assert '${'aaa' + 'bbb'}' == 'aaabbb' - assert '${show_more_info("aaa", "bbb")}' == 'aaabbb' assert '${show_more_info('aaa', 'bbb')}' == 'aaabbb' - assert '${show_more_info("aaa", 'bbb')}' == 'aaabbb' - assert '${show_more_info('aaa', "bbb")}' == 'aaabbb' + assert '${show_more_info('aaa', 'bbb')}' == 'aaabbb' + assert '${show_more_info('aaa', 'bbb')}' == 'aaabbb' + assert '${show_more_info('aaa', 'bbb')}' == 'aaabbb' - assert '1_${show_more_info("aaa", "111")} 2_${show_more_info("bbb", "222")}' == '1_aaa111 2_bbb222' + assert '1_${show_more_info('aaa', '111')} 2_${show_more_info('bbb', '222')}' == '1_aaa111 2_bbb222' assert '1_${show_more_info('aaa', '111')} 2_${show_more_info('bbb', '222')}' == '1_aaa111 2_bbb222' } diff --git a/vlib/v/tests/string_interpolation_struct_test.v b/vlib/v/tests/string_interpolation_struct_test.v index bf1d3ecf7e..087926b67c 100644 --- a/vlib/v/tests/string_interpolation_struct_test.v +++ b/vlib/v/tests/string_interpolation_struct_test.v @@ -42,7 +42,10 @@ struct Info { fn test_struct_map_field_string_interpolation() { info := Info{ name: 'test' - dict: {'a': int(1), 'b': 2} + dict: map{ + 'a': int(1) + 'b': 2 + } } s := '$info' assert s.starts_with('Info{') diff --git a/vlib/v/tests/string_interpolation_test.v b/vlib/v/tests/string_interpolation_test.v index bed3a1954d..fc399d8e58 100644 --- a/vlib/v/tests/string_interpolation_test.v +++ b/vlib/v/tests/string_interpolation_test.v @@ -38,11 +38,11 @@ fn test_excape_dollar_in_string() { assert !'(\\$i)'.contains('i') && '(\\$i)'.contains('42') && '(\\$i)'.contains('\\') assert '(\\\$i)'.contains('i') && !'(\\\$i)'.contains('42') && '(\\$i)'.contains('\\') assert !'(\\\\$i)'.contains('i') && '(\\\\$i)'.contains('42') && '(\\\\$i)'.contains('\\\\') - assert '(${i})' == '(42)' + assert '($i)' == '(42)' assert '(\${i})'.contains('i') && !'(\${i})'.contains('42') - assert !'(\\${i})'.contains('i') && '(\\${i})'.contains('42') && '(\\${i})'.contains('\\') - assert '(\\\${i})'.contains('i') && !'(\\\${i})'.contains('42') && '(\\${i})'.contains('\\') - assert !'(\\\\${i})'.contains('i') && '(\\\\${i})'.contains('42') && '(\\\\${i})'.contains('\\\\') + assert !'(\\$i)'.contains('i') && '(\\$i)'.contains('42') && '(\\$i)'.contains('\\') + assert '(\\\${i})'.contains('i') && !'(\\\${i})'.contains('42') && '(\\$i)'.contains('\\') + assert !'(\\\\$i)'.contains('i') && '(\\\\$i)'.contains('42') && '(\\\\$i)'.contains('\\\\') assert i == 42 } @@ -80,9 +80,9 @@ fn test_interpolation_string_prefix_expr() { r := 1 c := 2 js := 1 - assert '>${3+r}<' == '>4<' + assert '>${3 + r}<' == '>4<' assert '${r == js} $js' == 'true 1' - assert '>${js+c} ${js+r==c}<' == '>3 true<' + assert '>${js + c} ${js + r == c}<' == '>3 true<' } fn test_inttypes_string_interpolation() { @@ -97,8 +97,7 @@ fn test_inttypes_string_interpolation() { mut bp := byteptr(0) $if x64 { bp = byteptr(15541149836) - } - $else { + } $else { bp = byteptr(3541149836) } l := i64(-7694555558525237396) @@ -116,15 +115,12 @@ fn test_inttypes_string_interpolation() { // default pointer format is platform dependent, so try a few eprintln("platform pointer format: '${vp:p}:$bp'") $if x64 { - assert '${vp:p}:$bp' == '0xcbf6efc7:0x39e53208c' || - '${vp:p}:$bp' == 'CBF6EFC7:39E53208C' || - '${vp:p}:$bp' == 'cbf6efc7:39e53208c' || - '${vp:p}:$bp' == '00000000CBF6EFC7:000000039E53208C' - } - $else { - assert '${vp:p}:$bp' == 'CBF6EFC7:D311A88C' || - '${vp:p}:$bp' == 'cbf6efc7:d311a88c' || - '${vp:p}:$bp' == '0xcbf6efc7:0xd311a88c' + assert '${vp:p}:$bp' == '0xcbf6efc7:0x39e53208c' || '${vp:p}:$bp' == 'CBF6EFC7:39E53208C' + || '${vp:p}:$bp' == 'cbf6efc7:39e53208c' + || '${vp:p}:$bp' == '00000000CBF6EFC7:000000039E53208C' + } $else { + assert '${vp:p}:$bp' == 'CBF6EFC7:D311A88C' || '${vp:p}:$bp' == 'cbf6efc7:d311a88c' + || '${vp:p}:$bp' == '0xcbf6efc7:0xd311a88c' } } @@ -154,7 +150,7 @@ struct Sss { } fn (s Sss) str() string { - return '[${s.v1}, ${s.v2:.3f}]' + return '[$s.v1, ${s.v2:.3f}]' } fn test_string_interpolation_str_evaluation() { @@ -162,7 +158,6 @@ fn test_string_interpolation_str_evaluation() { assert '$x' == '[17, 13.456]' } - fn test_string_interpolation_with_negative_format_width_should_compile_and_run_without_segfaulting() { // discovered during debugging VLS i := 3 @@ -192,7 +187,7 @@ fn test_method_interpolation() { a: 2 } } - assert '>${y.f().a}<' == '>2<' + assert '>$y.f().a<' == '>2<' assert '>$y.f().a<' == '>2<' } diff --git a/vlib/v/tests/string_struct_interpolation_test.v b/vlib/v/tests/string_struct_interpolation_test.v index 3f426d389f..2c64efd387 100644 --- a/vlib/v/tests/string_struct_interpolation_test.v +++ b/vlib/v/tests/string_struct_interpolation_test.v @@ -10,7 +10,7 @@ fn (f Foo) baz() string { fn test_string_method_interpolation() { foo := Foo{} - s := 'baz=${foo.baz()}' + s := 'baz=$foo.baz()' assert s == 'baz=baz' } diff --git a/vlib/v/tests/struct_allow_both_field_defaults_and_skip_flag_test.v b/vlib/v/tests/struct_allow_both_field_defaults_and_skip_flag_test.v index fefc3905ab..b01f9334da 100644 --- a/vlib/v/tests/struct_allow_both_field_defaults_and_skip_flag_test.v +++ b/vlib/v/tests/struct_allow_both_field_defaults_and_skip_flag_test.v @@ -1,14 +1,14 @@ import json struct Foo { - x int = 123 + x int = 123 bar int [skip] = -112233 - y int = 456 + y int = 456 } fn test_check_field_default_expr() { f := Foo{} - //eprintln('f: $f') + // eprintln('f: $f') assert f.bar == -112233 assert f.x == 123 assert f.y == 456 @@ -17,7 +17,7 @@ fn test_check_field_default_expr() { fn test_check_field_skip_attribute() { f := Foo{} s := json.encode(f) - //eprintln('f: $f') - //eprintln('s: $s') + // eprintln('f: $f') + // eprintln('s: $s') assert s == '{"x":123,"y":456}' } diff --git a/vlib/v/tests/struct_chained_fields_correct_test.v b/vlib/v/tests/struct_chained_fields_correct_test.v index 9696ecb15e..f1e86ca8ee 100644 --- a/vlib/v/tests/struct_chained_fields_correct_test.v +++ b/vlib/v/tests/struct_chained_fields_correct_test.v @@ -1,13 +1,34 @@ +struct Axx { +mut: + v int +} -struct Axx { mut: v int } -struct Bxx { a Axx } -struct Cxx { mut: b Bxx } -struct Dxx { mut: c Cxx } -struct Exx { mut: v []int } -struct Fxx { e []Exx } +struct Bxx { + a Axx +} + +struct Cxx { +mut: + b Bxx +} + +struct Dxx { +mut: + c Cxx +} + +struct Exx { +mut: + v []int +} + +struct Fxx { + e []Exx +} fn test_chained_string() { - mut b := Bxx{} b = Bxx{Axx{2}} + mut b := Bxx{} + b = Bxx{Axx{2}} assert 'b is: ' + b.a.v.str() == 'b is: 2' } diff --git a/vlib/v/tests/struct_embed_test.v b/vlib/v/tests/struct_embed_test.v index 44892d4bb5..6732ebb616 100644 --- a/vlib/v/tests/struct_embed_test.v +++ b/vlib/v/tests/struct_embed_test.v @@ -1,5 +1,5 @@ import flag -import field_publicity +import v.tests.field_publicity struct Foo { x int @@ -19,12 +19,16 @@ fn test_embed() { } fn test_embed_direct_access() { - b := Bar{Foo: Foo{}} + b := Bar{ + Foo: Foo{} + } assert b.Foo.y == 5 } fn test_default_value() { - b := Bar{Foo: Foo{}} + b := Bar{ + Foo: Foo{} + } assert b.y == 5 } @@ -32,7 +36,9 @@ fn test_default_value_without_init() { b := Bar{} assert b.y == 5 } -/* TODO + +/* +TODO fn test_initialize() { b := Bar{x: 1, y: 2} assert b.x == 1 @@ -57,9 +63,11 @@ struct BarGeneric { pub: foo T } + struct BarGenericContainer { BarGeneric } + fn test_generic_embed() { b := BarGenericContainer{} assert b.BarGeneric.foo == 0 @@ -83,7 +91,7 @@ fn test_assign() { fn test_embed_is_public() { a := field_publicity.App{} - assert a.Context.name == '' + assert a.Context.name == '' } struct Eggs { diff --git a/vlib/v/tests/struct_eq_op_only_test.v b/vlib/v/tests/struct_eq_op_only_test.v index f03115e590..812e0d7487 100644 --- a/vlib/v/tests/struct_eq_op_only_test.v +++ b/vlib/v/tests/struct_eq_op_only_test.v @@ -1,6 +1,6 @@ struct User { name string - num int + num int } fn (u User) == (u1 User) bool { diff --git a/vlib/v/tests/struct_field_default_value_interface_cast_test.v b/vlib/v/tests/struct_field_default_value_interface_cast_test.v index 0613a2f229..92df4b2bf1 100644 --- a/vlib/v/tests/struct_field_default_value_interface_cast_test.v +++ b/vlib/v/tests/struct_field_default_value_interface_cast_test.v @@ -7,7 +7,9 @@ interface FooBar { } struct Abc { - foobar FooBar = Foo { x: 123 } + foobar FooBar = Foo{ + x: 123 + } } fn test_struct_field_default_value_interface_cast() { diff --git a/vlib/v/tests/struct_field_default_value_sumtype_cast_test.v b/vlib/v/tests/struct_field_default_value_sumtype_cast_test.v index df907f0b04..0692415512 100644 --- a/vlib/v/tests/struct_field_default_value_sumtype_cast_test.v +++ b/vlib/v/tests/struct_field_default_value_sumtype_cast_test.v @@ -4,10 +4,12 @@ struct Foo { struct Bar {} -type FooBar = Foo | Bar +type FooBar = Bar | Foo struct Abc { - foobar FooBar = Foo { x: 123 } + foobar FooBar = Foo{ + x: 123 + } } fn test_struct_field_default_value_sumtype_cast() { diff --git a/vlib/v/tests/struct_test.v b/vlib/v/tests/struct_test.v index 2e2f9c3bc7..0abf360395 100644 --- a/vlib/v/tests/struct_test.v +++ b/vlib/v/tests/struct_test.v @@ -18,9 +18,9 @@ mut: } struct Lol { - b []string [json:lol] - c string [json:cc] - d int + b []string [json: lol] + c string [json: cc] + d int } struct User { @@ -68,10 +68,10 @@ fn test_empty_struct() { d := &Empty{} d2 := Empty{} println('&empty:') - println(d) // != voidptr(0) + println(d) // != voidptr(0) println('empty:') - println(d2) // empty struct print - println(sizeof(Empty)) // == 0 + println(d2) // empty struct print + println(sizeof(Empty)) // == 0 } fn test_struct_levels() { @@ -106,7 +106,7 @@ fn test_struct_levels() { fn test_struct_str() { u := User{'Bob', 30} - println(u) // make sure the struct is printable + println(u) // make sure the struct is printable // assert u.str() == '{name:"Bob", age:30}' // QTODO } @@ -132,7 +132,7 @@ fn test_reserved_keywords() { // Make sure partial initialization works too. assert rk_holder2.inline == 9 assert rk_holder2.volatile == 11 - assert rk_holder2.while == 0 // Zero value as not specified. + assert rk_holder2.while == 0 // Zero value as not specified. } struct User2 { @@ -170,12 +170,19 @@ fn test_assoc_with_vars() { } assert merged.a == 42 assert merged.b == 7 - merged = {...def2, b: 9} + merged = { + ...def2 + b: 9 + } assert merged == Def{12, 9} - def3 := &Def{ 100, 200 } - merged1 := Def{...(*def3)} - merged2 := &Def{...(*def3)} + def3 := &Def{100, 200} + merged1 := Def{ + ...(*def3) + } + merged2 := &Def{ + ...(*def3) + } assert merged1.a == 100 assert merged1.b == 200 assert merged2.a == 100 @@ -199,7 +206,7 @@ fn test_assoc_with_constants() { again := { const_def | b: 22 } assert again.a == 100 assert again.b == 22 -*/ + */ } struct AttrTest { @@ -249,9 +256,11 @@ mut: fn foo_config(def int, c Config) { assert c.def == def } + fn bar_config(c Config, def int) { assert c.def == def } + fn mut_bar_config(mut c Config, def int) &Config { c.n = c.def assert c.n == def @@ -261,24 +270,22 @@ fn mut_bar_config(mut c Config, def int) &Config { fn foo_user(u User) {} fn test_struct_literal_args() { - foo_config(20, { + foo_config(20, n: 10 def: 20 - }) + ) foo_config(10, {}) foo_config(10, n: 40) foo_config(40, n: 30, def: 40) bar_config({}, 10) - bar_config({def:4}, 4) + bar_config({ def: 4 }, 4) - c := mut_bar_config(mut {def: 10}, 10) + c := mut_bar_config(mut { def: 10 }, 10) assert c.n == 10 assert c.def == 10 - foo_user({ - name: 'Peter' - }) + foo_user(name: 'Peter') foo_user(name: 'Peter') foo_user(age: 7) foo_user(name: 'Stew', age: 50) @@ -312,8 +319,8 @@ struct StructWithDefaultValues1 { // Struct where an inizialized field is before a non-initilized field. struct StructWithDefaultValues2 { - field_optional int = 3 - field_required int + field_optional int = 3 + field_required int } // Struct where an inizialized field is before several non-initilized fields. @@ -324,10 +331,16 @@ struct StructWithDefaultValues3 { } fn test_struct_with_default_values_init() { - s1 := StructWithDefaultValues1{ field_required: 5 } - s2 := StructWithDefaultValues2{ field_required: 5 } + s1 := StructWithDefaultValues1{ + field_required: 5 + } + s2 := StructWithDefaultValues2{ + field_required: 5 + } // Partially initialized - s3 := StructWithDefaultValues3{ field_required: 5 } + s3 := StructWithDefaultValues3{ + field_required: 5 + } assert s1.field_optional == 5 assert s2.field_optional == 3 @@ -346,49 +359,49 @@ fn test_struct_with_default_values_no_init() { } struct FieldsWithOptionalVoidReturnType { - f fn() ? - g fn() ? + f fn () ? + g fn () ? } fn test_fields_anon_fn_with_optional_void_return_type() { - foo := FieldsWithOptionalVoidReturnType { - f: fn() ? { - return error("oops") + foo := FieldsWithOptionalVoidReturnType{ + f: fn () ? { + return error('oops') } - g: fn() ? { + g: fn () ? { return } } - foo.f() or { - assert err.msg == "oops" - } + foo.f() or { assert err.msg == 'oops' } - foo.g() or { - assert false - } + foo.g() or { assert false } } struct Commands { - show []fn() string + show []fn () string } fn a() string { - return 'HELLOW' + return 'HELLOW' } fn b() string { - return 'WOLLEH' + return 'WOLLEH' } fn test_fields_array_of_fn() { - commands := Commands{show: [a, b]} - println(commands.show) + commands := Commands{ + show: [a, b] + } + println(commands.show) assert '$commands.show' == '[fn () string, fn () string]' } fn test_struct_update() { - c := Country{name: 'test'} + c := Country{ + name: 'test' + } c2 := Country{ ...c capital: City{ diff --git a/vlib/v/tests/struct_transmute_test.v b/vlib/v/tests/struct_transmute_test.v index a789aa968f..20c83de467 100644 --- a/vlib/v/tests/struct_transmute_test.v +++ b/vlib/v/tests/struct_transmute_test.v @@ -1,12 +1,12 @@ struct Foo { - age int + age int name string } // different order struct Bar { name string - age int + age int } fn test_order() { @@ -17,7 +17,7 @@ fn test_order() { b := Bar{ ...f } - assert b == Bar{'f',4} + assert b == Bar{'f', 4} b2 := Bar{ ...f name: 'b2' @@ -27,13 +27,13 @@ fn test_order() { } struct Qux { - name string - age int + name string + age int extra bool } fn test_extra() { - f := Foo{4,'f'} + f := Foo{4, 'f'} q := Qux{ ...f extra: true diff --git a/vlib/v/tests/sum_type_common_fields_test.v b/vlib/v/tests/sum_type_common_fields_test.v index e935fbe810..fc6500aae0 100644 --- a/vlib/v/tests/sum_type_common_fields_test.v +++ b/vlib/v/tests/sum_type_common_fields_test.v @@ -45,4 +45,3 @@ fn test_common_sumtype_field_access() { assert out0.val == 1 assert out0.name == 'one' } - diff --git a/vlib/v/tests/sum_type_test.v b/vlib/v/tests/sum_type_test.v index 7e95595ed5..0f0084984e 100644 --- a/vlib/v/tests/sum_type_test.v +++ b/vlib/v/tests/sum_type_test.v @@ -44,16 +44,24 @@ fn test_sum_type_match() { assert as_string(int(1)) == 'This is the string representation of "1"' assert as_string(f64(3.14)) == 'This is the string representation of "3.14"' assert as_string('String') == 'This is the string representation of "String"' - assert as_string(IntAndStr{foo: 2, bar: 'hi', baz: &IntAndStr{foo: 3, bar: 'hello', baz: 0}}) == 'This is the string representation of "5_hi_hello"' + assert as_string(IntAndStr{ + foo: 2 + bar: 'hi' + baz: &IntAndStr{ + foo: 3 + bar: 'hello' + baz: 0 + } + }) == 'This is the string representation of "5_hi_hello"' assert as_string(true) == 'This is the string representation of "true"' assert as_string(CommonType(Color.red)) == 'This is the string representation of "enum1_red"' assert as_string(CommonType(Color.green)) == 'This is the string representation of "enum2_green"' assert as_string(CommonType(Color.blue)) == 'This is the string representation of "enum3_blue"' assert sumtype_match_with_string_interpolation(1) == "it's an int: 5" assert sumtype_match_with_string_interpolation(2) == "it's a string: hello" - assert sumtype_match_with_string_interpolation(3) == "green_green" + assert sumtype_match_with_string_interpolation(3) == 'green_green' assert sumtype_match_with_string_interpolation(4) == "it's a f64: 1.5" - assert sumtype_match_with_string_interpolation(5) == "it's a bool: false" + assert sumtype_match_with_string_interpolation(5) == "it's a bool: false" assert sumtype_match_with_string_interpolation(6) == "it's an IntAndStr: 2_hi_3_hello" } @@ -98,7 +106,6 @@ fn test_converting_down() { assert res[1].name == 'three' } - fn test_assignment_and_push() { mut expr1 := Expr{} mut arr1 := []Expr{} @@ -132,11 +139,11 @@ fn test_zero_value_init() { _ := Outer2{} } -type Bar = string | Test +type Bar = Test | string type Xyz = int | string struct Test { - x string + x string xyz Xyz } @@ -164,11 +171,11 @@ fn test_as_cast() { } fn test_typeof() { - x := Expr(IfExpr{}) + x := Expr(IfExpr{}) assert x.type_name() == 'IfExpr' } -type Food = Milk | Eggs +type Food = Eggs | Milk struct FoodWrapper { mut: @@ -242,7 +249,6 @@ fn test_non_mut_ident_mut_selector_cast_if() { if w is FoodWrapper { if w.food is Eggs { assert w.food.name + '2' == 'test2' - } else { assert false } @@ -289,7 +295,7 @@ fn test_int_cast_to_sumtype() { } } -type Number = int | f64 +type Number = f64 | int fn is_gt_simple(val string, dst Number) bool { match dst { @@ -397,16 +403,20 @@ struct IntAndStr { baz &IntAndStr } -enum Color { red green blue } +enum Color { + red + green + blue +} -type CommonType = int | f64 | string | IntAndStr | bool | Color +type CommonType = Color | IntAndStr | bool | f64 | int | string fn as_string(val CommonType) string { return 'This is the string representation of "' + val.str() + '"' } fn (c CommonType) str() string { - match c { + match c { string { d := c.int() _ := d @@ -441,7 +451,7 @@ fn (c CommonType) str() string { fn sumtype_match_with_string_interpolation(code int) string { match code { 1 { - bar := CommonType(5) + bar := CommonType(5) match bar { f64 { return "shouldn't happen" } bool { return "shouldn't happen" } @@ -465,14 +475,24 @@ fn sumtype_match_with_string_interpolation(code int) string { 3 { bar := CommonType(Color.green) match bar { - string { return "shouldn't happen" } - int { return "shouldn't happen" } - f64 { return "shouldn't happen" } - bool { return "shouldn't happen" } - IntAndStr { return "shouldn't happen" } + string { + return "shouldn't happen" + } + int { + return "shouldn't happen" + } + f64 { + return "shouldn't happen" + } + bool { + return "shouldn't happen" + } + IntAndStr { + return "shouldn't happen" + } Color { match bar { - .red { return 'red_$bar'} + .red { return 'red_$bar' } .green { return 'green_$bar' } .blue { return 'blue_$bar' } } @@ -506,17 +526,27 @@ fn sumtype_match_with_string_interpolation(code int) string { // TODO: this should work // mut bar := CommonType(100) // bar = CommonType(IntAndStr{foo: 2, bar: 'hi', baz: &IntAndStr{foo: 3, bar: 'hello', baz: 0}}) - bar := CommonType(IntAndStr{foo: 2, bar: 'hi', baz: &IntAndStr{foo: 3, bar: 'hello', baz: 0}}) + bar := CommonType(IntAndStr{ + foo: 2 + bar: 'hi' + baz: &IntAndStr{ + foo: 3 + bar: 'hello' + baz: 0 + } + }) match bar { string { return "shouldn't happen" } int { return "shouldn't happen" } Color { return "shouldn't happen" } f64 { return "shouldn't happen" } bool { return "shouldn't happen" } - IntAndStr { return "it's an IntAndStr: ${bar.foo}_${bar.bar}_${bar.baz.foo}_${bar.baz.bar}" } + IntAndStr { return "it's an IntAndStr: ${bar.foo}_${bar.bar}_${bar.baz.foo}_$bar.baz.bar" } } } - else { return 'wrong' } + else { + return 'wrong' + } } } @@ -566,15 +596,23 @@ fn size(tree Tree) int { // insert a value to BST fn insert(tree Tree, x f64) Tree { match tree { - Empty { return Node{x, tree, tree} } - Node { + Empty { + return Node{x, tree, tree} + } + Node { return if x == tree.value { tree } else if x < tree.value { - Node{...tree, left: insert(tree.left, x)} + Node{ + ...tree + left: insert(tree.left, x) + } } else { - Node{...tree, right: insert(tree.right, x)} - } + Node{ + ...tree + right: insert(tree.right, x) + } + } } } } @@ -582,15 +620,17 @@ fn insert(tree Tree, x f64) Tree { // whether able to find a value in BST fn search(tree Tree, x f64) bool { match tree { - Empty { return false } - Node { + Empty { + return false + } + Node { return if x == tree.value { true } else if x < tree.value { search(tree.left, x) } else { search(tree.right, x) - } + } } } } @@ -606,20 +646,46 @@ fn min(tree Tree) f64 { // delete a value in BST (if nonexist do nothing) fn delete(tree Tree, x f64) Tree { match tree { - Empty { return tree } + Empty { + return tree + } Node { if tree.left is Node && tree.right is Node { - return if x < tree.value { - Node{...tree, left: delete(tree.left, x)} + return if x < tree.value { + Node{ + ...tree + left: delete(tree.left, x) + } } else if x > tree.value { - Node{...tree, right: delete(tree.right, x)} + Node{ + ...tree + right: delete(tree.right, x) + } } else { - Node{...tree, value: min(tree.right), right: delete(tree.right, min(tree.right))} - } + Node{ + ...tree + value: min(tree.right) + right: delete(tree.right, min(tree.right)) + } + } } else if tree.left is Node { - return if x == tree.value { tree.left } else { Node{...tree, left: delete(tree.left, x)} } + return if x == tree.value { + tree.left + } else { + Node{ + ...tree + left: delete(tree.left, x) + } + } } else { - if x == tree.value { return tree.right } else { return Node{...tree, right: delete(tree.right, x)} } + if x == tree.value { + return tree.right + } else { + return Node{ + ...tree + right: delete(tree.right, x) + } + } } } } @@ -637,7 +703,7 @@ fn test_binary_search_tree() { tree = delete(tree, i) } assert size(tree) == 7 - mut deleted := []f64{ } + mut deleted := []f64{} for i in input { if !search(tree, i) { deleted << i diff --git a/vlib/v/tests/sumtype_equality_test.v b/vlib/v/tests/sumtype_equality_test.v index 057159d1b0..beac8dae99 100644 --- a/vlib/v/tests/sumtype_equality_test.v +++ b/vlib/v/tests/sumtype_equality_test.v @@ -8,7 +8,7 @@ struct Bar { v int } -type FooBar = Foo | Bar +type FooBar = Bar | Foo fn test_sumtype_equality() { s1 := Str('s') @@ -22,8 +22,12 @@ fn test_sumtype_equality() { assert u1 != s1 // Same value, defferent type - foo := FooBar(Foo{v: 0}) - bar := FooBar(Bar{v: 0}) + foo := FooBar(Foo{ + v: 0 + }) + bar := FooBar(Bar{ + v: 0 + }) assert foo.v == bar.v assert foo != bar } diff --git a/vlib/v/tests/sumtype_str_for_subtypes_with_str_test.v b/vlib/v/tests/sumtype_str_for_subtypes_with_str_test.v index a9b34f03b5..f031ca1371 100644 --- a/vlib/v/tests/sumtype_str_for_subtypes_with_str_test.v +++ b/vlib/v/tests/sumtype_str_for_subtypes_with_str_test.v @@ -25,7 +25,7 @@ fn (dict Dictionary) str() string { fn test_str_of_sumtype_works() { o := Object(Dictionary{ - items: { + items: map{ 'abc': Object(Stream{ content: 'xyz' }) diff --git a/vlib/v/tests/sumtype_str_test.v b/vlib/v/tests/sumtype_str_test.v index 602cbe18f9..ce319f1188 100644 --- a/vlib/v/tests/sumtype_str_test.v +++ b/vlib/v/tests/sumtype_str_test.v @@ -4,7 +4,7 @@ struct Abc { str string } -type ST = int | string | bool | Abc +type ST = Abc | bool | int | string fn test_int_st_str() { a := ST(0) @@ -14,14 +14,14 @@ fn test_int_st_str() { fn test_string_st_str() { a := ST('test') - assert '$a' == 'ST(\'test\')' - assert a.str() == 'ST(\'test\')' + assert '$a' == "ST('test')" + assert a.str() == "ST('test')" } fn test_struct_st_str() { a := ST(Abc{}) - assert '$a' == 'ST(Abc{\n foo: 0\n bar: false\n str: \'\'\n})' - assert a.str() == 'ST(Abc{\n foo: 0\n bar: false\n str: \'\'\n})' + assert '$a' == "ST(Abc{\n foo: 0\n bar: false\n str: ''\n})" + assert a.str() == "ST(Abc{\n foo: 0\n bar: false\n str: ''\n})" } fn test_bool_st_str() { @@ -49,8 +49,8 @@ fn test_unknown_value() { fn test_nested_in_struct() { abc := Abc{} c := Container{ST(abc)} - assert '$c' == 'Container{\n st: ST(Abc{\n foo: 0\n bar: false\n str: \'\'\n })\n}' - assert c.str() == 'Container{\n st: ST(Abc{\n foo: 0\n bar: false\n str: \'\'\n })\n}' + assert '$c' == "Container{\n st: ST(Abc{\n foo: 0\n bar: false\n str: ''\n })\n}" + assert c.str() == "Container{\n st: ST(Abc{\n foo: 0\n bar: false\n str: ''\n })\n}" } fn test_pointer() { diff --git a/vlib/v/tests/tmpl_test.v b/vlib/v/tests/tmpl_test.v index 169e0790af..d3f6d5fcf3 100644 --- a/vlib/v/tests/tmpl_test.v +++ b/vlib/v/tests/tmpl_test.v @@ -45,7 +45,6 @@ so, it's basically true" fn test_tmpl_in_anon_fn() { anon := fn (name string, age int, numbers []int, downloads map[string]string, ignored bool) string { - return $tmpl('tmpl/base.txt') } diff --git a/vlib/v/tests/type_alias_test.v b/vlib/v/tests/type_alias_test.v index 6c9ad0239c..bada874624 100644 --- a/vlib/v/tests/type_alias_test.v +++ b/vlib/v/tests/type_alias_test.v @@ -25,9 +25,10 @@ fn test_type_alias_v2() { } struct Mystruct { - mut: +mut: i int } + type Mystruct_2 = Mystruct fn test_type_alias_struct() { diff --git a/vlib/v/tests/type_name_test.v b/vlib/v/tests/type_name_test.v index b069b0c66d..7d978c6fdc 100644 --- a/vlib/v/tests/type_name_test.v +++ b/vlib/v/tests/type_name_test.v @@ -4,15 +4,15 @@ fn simple(p T) string { return tname } -struct FunkyStruct{ } +struct FunkyStruct {} fn test_generic_type_name() { i := 42 - assert simple(i) == "int" + assert simple(i) == 'int' f := 3.14 - assert simple(f) == "f64" - assert simple("FuBar") == "string" - assert simple(FunkyStruct{}) == "FunkyStruct" - assert simple(fn(){}) == "fn ()" - //assert simple(test_generic_type_name) == "fn ()" + assert simple(f) == 'f64' + assert simple('FuBar') == 'string' + assert simple(FunkyStruct{}) == 'FunkyStruct' + assert simple(fn () {}) == 'fn ()' + // assert simple(test_generic_type_name) == "fn ()" } diff --git a/vlib/v/tests/type_promotion_test.v b/vlib/v/tests/type_promotion_test.v index 21ae13aa11..8465e847fa 100644 --- a/vlib/v/tests/type_promotion_test.v +++ b/vlib/v/tests/type_promotion_test.v @@ -14,7 +14,7 @@ fn test_anyfloat() { } fn g(x f32) f32 { - return x*x + return x * x } fn fabs(x f32) f32 { @@ -26,7 +26,7 @@ fn test_call() { r := g(f32(c) / 255.0) assert fabs(r - 3.890949634755863) <= 1.e-6 } - + struct Tx { x f32 } @@ -37,16 +37,16 @@ fn (s Tx) get() f32 { fn test_struct_init() { c := 503 - d := Tx { - x: g(f32(c) / 255.0) + d := Tx{ + x: g(f32(c) / 255.0) } assert fabs(d.get() - 3.890949634755863) < 1.e-6 } fn struct_init_return() Tx { c := 503 - return Tx { - x: g(f32(c) / 255.0) + return Tx{ + x: g(f32(c) / 255.0) } } @@ -57,8 +57,8 @@ fn test_struct_init_return() { fn struct_init_ref_return() &Tx { c := 503 - return &Tx { - x: g(f32(c) / 255.0) + return &Tx{ + x: g(f32(c) / 255.0) } } diff --git a/vlib/v/tests/unsafe_test.v b/vlib/v/tests/unsafe_test.v index e21a284865..3e7f705f2b 100644 --- a/vlib/v/tests/unsafe_test.v +++ b/vlib/v/tests/unsafe_test.v @@ -34,9 +34,9 @@ fn test_double_ptr() { fn test_ptr_infix() { v := 4 - mut q := unsafe {&v - 1} - q = unsafe {q + 3} - assert ptr_str(q) == ptr_str(unsafe {&v + 2}) + mut q := unsafe { &v - 1 } + q = unsafe { q + 3 } + assert ptr_str(q) == ptr_str(unsafe { &v + 2 }) } struct S1 { @@ -48,13 +48,13 @@ fn (s S1) f() { fn test_funcs() { s := S1{} - unsafe {s.f()} + unsafe { s.f() } _ = C.strerror(0) // [trusted] function prototype in builtin/cfns.c.v } fn test_if_expr_unsafe() { i := 4 - p := if true { unsafe {&i} } else { unsafe {&i} } + p := if true { unsafe { &i } } else { unsafe { &i } } assert *p == 4 } diff --git a/vlib/v/tests/valgrind/option_reassigned.v b/vlib/v/tests/valgrind/option_reassigned.v index 26ce1c1c32..50812e2dd3 100644 --- a/vlib/v/tests/valgrind/option_reassigned.v +++ b/vlib/v/tests/valgrind/option_reassigned.v @@ -2,8 +2,6 @@ import os fn main() { mut a := 'abc' - a = os.find_abs_path_of_executable('ls') or { - '' - } + a = os.find_abs_path_of_executable('ls') or { '' } eprintln(a) } diff --git a/vlib/v/tests/valgrind/option_simple.v b/vlib/v/tests/valgrind/option_simple.v index bdd8691a15..5b9d8fce86 100644 --- a/vlib/v/tests/valgrind/option_simple.v +++ b/vlib/v/tests/valgrind/option_simple.v @@ -1,8 +1,6 @@ import os fn main() { - a := os.find_abs_path_of_executable('ls') or { - '' - } + a := os.find_abs_path_of_executable('ls') or { '' } eprintln(a) } diff --git a/vlib/v/tests/vmod_parser_test.v b/vlib/v/tests/vmod_parser_test.v index e8db9d9bae..8d75f1b8e9 100644 --- a/vlib/v/tests/vmod_parser_test.v +++ b/vlib/v/tests/vmod_parser_test.v @@ -1,4 +1,4 @@ -import vmod +import v.vmod import os fn test_from_file() { @@ -6,7 +6,7 @@ fn test_from_file() { data := vmod.from_file('./v.mod') or { panic(err) } assert data.name == 'V' assert data.description == 'The V programming language.' - //assert data.version == '0.2.1' + // assert data.version == '0.2.1' assert data.version.contains('.') assert data.version.starts_with('0.') assert data.dependencies.len == 0 @@ -15,14 +15,14 @@ fn test_from_file() { fn test_decode() { content := " Module { - name: \'foobar\', - description: \'Just a sample module\' - version: \'0.2.0\', - repo_url: \'https://gitlab.com\', - author: \'Fooz Bar\', - license: \'GPL-2.0\', - dependencies: [\'hello\'], - test: \'foo\' + name: 'foobar', + description: 'Just a sample module' + version: '0.2.0', + repo_url: 'https://gitlab.com', + author: 'Fooz Bar', + license: 'GPL-2.0', + dependencies: ['hello'], + test: 'foo' } " data := vmod.decode(content) or { diff --git a/vlib/v/tests/voidptr_to_u64_cast_a_test.v b/vlib/v/tests/voidptr_to_u64_cast_a_test.v index e664984a29..78fbd9c92f 100644 --- a/vlib/v/tests/voidptr_to_u64_cast_a_test.v +++ b/vlib/v/tests/voidptr_to_u64_cast_a_test.v @@ -6,5 +6,5 @@ fn test_void_pointer_to_u64_cast_via_fn_call() { a := u64(10) b := voidptr(a) c := receive_addr_return_u64(b) - assert (a == c) + assert a == c } diff --git a/vlib/v/tests/voidptr_to_u64_cast_b_test.v b/vlib/v/tests/voidptr_to_u64_cast_b_test.v index aa2251ed44..ede249f854 100644 --- a/vlib/v/tests/voidptr_to_u64_cast_b_test.v +++ b/vlib/v/tests/voidptr_to_u64_cast_b_test.v @@ -6,5 +6,5 @@ fn test_u64_to_void_pointer_cast_via_fn_call() { a := u64(100) b := receive_u64_return_addr(a) c := u64(b) - assert (a == c) + assert a == c } diff --git a/vlib/v/tests/working_with_an_empty_struct_test.v b/vlib/v/tests/working_with_an_empty_struct_test.v index 67ac926115..ce14ee4988 100644 --- a/vlib/v/tests/working_with_an_empty_struct_test.v +++ b/vlib/v/tests/working_with_an_empty_struct_test.v @@ -1,5 +1,9 @@ struct EmptyStruct {} -pub fn (f EmptyStruct) str() string { return 'EmptyStruct{}' } + +pub fn (f EmptyStruct) str() string { + return 'EmptyStruct{}' +} + fn new_s() EmptyStruct { println('>get_foo') return EmptyStruct{}