mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
std/lib: simplify String.{,r}index_of and improve speed for the index… (#907)
* std/lib: simplify String.{,r}index_of and improve speed for the index_of one
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
* lib/std/collections: add EnumMap.get_ref
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
---------
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -80,6 +80,7 @@ fn void! test_index_of()
|
||||
String test = "hello world hello";
|
||||
assert(test.index_of("o")! == 4);
|
||||
assert(test.index_of("ll")! == 2);
|
||||
assert(test.index_of(" hello")! == 11);
|
||||
assert(@catchof(test.index_of("wi")));
|
||||
}
|
||||
|
||||
@@ -90,6 +91,7 @@ fn void! test_rindex_of()
|
||||
assert(test.rindex_of("ll")! == 14);
|
||||
assert(test.rindex_of("he")! == 12);
|
||||
assert(test.rindex_of("world")! == 6);
|
||||
assert(test.rindex_of("hello ")! == 0);
|
||||
assert(@catchof(test.rindex_of("wi")));
|
||||
}
|
||||
|
||||
@@ -98,6 +100,7 @@ fn void! test_index_of_char()
|
||||
String test = "hello world hello";
|
||||
assert(test.index_of_char('o')! == 4);
|
||||
assert(test.index_of_char('l')! == 2);
|
||||
assert(test.index_of_char('h')! == 0);
|
||||
assert(@catchof(test.index_of_char('x')));
|
||||
}
|
||||
|
||||
@@ -106,5 +109,6 @@ fn void! test_rindex_of_char()
|
||||
String test = "hello world hello";
|
||||
assert(test.rindex_of_char('o')! == 16);
|
||||
assert(test.rindex_of_char('l')! == 15);
|
||||
assert(test.rindex_of_char('h')! == 12);
|
||||
assert(@catchof(test.index_of_char('x')));
|
||||
}
|
||||
Reference in New Issue
Block a user