feat: implement eager * operator for String and List to repeat content by integer count
Add `*(count)` method to both String and List classes in wren_core.wren, enabling eager repetition of string characters or list elements. The operator validates that count is a non-negative integer, aborting with a clear error message otherwise. For strings, concatenates the original string count times; for lists, builds a new list by adding all elements count times. Includes comprehensive test cases for normal, zero, and edge-case inputs, plus error tests for negative, non-integer, and non-numeric counts. Also refactors existing list plus tests to use inline expressions and adds a plus_not_iterable error test.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
System.print("|" + "abc" * 0 + "|") // expect: ||
|
||||
System.print("abc" * 1) // expect: abc
|
||||
System.print("abc" * 4) // expect: abcabcabcabc
|
||||
@@ -0,0 +1 @@
|
||||
"abc" * -3 // expect runtime error: Count must be a non-negative integer.
|
||||
@@ -0,0 +1 @@
|
||||
"abc" * 1.2 // expect runtime error: Count must be a non-negative integer.
|
||||
@@ -0,0 +1 @@
|
||||
"abc" * "not num" // expect runtime error: Count must be a non-negative integer.
|
||||
Reference in New Issue
Block a user