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:
Bob Nystrom
2016-02-24 15:48:03 +00:00
parent c9390c624b
commit b301e9f119
12 changed files with 74 additions and 15 deletions
+3
View File
@@ -0,0 +1,3 @@
System.print("|" + "abc" * 0 + "|") // expect: ||
System.print("abc" * 1) // expect: abc
System.print("abc" * 4) // expect: abcabcabcabc
+1
View File
@@ -0,0 +1 @@
"abc" * -3 // expect runtime error: Count must be a non-negative integer.
+1
View File
@@ -0,0 +1 @@
"abc" * 1.2 // expect runtime error: Count must be a non-negative integer.
+1
View File
@@ -0,0 +1 @@
"abc" * "not num" // expect runtime error: Count must be a non-negative integer.