mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Update string_iterator.c3 to include extra convenience methods (#1327)
Update string_iterator.c3 to include extra convenience methods Added peek: returns the next character without incrementing current Added has_next: checks if the iterator has another element Added get: gets the current element (the same one that was returned with the previous call to next).
This commit is contained in:
35
test/unit/stdlib/core/string_iterator.c3
Normal file
35
test/unit/stdlib/core/string_iterator.c3
Normal file
@@ -0,0 +1,35 @@
|
||||
module std::core::test::string_iterator::tests @test;
|
||||
|
||||
fn void test_at_start()
|
||||
{
|
||||
String test = "abcd";
|
||||
StringIterator iterator = test.iterator();
|
||||
assert(iterator.get()! == 'a');
|
||||
assert(iterator.peek()! == 'a');
|
||||
iterator.next()!;
|
||||
assert(iterator.next()! == 'b');
|
||||
assert(iterator.has_next());
|
||||
}
|
||||
|
||||
|
||||
fn void test_general()
|
||||
{
|
||||
String test = "åƦs1";
|
||||
StringIterator iterator = test.iterator();
|
||||
assert(iterator.get()! == 'å');
|
||||
iterator.next()!;
|
||||
assert(iterator.peek()! == 'Ʀ');
|
||||
assert(iterator.next()! == 'Ʀ');
|
||||
iterator.reset();
|
||||
assert(iterator.current == 0);
|
||||
}
|
||||
|
||||
fn void test_end()
|
||||
{
|
||||
String test = "åƦ";
|
||||
StringIterator iterator = test.iterator();
|
||||
assert(@ok(iterator.next()));
|
||||
assert(iterator.peek()! == 'Ʀ');
|
||||
assert(@ok(iterator.next()));
|
||||
assert(@catch(iterator.next()));
|
||||
}
|
||||
Reference in New Issue
Block a user