feat: implement List.addAll() method to append elements from iterable
Add `addAll(other)` method to the List class in both the Wren core library source and its embedded C string representation. The method iterates over the given `other` sequence, appends each element to the list using the existing `add()` method, and returns the original `other` argument to match the documented return behavior. Include a new test file `test/list/add_all.wren` covering basic appending, empty iterable, range input, and return value verification.
This commit is contained in:
+1
-3
@@ -1,6 +1,4 @@
|
||||
var a = []
|
||||
a.add(1)
|
||||
IO.print(a) // expect: [1]
|
||||
var a = [1]
|
||||
a.add(2)
|
||||
IO.print(a) // expect: [1, 2]
|
||||
a.add(3)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
var a = [1]
|
||||
a.addAll([2, 3])
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
a.addAll([])
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
a.addAll(4..6)
|
||||
IO.print(a) // expect: [1, 2, 3, 4, 5, 6]
|
||||
|
||||
// Returns argument.
|
||||
var range = 7..9
|
||||
IO.print(a.addAll(range) == range) // expect: true
|
||||
Reference in New Issue
Block a user