forked from Mirror/wren
2
test/core/map/is_empty.wren
Normal file
2
test/core/map/is_empty.wren
Normal file
@ -0,0 +1,2 @@
|
||||
System.print({}.isEmpty) // expect: true
|
||||
System.print({1: 1}.isEmpty) // expect: false
|
||||
45
test/core/map/iterate.wren
Normal file
45
test/core/map/iterate.wren
Normal file
@ -0,0 +1,45 @@
|
||||
var a = {"one": 1, "two": 2, "three": 3, "four": 4}
|
||||
|
||||
// The precise numeric values aren't defined since they are indexes into the
|
||||
// entry table and the hashing process isn't specified. So we just validate
|
||||
// what we can assume about them.
|
||||
|
||||
System.print(a.iterate(null) is Num) // expect: true
|
||||
System.print(a.iterate(null) >= 0) // expect: true
|
||||
|
||||
System.print(a.iterate(0) is Num) // expect: true
|
||||
System.print(a.iterate(0) > 0) // expect: true
|
||||
System.print(a.iterate(1) is Num) // expect: true
|
||||
System.print(a.iterate(1) > 0) // expect: true
|
||||
System.print(a.iterate(2) is Num) // expect: true
|
||||
System.print(a.iterate(2) > 0) // expect: true
|
||||
System.print(a.iterate(3) is Num) // expect: true
|
||||
System.print(a.iterate(3) > 0) // expect: true
|
||||
|
||||
var previous = -1
|
||||
var iterator = a.iterate(null)
|
||||
while (iterator) {
|
||||
System.print(iterator > previous)
|
||||
System.print(iterator is Num)
|
||||
previous = iterator
|
||||
iterator = a.iterate(iterator)
|
||||
}
|
||||
// First entry:
|
||||
// expect: true
|
||||
// expect: true
|
||||
// Second entry:
|
||||
// expect: true
|
||||
// expect: true
|
||||
// Third entry:
|
||||
// expect: true
|
||||
// expect: true
|
||||
// Fourth entry:
|
||||
// expect: true
|
||||
// expect: true
|
||||
|
||||
// Out of bounds.
|
||||
System.print(a.iterate(16)) // expect: false
|
||||
System.print(a.iterate(-1)) // expect: false
|
||||
|
||||
// Nothing to iterate in an empty map.
|
||||
System.print({}.iterate(null)) // expect: false
|
||||
2
test/core/map/iterate_iterator_not_int.wren
Normal file
2
test/core/map/iterate_iterator_not_int.wren
Normal file
@ -0,0 +1,2 @@
|
||||
var a = {1: 2, 3: 4}
|
||||
a.iterate(1.5) // expect runtime error: Iterator must be an integer.
|
||||
2
test/core/map/iterate_iterator_not_num.wren
Normal file
2
test/core/map/iterate_iterator_not_num.wren
Normal file
@ -0,0 +1,2 @@
|
||||
var a = {1: 2, 3: 4}
|
||||
a.iterate("2") // expect runtime error: Iterator must be a number.
|
||||
13
test/core/map/iterator_value.wren
Normal file
13
test/core/map/iterator_value.wren
Normal file
@ -0,0 +1,13 @@
|
||||
var a = {1: "one"}
|
||||
|
||||
// The actual iterator values are implementation specific, so ask the map.
|
||||
var iterator = a.iterate(null)
|
||||
var value = a.iteratorValue(iterator)
|
||||
|
||||
System.print(value is MapEntry) // expect: true
|
||||
System.print(value.key) // expect: 1
|
||||
System.print(value.value) // expect: one
|
||||
|
||||
// The entry does not track the underlying map.
|
||||
a[1] = "updated"
|
||||
System.print(value.value) // expect: one
|
||||
2
test/core/map/iterator_value_iterator_not_int.wren
Normal file
2
test/core/map/iterator_value_iterator_not_int.wren
Normal file
@ -0,0 +1,2 @@
|
||||
var a = {1: "one"}
|
||||
a.iteratorValue(1.5) // expect runtime error: Iterator must be an integer.
|
||||
2
test/core/map/iterator_value_iterator_not_num.wren
Normal file
2
test/core/map/iterator_value_iterator_not_num.wren
Normal file
@ -0,0 +1,2 @@
|
||||
var a = {1: "one"}
|
||||
a.iteratorValue("2") // expect runtime error: Iterator must be a number.
|
||||
6
test/core/map/iterator_value_iterator_too_large.wren
Normal file
6
test/core/map/iterator_value_iterator_too_large.wren
Normal file
@ -0,0 +1,6 @@
|
||||
var a = {1: "one"}
|
||||
|
||||
// The maximum value is based on the map's capacity, not its count, so use a
|
||||
// sufficiently large enough value for the test to make not affected by growth
|
||||
// strategy.
|
||||
a.iteratorValue(9999) // expect runtime error: Iterator out of bounds.
|
||||
6
test/core/map/iterator_value_iterator_too_small.wren
Normal file
6
test/core/map/iterator_value_iterator_too_small.wren
Normal file
@ -0,0 +1,6 @@
|
||||
var a = {1: "one"}
|
||||
|
||||
// The maximum value is based on the map's capacity, not its count, so use a
|
||||
// sufficiently large enough value for the test to make not affected by growth
|
||||
// strategy.
|
||||
a.iteratorValue(-9999) // expect runtime error: Iterator out of bounds.
|
||||
4
test/core/map_entry/new.wren
Normal file
4
test/core/map_entry/new.wren
Normal file
@ -0,0 +1,4 @@
|
||||
var entry = MapEntry.new("key", "value")
|
||||
|
||||
System.print(entry.key) // expect: key
|
||||
System.print(entry.value) // expect: value
|
||||
Reference in New Issue
Block a user