1
0
forked from Mirror/wren

Tweak new list constructors.

- Remove List.new(_). I was convinced by the issue discussion that
  using it is probably a bad idea. We don't want to encourage more nulls
  in the world than there are already are. So let's see if we can live
  without it and just have List.filled(). That way users think about
  what they're creating a list *of*.
- Added some more tests.
- Correctly handle being given a negative size.
This commit is contained in:
Bob Nystrom
2016-08-03 22:42:31 -07:00
parent 3de394e8a1
commit 3666eae013
6 changed files with 29 additions and 45 deletions

View File

@ -0,0 +1,8 @@
var list = List.filled(3, "value")
System.print(list.count) // expect: 3
System.print(list) // expect: [value, value, value]
// Can create an empty list.
list = List.filled(0, "value")
System.print(list.count) // expect: 0
System.print(list) // expect: []

View File

@ -0,0 +1 @@
List.filled(-1, null) // expect runtime error: Size cannot be negative.

View File

@ -0,0 +1 @@
List.filled(1.2, null) // expect runtime error: Size must be an integer.

View File

@ -0,0 +1 @@
List.filled("not num", null) // expect runtime error: Size must be a number.

View File

@ -1,8 +0,0 @@
var list = List.new(5)
System.print(list.count) // expect: 5
System.print(list) // expect: [null, null, null, null, null]
var list2 = List.filled(5, 2)
System.print(list2.count) // expect: 5
System.print(list2) // expect: [2, 2, 2, 2, 2]