From 24ac0c1fb5ca14ab5f8ccb4f2cc3f0c790afb780 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 29 Mar 2024 07:59:11 +0300 Subject: [PATCH] builtin: fix tests --- examples/sokol/06_obj_viewer/modules/obj/obj.v | 2 +- vlib/builtin/string_test.v | 12 ++++++------ vlib/v/checker/tests/type_cast_option_err.out | 2 +- vlib/v/checker/tests/type_cast_option_err.vv | 2 +- vlib/v/tests/option_default_values_test.v | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/sokol/06_obj_viewer/modules/obj/obj.v b/examples/sokol/06_obj_viewer/modules/obj/obj.v index 5ede5a0da14c7f..f23b3d98f66654 100644 --- a/examples/sokol/06_obj_viewer/modules/obj/obj.v +++ b/examples/sokol/06_obj_viewer/modules/obj/obj.v @@ -232,7 +232,7 @@ pub fn (mut obj_part ObjPart) parse_obj_buffer(rows []string, single_material bo mat_count++ mut part := Part{} if mat_count > 1 { - li := obj_part.part[obj_part.part.len - 1].name.index_last('_m') or { + li := obj_part.part[obj_part.part.len - 1].name.last_index('_m') or { obj_part.part[obj_part.part.len - 1].name.len - 1 } part.name = obj_part.part[obj_part.part.len - 1].name[..li] + diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 8f483398fea445..82a0ce8ff99e9d 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -1309,7 +1309,7 @@ fn test_string_literal_with_backslash_followed_by_newline() { Five \\\\\ end' assert b == 'One Two Three ${single_backslash}Four ${double_backslash}${newline} Five ${double_backslash}end' - + // Note `\\` is followed *directly* by a newline, but `\\` is just an escape for `\`, // and thus the newline has no special meaning, and should go into the string literal. c := 'Hello\\ @@ -1481,11 +1481,11 @@ fn test_index_u8() { } fn test_index_last() { - assert 'abcabca'.index_last('ca')? == 5 - assert 'abcabca'.index_last('ab')? == 3 - assert 'abcabca'.index_last('b')? == 4 - assert 'Zabcabca'.index_last('Z')? == 0 - x := 'Zabcabca'.index_last('Y') + assert 'abcabca'.last_index('ca')? == 5 + assert 'abcabca'.last_index('ab')? == 3 + assert 'abcabca'.last_index('b')? == 4 + assert 'Zabcabca'.last_index('Z')? == 0 + x := 'Zabcabca'.last_index('Y') assert x == none // TODO: `assert 'Zabcabca'.index_last('Y') == none` is a cgen error, 2023/12/04 } diff --git a/vlib/v/checker/tests/type_cast_option_err.out b/vlib/v/checker/tests/type_cast_option_err.out index 99d0c32cd44fcd..95931d13f977d4 100644 --- a/vlib/v/checker/tests/type_cast_option_err.out +++ b/vlib/v/checker/tests/type_cast_option_err.out @@ -1,5 +1,5 @@ vlib/v/checker/tests/type_cast_option_err.vv:2:10: error: cannot type cast an Option 1 | fn main() { - 2 | println(int('hi'.index_last('i'))) + 2 | println(int('hi'.last_index('i'))) | ~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | } diff --git a/vlib/v/checker/tests/type_cast_option_err.vv b/vlib/v/checker/tests/type_cast_option_err.vv index 821faa08ed12e1..5c9cc124e4d833 100644 --- a/vlib/v/checker/tests/type_cast_option_err.vv +++ b/vlib/v/checker/tests/type_cast_option_err.vv @@ -1,3 +1,3 @@ fn main() { - println(int('hi'.index_last('i'))) + println(int('hi'.last_index('i'))) } diff --git a/vlib/v/tests/option_default_values_test.v b/vlib/v/tests/option_default_values_test.v index 22d82b314e199f..759501eb728c2a 100644 --- a/vlib/v/tests/option_default_values_test.v +++ b/vlib/v/tests/option_default_values_test.v @@ -127,7 +127,7 @@ fn test_nested_option_with_opt_fn_call_as_last_value() { fn remove_suffix1(s string) string { n := s.len - i := s.index_last('.') or { n } + i := s.last_index('.') or { n } return s[0..i] }