Skip to content

Instantly share code, notes, and snippets.

@erikcorry
Created January 6, 2023 13:44
Show Gist options
  • Save erikcorry/5bc9e3c6c154fcab7b76157363e967a1 to your computer and use it in GitHub Desktop.
Save erikcorry/5bc9e3c6c154fcab7b76157363e967a1 to your computer and use it in GitHub Desktop.
diff --git a/examples/bubble_sort.toit b/examples/bubble_sort.toit
index 0ceee960..d28172d0 100644
--- a/examples/bubble_sort.toit
+++ b/examples/bubble_sort.toit
@@ -11,8 +11,8 @@ main:
bubble_sort a:
size := a.size
- for i := 0; i < size; i++:
+ for i := ..size:
limit := size - i - 1
- for j := 0; j < limit; j++:
+ for j := ..limit:
if a[j] > a[j + 1]: a.swap j j+1
assert: a.is_sorted
diff --git a/examples/mandelbrot.toit b/examples/mandelbrot.toit
index 08c69faf..7d84ce19 100644
--- a/examples/mandelbrot.toit
+++ b/examples/mandelbrot.toit
@@ -13,7 +13,7 @@ mandelbrot width height x_center y_center scale limit:
ByteArray height
y_scale := scale * 2;
for y := height - 1; y >= 0; y--:
- for x := 0; x < width; x++:
+ for x := ..width:
pixels[x][y] = do_pixel
(x - (width >> 1)) * scale + x_center
(y - (height >> 1)) * y_scale + y_center
diff --git a/lib/core/collections.toit b/lib/core/collections.toit
index a5e9a22e..cd0a3a5e 100644
--- a/lib/core/collections.toit
+++ b/lib/core/collections.toit
@@ -360,7 +360,7 @@ abstract class List extends CollectionBase:
for i := size - 1; i >= 0; i--:
entry := this[i]
if entry == needle:
- for j := i + 1; j < size; j++:
+ for j := i + 1 .. size:
this[j - 1] = this[j]
resize size - 1
break
@@ -611,7 +611,7 @@ abstract class List extends CollectionBase:
index_of --last/bool=false needle from/int=0 to/int=size [--if_absent]:
if not 0 <= from <= size: throw "BAD ARGUMENTS"
if not last:
- for i := from; i < to; i++:
+ for i := from..to:
if this[i] == needle: return i
else:
for i := to - 1; i >= from; i--:
@@ -743,7 +743,7 @@ abstract class List extends CollectionBase:
r = this[right]
insertion_sort_ from/int to/int [compare]:
- for i := from + 1; i < to; i++:
+ for i := from + 1 .. to:
element := this[i]
if (compare.call element this[i - 1]) < 0:
j := i - 2
@@ -1381,7 +1381,7 @@ abstract class ByteArrayBase_ implements ByteArray:
return float.from_bits bits
do_utf8_with_replacements_ from to [block]:
- for i := from; i < to; i++:
+ for i := from..to:
c := this[i]
bytes := 1
if c >= 0xf0:
@@ -1808,7 +1808,7 @@ class List_ extends List:
array_ = array_.resize_for_list_ size_ (round_up new_size LargeArray_.ARRAYLET_SIZE) null
// Clear entries so they can be GC'ed.
limit := min size_ array_.size
- for i := new_size; i < limit; i++:
+ for i := new_size..limit:
array_[i] = null
size_ = new_size
diff --git a/lib/core/numbers.toit b/lib/core/numbers.toit
index 34205fba..63816c62 100644
--- a/lib/core/numbers.toit
+++ b/lib/core/numbers.toit
@@ -979,7 +979,7 @@ abstract class int extends num:
```
*/
repeat [block] -> none:
- for index := 0; index < this; index++: block.call index
+ for index := ..this: block.call index
/**
Returns the number of initial zeros in the binary representation of the
diff --git a/lib/core/string.toit b/lib/core/string.toit
index b3e7d83b..b18e1721 100644
--- a/lib/core/string.toit
+++ b/lib/core/string.toit
@@ -223,7 +223,7 @@ abstract class string implements Comparable:
```
*/
do [block] -> none:
- for i := 0; i < size; i++: block.call this[i]
+ for i := ..size: block.call this[i]
/**
Iterates over all runes (Unicode "code point") and calls the given $block with the values.
@@ -240,7 +240,7 @@ abstract class string implements Comparable:
*/
do --runes/bool [block] -> none:
if runes != true: throw "Bad Argument"
- for i := 0; i < size; i++:
+ for i := ..size:
rune := this[i]
if rune: block.call rune
@@ -1170,7 +1170,7 @@ abstract class string implements Comparable:
bytes := ByteArray result_size
next_from := 0
next_to := 0
- for i := 0; i < positions.size; i++:
+ for i := ..positions.size:
this_position := positions[i]
write_to_byte_array_ bytes next_from this_position next_to
next_to += this_position - next_from
diff --git a/lib/crypto/crc.toit b/lib/crypto/crc.toit
index 112ef774..ac718475 100644
--- a/lib/crypto/crc.toit
+++ b/lib/crypto/crc.toit
@@ -74,7 +74,7 @@ class Crc extends Checksum:
constructor.little_endian .width/int --normal_polynomial/int --initial_state/int=0 --.xor_result/int=0:
if not 3 <= width <= 64: throw "INVALID_ARGUMENT"
poly := 0
- for i := 0; i < width; i++:
+ for i := ..width:
if (normal_polynomial >> i) & 1 == 1:
poly |= 1 << (width - 1 - i)
if width < 64 and poly > (1 << width): throw "Polynomial and width don't match"
diff --git a/lib/encoding/json.toit b/lib/encoding/json.toit
index eb27f8ca..47128a03 100644
--- a/lib/encoding/json.toit
+++ b/lib/encoding/json.toit
@@ -271,7 +271,7 @@ class Encoder extends Buffer_:
put_list size/int [generator] [converter]:
put_byte_ '['
- for i := 0; i < size; i++:
+ for i := ..size:
if i > 0: put_byte_ ','
encode (generator.call i) converter
diff --git a/lib/encoding/ubjson.toit b/lib/encoding/ubjson.toit
index 5fb3fb95..8b066e16 100644
--- a/lib/encoding/ubjson.toit
+++ b/lib/encoding/ubjson.toit
@@ -83,7 +83,7 @@ class Encoder:
buffer_.write_byte '['
buffer_.write_byte '#'
encode_int_ list.size
- for i := 0; i < list.size; i++:
+ for i := ..list.size:
encode_ list[i]
encode_string_ str:
diff --git a/lib/encoding/url.toit b/lib/encoding/url.toit
index 95379ffc..19705682 100644
--- a/lib/encoding/url.toit
+++ b/lib/encoding/url.toit
@@ -80,7 +80,7 @@ decode data -> any:
if c == '%': count++
result := ByteArray data.size - count * 2
j := 0
- for i := 0; i < data.size; i++:
+ for i := ..data.size:
c := data[i]
if c == '%':
c = (hex_char_to_value data[i + 1]) << 4
diff --git a/lib/expect.toit b/lib/expect.toit
index c2f99059..f05649b4 100644
--- a/lib/expect.toit
+++ b/lib/expect.toit
@@ -84,7 +84,7 @@ expect_list_equals expected/List actual/List:
list_equals_ expected/List actual -> bool:
if actual is List and actual.size == expected.size:
all_good := true
- for i := 0; i < expected.size; i++:
+ for i := ..expected.size:
if not structural_equals_ expected[i] actual[i]:
all_good = false
break
@@ -110,7 +110,7 @@ expect_bytes_equal expected/ByteArray actual/ByteArray:
expect false --message="Expected <$expected> (size $expected.size), but was <$actual> (size $actual.size)"
all_good := true
- for i := 0; i < expected.size; i++:
+ for i := ..expected.size:
if expected[i] != actual[i]:
expect false --message="Expected <$expected>, but was <$actual> (differ at position $i, expected $expected[i], but was $actual[i])"
diff --git a/lib/i2c.toit b/lib/i2c.toit
index 562923fe..1957f323 100644
--- a/lib/i2c.toit
+++ b/lib/i2c.toit
@@ -53,7 +53,7 @@ class Bus:
*/
scan -> Set:
result := {}
- for i := 0x08; i < 0x78; i++:
+ for i := 0x08..0x78:
if test i: result.add i
return result
diff --git a/lib/serial/registers.toit b/lib/serial/registers.toit
index c3e188fe..93ffeceb 100644
--- a/lib/serial/registers.toit
+++ b/lib/serial/registers.toit
@@ -302,7 +302,7 @@ abstract class Registers:
*/
dump --from=128 --to=256 --width=8:
line := ""
- for i := 0; i < to - from; i++:
+ for i := .. to - from:
if line.size > 0: line += " "
line += "0x"
v := read_u8 from + i
diff --git a/lib/services/arguments.toit b/lib/services/arguments.toit
index 267df68c..a7bc67ba 100644
--- a/lib/services/arguments.toit
+++ b/lib/services/arguments.toit
@@ -91,7 +91,7 @@ parse_ grammar command arguments index:
while index < arguments.size:
argument := arguments[index]
if argument == "--":
- for i := index + 1; i < arguments.size; i++: rest.add arguments[i]
+ for i := index + 1 .. arguments.size: rest.add arguments[i]
break // We're done!
option := null
diff --git a/lib/uuid.toit b/lib/uuid.toit
index 3beb37a9..1897c3e6 100644
--- a/lib/uuid.toit
+++ b/lib/uuid.toit
@@ -120,7 +120,7 @@ class Uuid:
stringify:
buffer := ByteArray 36
index := 0
- for i := 0; i < SIZE; i++:
+ for i := ..SIZE:
if index == 8 or index == 13 or index == 18 or index == 23:
buffer[index++] = '-'
c := bytes_[i]
@@ -142,7 +142,7 @@ class Uuid:
operator == other -> bool:
if other is not Uuid: return false
other_bytes := other.bytes_
- for i := 0; i < SIZE; i++:
+ for i := ..SIZE:
if bytes_[i] != other_bytes[i]: return false
return true
diff --git a/src/compiler/resolver_method.cc b/src/compiler/resolver_method.cc
index c586565a..5e75ac2c 100644
--- a/src/compiler/resolver_method.cc
+++ b/src/compiler/resolver_method.cc
@@ -1773,7 +1773,7 @@ void MethodResolver::visit_loop(ast::Node* node,
if (ast_initializer != null && ast_initializer->is_DeclarationLocal()) {
// Something like:
- // for x := 0; x < 10; x++:
+ // for x := ..10:
// x.bar
auto loop_variable_declaration = ast_initializer->as_DeclarationLocal();
diff --git a/system/flash/registry.toit b/system/flash/registry.toit
index e5c211e8..67dabcc8 100644
--- a/system/flash/registry.toit
+++ b/system/flash/registry.toit
@@ -94,7 +94,7 @@ class FlashRegistry:
// with the coalesced holes.
last/FlashHole_ := holes[0]
result := [last]
- for i := 1; i < holes.size; i++:
+ for i := 1..holes.size:
hole := holes[i]
if last.offset + last.size == hole.offset:
last.size += hole.size
diff --git a/tests/array_and_list_test.toit b/tests/array_and_list_test.toit
index 9e85cc62..69886895 100644
--- a/tests/array_and_list_test.toit
+++ b/tests/array_and_list_test.toit
@@ -173,10 +173,10 @@ test_large_array_do:
(copy as LargeArray_).vector_[it]
// Verify that values were copied.
copy_edge := min size (min new_size copy_size)
- for i := 0; i < copy_edge; i++:
+ for i := ..copy_edge:
expect_equals i copy[i]
// Verify filler was used.
- for i := copy_edge; i < new_size; i++:
+ for i := copy_edge..new_size:
expect_equals FILLER copy[i]
test_matrix:
diff --git a/tests/big_byte_array_literal_test.toit b/tests/big_byte_array_literal_test.toit
index f01df02f..0d9ba086 100644
--- a/tests/big_byte_array_literal_test.toit
+++ b/tests/big_byte_array_literal_test.toit
@@ -1129,7 +1129,7 @@ main:
lists := [BIG1, BIG2, BIG3, BIG4]
lists.do: |big|
expect (big is CowByteArray_)
- for i := 0; i < big.size; i++:
+ for i := ..big.size:
if i % 1000 == 0:
expect_equals (i / 100) big[i]
else if i % 100 == 0:
diff --git a/tests/bitmap_test_slow.toit b/tests/bitmap_test_slow.toit
index 71566167..ef207e08 100644
--- a/tests/bitmap_test_slow.toit
+++ b/tests/bitmap_test_slow.toit
@@ -496,8 +496,8 @@ blur_gold ba width x_radius y_radius=x_radius:
ba2 := ba.copy
if x_radius == 0: x_radius = 1
if y_radius == 0: y_radius = 1
- for y := 0; y < ba.size/width; y++:
- for x := x_radius - 1; x < width - (x_radius - 1); x++:
+ for y := ..ba.size/width:
+ for x := x_radius - 1 .. width - (x_radius - 1):
sum := 0
if x_radius < 2:
sum = blur_get ba width x y
@@ -515,8 +515,8 @@ blur_gold ba width x_radius y_radius=x_radius:
sum >>= 4
blur_set ba2 width x y sum
result := ba2.copy
- for x := 0; x < width; x++:
- for y := y_radius - 1; y < ba.size/width - (y_radius - 1); y++:
+ for x := ..width:
+ for y := y_radius - 1 .. ba.size/width - (y_radius - 1):
sum := 0
if y_radius < 2:
sum = blur_get ba2 width x y
@@ -538,17 +538,17 @@ blur_gold ba width x_radius y_radius=x_radius:
blur_compare ba ba2 width x_radius y_radius=x_radius:
if x_radius < 1: x_radius = 1
if y_radius < 1: y_radius = 1
- for x := x_radius - 1; x < width - (x_radius - 1); x++:
- for y := y_radius - 1; y < ba.size/width - (y_radius - 1); y++:
+ for x := x_radius - 1 .. width - (x_radius - 1):
+ for y := y_radius - 1 .. ba.size/width - (y_radius - 1):
if ba[x + y * width] != ba2[x + y * width]:
print "Differ at $x $y $(x + y * width): $ba[x + y * width] vs $ba2[x + y * width]"
expect_equals ba[x + y * width] ba2[x + y * width]
blur_log ba width:
print ""
- for y := 0; y < ba.size/width; y++:
+ for y := ..ba.size/width:
line := ""
- for x := 0; x < width; x++:
+ for x := ..width:
line += "$(%3d ba[x + y * width]) "
print line
diff --git a/tests/block4_test.toit b/tests/block4_test.toit
index 9181a2f7..e1573f1d 100644
--- a/tests/block4_test.toit
+++ b/tests/block4_test.toit
@@ -12,6 +12,6 @@ main:
b
expect_null b2
- b2 = for i := 0; i < 1; i++:
+ b2 = for i := ..1:
b
expect_null b2
diff --git a/tests/byte_array_test.toit b/tests/byte_array_test.toit
index 10ea2515..16a050b7 100644
--- a/tests/byte_array_test.toit
+++ b/tests/byte_array_test.toit
@@ -126,7 +126,7 @@ test_basic:
b5 = #[1 + 1]
test_slices:
- for i := 0; i < 4; i++:
+ for i := ..4:
bytes := #[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
bytes_long := #[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
if i == 0:
diff --git a/tests/captured_loop2_test.toit b/tests/captured_loop2_test.toit
index e4d50d34..894725f7 100644
--- a/tests/captured_loop2_test.toit
+++ b/tests/captured_loop2_test.toit
@@ -34,7 +34,7 @@ main:
for x := 0; x < ITERATIONS; (run: (funs.add:: x)):
x++
- for i := 0; i < ITERATIONS - 1; i++:
+ for i := .. ITERATIONS - 1:
// The 'x' that is captured in the update, corresponds to the
// one of the *next* iteration. The first time we enter the
// update clause, 'x' is already equal to 'x' (because of the increment
@@ -50,7 +50,7 @@ main:
for x := 0; x++ < ITERATIONS; (run: (funs.add:: x)):
x
- for i := 0; i < ITERATIONS; i++:
+ for i := ..ITERATIONS:
// The 'x' that is captured in the update, corresponds to the
// one of the *next* iteration. The first time we get into the
// update clause, x is equal to 1, which is then immediately
diff --git a/tests/captured_loop_test.toit b/tests/captured_loop_test.toit
index 58892a50..a30d4f26 100644
--- a/tests/captured_loop_test.toit
+++ b/tests/captured_loop_test.toit
@@ -7,13 +7,13 @@ import expect show *
main:
funs := []
- for i := 0; i < 3; i++:
+ for i := ..3:
funs.add (:: i)
3.repeat:
expect_equals it funs[it].call
funs = []
- for i := 0; i < 6; i++:
+ for i := ..6:
funs.add (:: i)
i++
3.repeat:
diff --git a/tests/coap_client_test.toit b/tests/coap_client_test.toit
index 5ffbb493..0e56a401 100644
--- a/tests/coap_client_test.toit
+++ b/tests/coap_client_test.toit
@@ -36,7 +36,7 @@ test_abort_on_disconnect:
t := TestTransport
client := coap.Client t
- for i := 0; i < 10; i++:
+ for i := ..10:
task::
expect_exception coap.CLOSED_ERROR:
client.get "/test"
@@ -50,7 +50,7 @@ test_abort_on_disconnect_delayed:
t := TestTransport
client := coap.Client t
- for i := 0; i < 10; i++:
+ for i := ..10:
task::
expect_exception coap.CLOSED_ERROR:
client.get "/test"
diff --git a/tests/constructor3_test.toit b/tests/constructor3_test.toit
index 996dfd73..c9100409 100644
--- a/tests/constructor3_test.toit
+++ b/tests/constructor3_test.toit
@@ -26,7 +26,7 @@ class C extends B:
expect_list_equals list1 list2:
expect_equals list1.size list2.size
- for i := 0; i < list1.size; i++:
+ for i := ..list1.size:
expect_equals list1[i] list2[i]
main:
diff --git a/tests/constructor_super_test.toit b/tests/constructor_super_test.toit
index 0268c4db..f9b47993 100644
--- a/tests/constructor_super_test.toit
+++ b/tests/constructor_super_test.toit
@@ -306,7 +306,7 @@ class G:
expect_list_equals l1 l2:
expect_equals l1.size l2.size
- for i := 0; i < l1.size; i++:
+ for i := ..l1.size:
expect_equals l1[i] l2[i]
main:
diff --git a/tests/esp32/rmt.toit b/tests/esp32/rmt.toit
index 41e00887..6d1d6388 100644
--- a/tests/esp32/rmt.toit
+++ b/tests/esp32/rmt.toit
@@ -145,7 +145,7 @@ test_multiple_pulses pin_in/gpio.Pin pin_out/gpio.Pin:
expect signals.size >= SIGNAL_COUNT
SIGNAL_COUNT.repeat:
expect (PULSE_LENGTH - (signals.period it)).abs <= SLACK
- for i := SIGNAL_COUNT; i < signals.size; i++:
+ for i := SIGNAL_COUNT..signals.size:
expect_equals 0 (signals.period i)
test_long_sequence pin_in/gpio.Pin pin_out/gpio.Pin:
@@ -182,7 +182,7 @@ test_long_sequence pin_in/gpio.Pin pin_out/gpio.Pin:
expect signals.size >= SIGNAL_COUNT
(SIGNAL_COUNT - 1).repeat:
expect (PULSE_LENGTH - (signals.period it)).abs <= SLACK
- for i := SIGNAL_COUNT; i < signals.size; i++:
+ for i := SIGNAL_COUNT..signals.size:
expect_equals 0 (signals.period i)
test_bidirectional pin1/gpio.Pin pin2/gpio.Pin:
@@ -236,7 +236,7 @@ test_bidirectional pin1/gpio.Pin pin2/gpio.Pin:
// At the same time we want to see 1000us pulses from our pin.
saw_10us := false
saw_1000us := false
- for i := 0; i < in_signals.size; i++:
+ for i := ..in_signals.size:
if ((in_signals.period i) - 10).abs < SLACK: saw_10us = true
if ((in_signals.period i) - 1000).abs < SLACK: saw_1000us = true
if saw_10us and saw_1000us: break
diff --git a/tests/esp32/uart_big_data_shared.toit b/tests/esp32/uart_big_data_shared.toit
index 51fe17e1..4a4005b8 100644
--- a/tests/esp32/uart_big_data_shared.toit
+++ b/tests/esp32/uart_big_data_shared.toit
@@ -34,7 +34,7 @@ TEST_BYTES := ByteArray 4096:
check_read_data data/ByteArray:
expect_equals TEST_BYTES.size data.size
if TEST_BYTES != data:
- for i := 0; i < TEST_BYTES.size; i++:
+ for i := ..TEST_BYTES.size:
if TEST_BYTES[i] != data[i]:
print "Mismatch at $i: $TEST_BYTES[i] != $data[i]"
print TEST_BYTES[max 0 (i - 3)..min data.size (i + 3)]
diff --git a/tests/esp32/uart_flush.toit b/tests/esp32/uart_flush.toit
index 5115d29f..be6705b2 100644
--- a/tests/esp32/uart_flush.toit
+++ b/tests/esp32/uart_flush.toit
@@ -26,7 +26,7 @@ main:
pin_tx1 := gpio.Pin TX1
pin_rx2 := gpio.Pin RX2
pin_tx2 := gpio.Pin TX2
- for i := 0; i < 2; i++:
+ for i := ..2:
port1 := uart.Port
--rx=pin_rx1
--tx=pin_tx1
diff --git a/tests/esp32/wait_for1.toit b/tests/esp32/wait_for1.toit
index 68fb9ea6..ae845209 100644
--- a/tests/esp32/wait_for1.toit
+++ b/tests/esp32/wait_for1.toit
@@ -35,7 +35,7 @@ main:
ITERATIONS.repeat: | counter |
if counter % 1000 == 0: print "Iteration: $counter"
- for i := 0; i < (counter % 200); i++:
+ for i := .. (counter % 200):
null
// In this mode the pin stays high as long as we don't get any response.
pin_out.set 1
diff --git a/tests/field2_test.toit b/tests/field2_test.toit
index b32facde..84b99e5b 100644
--- a/tests/field2_test.toit
+++ b/tests/field2_test.toit
@@ -39,7 +39,7 @@ class A:
field = 42
constructor.gee:
- for i := 0; i < 1; i++:
+ for i := ..1:
field = 499
side field
field = 0
diff --git a/tests/firmware_map_test.toit b/tests/firmware_map_test.toit
index 7211df11..39ba6321 100644
--- a/tests/firmware_map_test.toit
+++ b/tests/firmware_map_test.toit
@@ -67,8 +67,8 @@ test_map_out_of_bounds from/int to/int -> none:
test_mapping bytes/ByteArray mapping/firmware.FirmwareMapping:
expect.expect_equals bytes.size mapping.size
- for i := 0; i < bytes.size; i++:
- for j := i; j < bytes.size; j++:
+ for i := ..bytes.size:
+ for j := i..bytes.size:
section := ByteArray j - i
mapping.copy i j --into=section
expect.expect_bytes_equal bytes[i..j] section
diff --git a/tests/font_test.toit b/tests/font_test.toit
index 52c44ed6..afba9821 100644
--- a/tests/font_test.toit
+++ b/tests/font_test.toit
@@ -109,9 +109,9 @@ test_missing_glyph_substitution:
WIDTH
str_version := ""
- for y := 0; y < HEIGHT; y++:
+ for y := ..HEIGHT:
str := ""
- for x := 0; x < WIDTH; x++:
+ for x := ..WIDTH:
byte := canvas[x + (y >> 3) * WIDTH]
str += (byte & (1 << (y & 7)) != 0) ? "█" : " "
print str
diff --git a/tests/for_test.toit b/tests/for_test.toit
index 0ef517f4..7e64422f 100644
--- a/tests/for_test.toit
+++ b/tests/for_test.toit
@@ -41,7 +41,7 @@ test_for_as_expression:
expect_null n
n = 87
- n = exec: for j := 0; j < 1; j++: // Do nothing.
+ n = exec: for j := ..1: // Do nothing.
expect_null n
n = 87
@@ -49,18 +49,18 @@ test_for_as_expression:
expect_null n
n = 87
- n = exec: for j := 0; j < 1; j++: 42
+ n = exec: for j := ..1: 42
expect_null n
n = 87
- n = exec: for j := 0; j < 1; j++: 42;
+ n = exec: for j := ..1: 42;
expect_null n
exec [block]:
return block.call
test_declaration_in_for:
- for i := 0; i < 0; i++: x := 0
+ for i := ..0: x := 0
test_regression:
first := null
@@ -73,26 +73,26 @@ test_break:
if true: break
count := 0
- for i := 0; i < 10; i++:
+ for i := ..10:
count++
if i > 5: break
expect_equals 7 count
test_continue:
count := 0
- for i := 0; i < 5; i++:
+ for i := ..5:
count++
if true: continue
expect_equals 5 count
count = 0
- for i := 0; i < 5; i++:
+ for i := ..5:
if true: continue
count++
expect_equals 0 count
count = 0
- for i := 0; i < 5; i++:
+ for i := ..5:
if i % 2 == 1: continue
count++
expect_equals 3 count
diff --git a/tests/fuzzer/afl-tests/afl.toit b/tests/fuzzer/afl-tests/afl.toit
index 44447d71..0b45f2cc 100644
--- a/tests/fuzzer/afl-tests/afl.toit
+++ b/tests/fuzzer/afl-tests/afl.toit
@@ -57,7 +57,7 @@ main:
bar: continue.bar 11
while foo (:: it):
- for i := 0; i < 49; i++:
+ for i := ..49:
if true:
gee 1 2
else:
diff --git a/tests/hatch_test.toit b/tests/hatch_test.toit
index 732f9043..4cda7b8f 100644
--- a/tests/hatch_test.toit
+++ b/tests/hatch_test.toit
@@ -59,7 +59,7 @@ test_chain
create_chain n seed
result := spawn:: respond: it + seed
- for i := 0; i < n; i++:
+ for i := ..n:
sub := result
result = spawn:: respond: sub.send (it + 1)
return result
diff --git a/tests/indentation_test.toit b/tests/indentation_test.toit
index c0074fc5..6c0b42b9 100644
--- a/tests/indentation_test.toit
+++ b/tests/indentation_test.toit
@@ -60,14 +60,14 @@ test_different_indentations:
expect_equals "must be indented" x
x = run:
- for i := 0; i < 1; i++:
+ for i := ..1:
t := foo (if true: 499 else: break):
it + 1
expect_equals 500 t
expect_null x
x = run:
- for i := 0; i < 1; i++:
+ for i := ..1:
t := foo
if true: 499 else: break
: it + 1
diff --git a/tests/lambda6_test.toit b/tests/lambda6_test.toit
index 1890d3f2..dde12a82 100644
--- a/tests/lambda6_test.toit
+++ b/tests/lambda6_test.toit
@@ -19,7 +19,7 @@ create_list x y: return [x, y]
expect_array_equals expected given:
expect given is Array_
expect_equals expected.size given.size
- for i := 0; i < expected.size; i++:
+ for i := ..expected.size:
expect_equals expected[i] given[i]
create_lambda0: return :: 499
diff --git a/tests/list_test.toit b/tests/list_test.toit
index 25727717..e3941a71 100644
--- a/tests/list_test.toit
+++ b/tests/list_test.toit
@@ -517,7 +517,7 @@ test_constructors:
test_collection_list it
test_slice:
- for i := 0; i < 2; i++:
+ for i := ..2:
list := [1, 2, 3, 4, 5, 6]
// In the second run, the 'list' is a slice itself.
if i == 1: list = list[..]
diff --git a/tests/lsp/dep3_compiler_test.toit b/tests/lsp/dep3_compiler_test.toit
index bc35e0df..a9a3470c 100644
--- a/tests/lsp/dep3_compiler_test.toit
+++ b/tests/lsp/dep3_compiler_test.toit
@@ -22,7 +22,7 @@ test client/LspClient:
client.send_did_open --path=paths[it] --text=""
// Build up a chain of import/exports.
- for i := 1; i < LEVELS - 1; i++:
+ for i := 1 .. LEVELS - 1:
content := "import $relatives[i + 1]\nexport *"
client.send_did_change --path=paths[i] content
@@ -33,7 +33,7 @@ test client/LspClient:
"""
diagnostics := client.diagnostics_for --path=paths[0]
expect_equals 1 diagnostics.size
- for i := 1; i < LEVELS; i++:
+ for i := 1..LEVELS:
diagnostics = client.diagnostics_for --path=paths[i]
expect_equals 0 diagnostics.size
@@ -55,6 +55,6 @@ test client/LspClient:
"""
diagnostics = client.diagnostics_for --path=paths[0]
expect_equals 1 diagnostics.size
- for i := 1; i < LEVELS; i++:
+ for i := 1..LEVELS:
diagnostics = client.diagnostics_for --path=paths[i]
expect_equals 0 diagnostics.size
diff --git a/tests/lsp/dep3b_compiler_test.toit b/tests/lsp/dep3b_compiler_test.toit
index d5ac5c92..3c778102 100644
--- a/tests/lsp/dep3b_compiler_test.toit
+++ b/tests/lsp/dep3b_compiler_test.toit
@@ -23,7 +23,7 @@ test client/LspClient:
client.send_did_open --path=paths[it] --text=""
// Build up a chain of import/exports.
- for i := 1; i < LEVELS - 1; i++:
+ for i := 1 .. LEVELS - 1:
content := "import $relatives[i + 1]\nexport foo"
client.send_did_change --path=paths[i] content
@@ -32,7 +32,7 @@ test client/LspClient:
main:
foo
"""
- for i := 0; i < LEVELS; i++:
+ for i := ..LEVELS:
diagnostics := client.diagnostics_for --path=paths[i]
if i != LEVELS - 1:
// Unresolved 'foo'.
@@ -58,6 +58,6 @@ test client/LspClient:
"""
diagnostics := client.diagnostics_for --path=paths[0]
expect_equals 1 diagnostics.size
- for i := 1; i < LEVELS; i++:
+ for i := 1..LEVELS:
diagnostics = client.diagnostics_for --path=paths[i]
expect_equals 0 diagnostics.size
diff --git a/tests/lsp/dump_crash_compiler_test.toit b/tests/lsp/dump_crash_compiler_test.toit
index 4e9c3e6b..dd92c36f 100644
--- a/tests/lsp/dump_crash_compiler_test.toit
+++ b/tests/lsp/dump_crash_compiler_test.toit
@@ -13,7 +13,7 @@ binary_contains_string byte_array/ByteArray needle/string -> bool:
bytes := needle.to_byte_array
(byte_array.size - bytes.size).repeat: |offset|
found := true
- for i := 0; i < bytes.size; i++:
+ for i := ..bytes.size:
if byte_array[offset + i] != bytes[i]:
found = false
break
diff --git a/tests/lsp/file_check_compiler_test_slow.toit b/tests/lsp/file_check_compiler_test_slow.toit
index 5608e365..7be08ea9 100644
--- a/tests/lsp/file_check_compiler_test_slow.toit
+++ b/tests/lsp/file_check_compiler_test_slow.toit
@@ -73,7 +73,7 @@ test client/LspClient files_to_check/List:
last_was_whitespace := false
last_was_special := false
- for i := 0; i < content.size; i++:
+ for i := ..content.size:
c := content[i]
c_is_whitespace := is_whitespace c
if last_was_whitespace and c_is_whitespace:
diff --git a/tests/lsp/location_compiler_test_runner_base.toit b/tests/lsp/location_compiler_test_runner_base.toit
index 2f002a2a..304cc605 100644
--- a/tests/lsp/location_compiler_test_runner_base.toit
+++ b/tests/lsp/location_compiler_test_runner_base.toit
@@ -30,7 +30,7 @@ abstract class LocationCompilerTestRunner:
client.send_did_open --path=test_path --text=content
lines := (content.trim --right "\n").split "\n"
- for i := 0; i < lines.size; i++:
+ for i := ..lines.size:
line := lines[i]
is_test_line := false
if line.starts_with "/*" and not line.starts_with "/**":
diff --git a/tests/lsp/lsp_stress_compiler_test_slow.toit b/tests/lsp/lsp_stress_compiler_test_slow.toit
index 8f2caf3c..3f520305 100644
--- a/tests/lsp/lsp_stress_compiler_test_slow.toit
+++ b/tests/lsp/lsp_stress_compiler_test_slow.toit
@@ -25,7 +25,7 @@ test client/LspClient:
client.always_wait_for_idle = false
print "Sending open documents"
- for i := 0; i < FILE_COUNT; i++:
+ for i := ..FILE_COUNT:
pipe.stdout.write "."
// Don't create the files in parallel, to avoid launching all the diagnostic
// requests.
diff --git a/tests/lsp/outline_compiler_test.toit b/tests/lsp/outline_compiler_test.toit
index 6a5ae025..44db7f4b 100644
--- a/tests/lsp/outline_compiler_test.toit
+++ b/tests/lsp/outline_compiler_test.toit
@@ -87,7 +87,7 @@ test client/LspClient outline_path/string:
parent = combined_name.copy 0 dot_pos
name = combined_name.copy dot_pos + 1
detail := {}
- for i := 1; i < parts.size; i++: detail.add parts[i]
+ for i := 1..parts.size: detail.add parts[i]
(expected_outline.get name --init=:[]).add
ExpectedSymbol name parent kind detail location
@@ -106,7 +106,7 @@ test client/LspClient outline_path/string:
name := symbol["name"]
candidates := expected_outline[name]
found_expected_symbol := false
- for i := 0; i < candidates.size; i++:
+ for i := ..candidates.size:
candidate := candidates[i]
if checked.contains candidate: continue
if candidate.matches_actual symbol parent_name:
diff --git a/tests/lsp/semantic_tokens_compiler_test.toit b/tests/lsp/semantic_tokens_compiler_test.toit
index 0ea5662f..76a70705 100644
--- a/tests/lsp/semantic_tokens_compiler_test.toit
+++ b/tests/lsp/semantic_tokens_compiler_test.toit
@@ -26,7 +26,7 @@ test client/LspClient:
test_file := "$(directory.cwd)/semantic_tokens.toit"
content := (file.read_content test_file).to_string
lines := (content.trim --right "\n").split "\n"
- for i := 0; i < lines.size; i++:
+ for i := ..lines.size:
line /string := lines[i]
is_test_line := false
if line.starts_with "/*" and not line.starts_with "/**":
diff --git a/tests/lsp/toitdoc_compiler_test.toit b/tests/lsp/toitdoc_compiler_test.toit
index 5da7d02f..bd4ed3de 100644
--- a/tests/lsp/toitdoc_compiler_test.toit
+++ b/tests/lsp/toitdoc_compiler_test.toit
@@ -91,7 +91,7 @@ class TemplateFiller:
chunks := []
chunk_start := 0
indentation := 0
- for i := 0; i < template.size; i++:
+ for i := ..template.size:
if template[i] == '#':
// Don't copy the indentation. It's nicer if the generator
// is more uniform for each line it generates.
diff --git a/tests/lsp/utils.toit b/tests/lsp/utils.toit
index 749b2196..312e4c59 100644
--- a/tests/lsp/utils.toit
+++ b/tests/lsp/utils.toit
@@ -9,7 +9,7 @@ import reader show BufferedReader
combine_and_replace lines replacement_index replacement_line:
builder := bytes.Buffer
- for i := 0; i < lines.size; i++:
+ for i := ..lines.size:
if i == replacement_index:
builder.write replacement_line
else:
@@ -36,7 +36,7 @@ extract_locations path -> Map/*<string, Location>*/:
content := (file.read_content path).to_string
lines := (content.trim --right "\n").split "\n"
result := {:}
- for i := 0; i < lines.size; i++:
+ for i := ..lines.size:
line := lines[i]
if line.starts_with "import ." or line.starts_with "// import_for_locations .":
first_dot := line.index_of "."
diff --git a/tests/max_heap_size_test.toit b/tests/max_heap_size_test.toit
index 15b2186d..adff038d 100644
--- a/tests/max_heap_size_test.toit
+++ b/tests/max_heap_size_test.toit
@@ -17,9 +17,9 @@ expect_allocation_failed [code]:
main:
// We can limit ourselves to as little as a 4k heap (on 32 bit) which
// means no old-space.
- for i := 12; i < 17; i++:
+ for i := 12..17:
doesnt_fail 1 << i
- for i := 14; i < 17; i++:
+ for i := 14..17:
doesnt_fail_external 1 << i
spawn:: eventually_fails 70000 --external
sleep --ms=2000
diff --git a/tests/monitor_test.toit b/tests/monitor_test.toit
index 9fbf7372..e20d3a95 100644
--- a/tests/monitor_test.toit
+++ b/tests/monitor_test.toit
@@ -167,7 +167,7 @@ monitor MyMonitor:
foo expect:
expect_equals expect ran
- for i := 0; i < 20; i++:
+ for i := ..20:
yield_a_lot
sleep --ms=1
ran = true
diff --git a/tests/named2_test_force.toit b/tests/named2_test_force.toit
index 1ce2202e..395681ff 100644
--- a/tests/named2_test_force.toit
+++ b/tests/named2_test_force.toit
@@ -27,5 +27,5 @@ main:
c := C
expect_equals 4 glob.size
expected := ["B", "A", "x setter in C", "B2"]
- for i := 0; i < glob.size; i++:
+ for i := ..glob.size:
expect_equals expected[i] glob[i]
diff --git a/tests/negative/gold/shadow5_test.gold b/tests/negative/gold/shadow5_test.gold
index 39903e63..ffc501f3 100644
--- a/tests/negative/gold/shadow5_test.gold
+++ b/tests/negative/gold/shadow5_test.gold
@@ -1,5 +1,5 @@
tests/negative/shadow5_test.toit:9:7: error: Definition of 'x' shadows earlier definition
- for x := 1; x < 10; x++:
+ for x := 1..10:
^
tests/negative/shadow5_test.toit:8:3: note: Earlier definition of 'x'
x := 0
diff --git a/tests/negative/return_missing_test.toit b/tests/negative/return_missing_test.toit
index 459a7c4f..3c2bd204 100644
--- a/tests/negative/return_missing_test.toit
+++ b/tests/negative/return_missing_test.toit
@@ -22,7 +22,7 @@ test3:
return 499
test4:
- for i := 0; i < 0; i++:
+ for i := ..0:
return 499
test5:
diff --git a/tests/negative/shadow5_test.toit b/tests/negative/shadow5_test.toit
index d89add22..eeb983ed 100644
--- a/tests/negative/shadow5_test.toit
+++ b/tests/negative/shadow5_test.toit
@@ -6,5 +6,5 @@ foo f:
main:
x := 0
- for x := 1; x < 10; x++:
+ for x := 1..10:
foo:: x
diff --git a/tests/negative/uninitialized_field2_test.toit b/tests/negative/uninitialized_field2_test.toit
index 871d43b6..04847bba 100644
--- a/tests/negative/uninitialized_field2_test.toit
+++ b/tests/negative/uninitialized_field2_test.toit
@@ -24,7 +24,7 @@ class B:
field = 499
constructor.y:
- for i := 0; i < 0; i++:
+ for i := ..0:
some_fun field
field = 499
diff --git a/tests/negative/uninitialized_field_test.toit b/tests/negative/uninitialized_field_test.toit
index 795a0690..53c978a9 100644
--- a/tests/negative/uninitialized_field_test.toit
+++ b/tests/negative/uninitialized_field_test.toit
@@ -26,7 +26,7 @@ class B:
field = 499
constructor.y:
- for i := 0; i < 0; i++:
+ for i := ..0:
field = 42
constructor.z:
diff --git a/tests/negative/uninitialized_local2_test.toit b/tests/negative/uninitialized_local2_test.toit
index e6659bc1..dbbd061e 100644
--- a/tests/negative/uninitialized_local2_test.toit
+++ b/tests/negative/uninitialized_local2_test.toit
@@ -31,7 +31,7 @@ main:
use local3
local4 ::= ?
- for i := 0; i < 0; i++:
+ for i := ..0:
local4 = 42
use local4
diff --git a/tests/negative/uninitialized_local_test.toit b/tests/negative/uninitialized_local_test.toit
index d334a642..8267a549 100644
--- a/tests/negative/uninitialized_local_test.toit
+++ b/tests/negative/uninitialized_local_test.toit
@@ -37,7 +37,7 @@ main:
use local3
local4 := ?
- for i := 0; i < 0; i++:
+ for i := ..0:
local4 = 42
use local4
diff --git a/tests/non_local_branch2_test.toit b/tests/non_local_branch2_test.toit
index 2e807ff9..6763a0c3 100644
--- a/tests/non_local_branch2_test.toit
+++ b/tests/non_local_branch2_test.toit
@@ -38,7 +38,7 @@ main:
finally_count := 0
expected_finally_count := 0
- for i := 0; i < 5; i++:
+ for i := ..5:
expect_equals i foo_count
expect_equals i before_count
expect_equals 0 after_count
diff --git a/tests/non_local_branch3_test.toit b/tests/non_local_branch3_test.toit
index dee862d1..c0f3fbf0 100644
--- a/tests/non_local_branch3_test.toit
+++ b/tests/non_local_branch3_test.toit
@@ -16,9 +16,9 @@ foo2 x [--named]:
main:
limit ::= 3
- for mode := 0; mode < 2; mode++:
+ for mode := ..2:
foo_count = 0
- for i := 0; i < 5; i++:
+ for i := ..5:
block :=:
// Depending on the mode we use the first call or not.
if it == mode:
@@ -26,7 +26,7 @@ main:
continue
else:
break
- for j := 0; j < 1; j++:
+ for j := ..1:
foo1 block
foo2 1 --named=block
throw "UNREACHABLE"
diff --git a/tests/non_local_branch4_test.toit b/tests/non_local_branch4_test.toit
index e276c528..8f49cffa 100644
--- a/tests/non_local_branch4_test.toit
+++ b/tests/non_local_branch4_test.toit
@@ -20,9 +20,9 @@ main:
// Make all non-local targets go into a block.
run:
limit ::= 3
- for mode := 0; mode < 2; mode++:
+ for mode := ..2:
foo_count = 0
- for i := 0; i < 5; i++:
+ for i := ..5:
block :=:
// Depending on the mode we use the first call or not.
if it == mode:
@@ -30,7 +30,7 @@ main:
continue
else:
break
- for j := 0; j < 1; j++:
+ for j := ..1:
foo1 block
foo2 1 --named=block
throw "UNREACHABLE"
diff --git a/tests/non_local_branch_test.toit b/tests/non_local_branch_test.toit
index c18041a2..f2cbbe82 100644
--- a/tests/non_local_branch_test.toit
+++ b/tests/non_local_branch_test.toit
@@ -20,7 +20,7 @@ foo [b]:
main:
before_count := 0
after_count := 0
- for i := 0; i < 5; i++:
+ for i := ..5:
expect_equals i before_count
expect_equals i finally_count
diff --git a/tests/profiler/basic_input.toit b/tests/profiler/basic_input.toit
index 2e5ccc49..9acf6f3f 100644
--- a/tests/profiler/basic_input.toit
+++ b/tests/profiler/basic_input.toit
@@ -13,7 +13,7 @@ bar:
foo:
sum := 0
- for i := 0; i < ITERATIONS * 8; i++:
+ for i := .. ITERATIONS * 8:
sum += i
expect_equals 31_996_000 sum
diff --git a/tests/profiler/lambda_input.toit b/tests/profiler/lambda_input.toit
index 15c5dfbe..05bb6013 100644
--- a/tests/profiler/lambda_input.toit
+++ b/tests/profiler/lambda_input.toit
@@ -18,7 +18,7 @@ bar:
foo:
run::
sum := 0
- for i := 0; i < ITERATIONS * 8; i++:
+ for i := .. ITERATIONS * 8:
sum += i
expect_equals 31_996_000 sum
diff --git a/tests/reader_test.toit b/tests/reader_test.toit
index b5cb54ad..7b21e57c 100644
--- a/tests/reader_test.toit
+++ b/tests/reader_test.toit
@@ -57,9 +57,9 @@ utf_8:
// € is e2 82 ac
S ::= DIFFICULT_STRING.to_byte_array
- for i := 1; i < S.size - 1; i++:
+ for i := 1 .. S.size - 1:
for j := -4; j <= 4; j++:
- for k := 1; k < 5; k++:
+ for k := 1..5:
split_test S i j k
split_test ba/ByteArray split_point/int offset/int part_2_size:
@@ -135,7 +135,7 @@ consumed_one_at_a_time:
consumed_get_and_unget:
br2 := reader.BufferedReader MultiByteArrayReader
expected_cursor := 0
- for i := 0; i < 256; i++:
+ for i := ..256:
expect_equals expected_cursor i
if i + 13 > 256: break
br2.read_bytes 13
diff --git a/tests/return_test_force.toit b/tests/return_test_force.toit
index e7a720af..b31d1518 100644
--- a/tests/return_test_force.toit
+++ b/tests/return_test_force.toit
@@ -25,7 +25,7 @@ test3 arg:
return 499
test4:
- for i := 0; i < 0; i++:
+ for i := ..0:
throw "bad"
return 499
diff --git a/tests/serialization_test.toit b/tests/serialization_test.toit
index 9cee1297..2dc14b6c 100644
--- a/tests/serialization_test.toit
+++ b/tests/serialization_test.toit
@@ -15,7 +15,7 @@ test_array array:
result := tison.decode
tison.encode array
expect_equals array.size result.size
- for i := 0; i < array.size; i++:
+ for i := ..array.size:
expect_equals array[i] result[i]
test_map:
diff --git a/tests/set_map_middle_gap_test.toit b/tests/set_map_middle_gap_test.toit
index e388b93a..d3f86316 100644
--- a/tests/set_map_middle_gap_test.toit
+++ b/tests/set_map_middle_gap_test.toit
@@ -13,7 +13,7 @@ test_set:
// bailout from the C++ code to the Toit code in the
// do method. Ensure that we continue at the correct
// index in this case.
- for i := 240; i < 260; i++:
+ for i := 240..260:
s.remove i
s2 := Set
s.do:
@@ -35,7 +35,7 @@ test_map:
// bailout from the C++ code to the Toit code in the
// do method. Ensure that we continue at the correct
// index in this case.
- for i := 240; i < 260; i++:
+ for i := 240..260:
m.remove i
s2 := Set
m.do:
diff --git a/tests/set_map_test.toit b/tests/set_map_test.toit
index 1801d0b3..f5bb7e19 100644
--- a/tests/set_map_test.toit
+++ b/tests/set_map_test.toit
@@ -7,24 +7,24 @@ import expect show *
test_map:
n := 213
map := Map
- for i := 0; i < n; i++:
+ for i := ..n:
map[i.stringify] = i
map[i] = i + i
map["fjummer"] = 123
- for i := 0; i < n; i++:
+ for i := ..n:
expect (map.contains i.stringify)
expect (map.contains i)
expect (map.contains "fjummer")
map.remove "fjummer"
expect (not map.contains "fjummer")
map[#['f', 'j', 'u', 'm', 'm', 'e', 'r']] = 243
- for i := 0; i < n; i++:
+ for i := ..n:
expect (map.contains i.stringify)
expect (map.contains i)
expect (map.contains #['f', 'j', 'u', 'm', 'm', 'e', 'r'])
map.remove #['f', 'j', 'u', 'm', 'm', 'e', 'r']
expect (not map.contains #['f', 'j', 'u', 'm', 'm', 'e', 'r'])
- for i := 0; i < n; i++:
+ for i := ..n:
expect (map.contains i.stringify)
expect (map.contains i)
expect map.size == n * 2
@@ -123,15 +123,15 @@ test_map_clear:
map.clear
expect map.is_empty
- for i := 0; i < 100; i++:
+ for i := ..100:
map[i] = i
- for i := 0; i < 100; i++:
+ for i := ..100:
expect_equals i map[i]
map.clear
expect map.is_empty
- for i := 0; i < 100; i++:
+ for i := ..100:
map[i] = i
- for i := 0; i < 100; i++:
+ for i := ..100:
expect_equals i map[i]
map.clear
expect map.is_empty
@@ -152,7 +152,7 @@ test_set:
test_set_basics:
n := 213
set := Set
- for i := 0; i < n; i++:
+ for i := ..n:
set.add i.stringify
set.add i
set.add "fjummer"
@@ -329,15 +329,15 @@ test_set_clear:
set.clear
expect set.is_empty
- for i := 0; i < 100; i++:
+ for i := ..100:
set.add i
- for i := 0; i < 100; i++:
+ for i := ..100:
expect (set.contains i)
set.clear
expect set.is_empty
- for i := 0; i < 100; i++:
+ for i := ..100:
set.add i
- for i := 0; i < 100; i++:
+ for i := ..100:
expect (set.contains i)
set.clear
expect set.is_empty
diff --git a/tests/sleep_mixed_test.toit b/tests/sleep_mixed_test.toit
index 69a70883..b720ffe5 100644
--- a/tests/sleep_mixed_test.toit
+++ b/tests/sleep_mixed_test.toit
@@ -9,7 +9,7 @@ main:
sleep_ms 40
sleep_ms ms:
- for i := 0; i < 10; i++:
+ for i := ..10:
before := Time.monotonic_us
sleep --ms=ms
took := (Time.monotonic_us - before) / 1000
diff --git a/tests/sleep_test.toit b/tests/sleep_test.toit
index a9a3c951..fa5fe241 100644
--- a/tests/sleep_test.toit
+++ b/tests/sleep_test.toit
@@ -18,11 +18,11 @@ test_sleep:
test_sleep_many:
- for i := 0; i < 10; i++:
+ for i := ..10:
task:: sleep_often i
sleep_often n:
- for i := 0; i < 10; i++:
+ for i := ..10:
duration := 10
before := Time.monotonic_us
sleep --ms=duration
diff --git a/tests/socket_task_test.toit b/tests/socket_task_test.toit
index 6e5c2b6c..e96fb351 100644
--- a/tests/socket_task_test.toit
+++ b/tests/socket_task_test.toit
@@ -48,7 +48,7 @@ writer socket delay done:
writer := Writer socket
array := ByteArray PACKET_SIZE
- for i := 0; i < PACKAGES; i++:
+ for i := ..PACKAGES:
writer.write array
print "DONE WRITER"
diff --git a/tests/string_test.toit b/tests/string_test.toit
index fe8d2547..3b0a4aa3 100644
--- a/tests/string_test.toit
+++ b/tests/string_test.toit
@@ -270,7 +270,7 @@ test_string_at:
expect_equals s[i++] '!'
)
test_soen.call str1 0
- for i := 0; i < big_repetitions; i++:
+ for i := ..big_repetitions:
test_soen.call long_str1 (i * str1.size)
// Euro sign is a three byte UTF-8 sequence.
@@ -319,7 +319,7 @@ test_string_at:
expect_out_of_bounds: germany[i]
expect_equals germany germany.to_byte_array.to_string
- for x := 0; x < germany.size; x++:
+ for x := ..germany.size:
for y := x; y <= germany.size; y++:
ok := false
// Zero length slices between the letters are OK
@@ -335,7 +335,7 @@ test_string_at:
else:
expect_illegal_utf_8: germany.copy x y
- for x := 0; x < germany.size; x++:
+ for x := ..germany.size:
for y := x; y <= germany.size; y++:
copied := germany.copy --force_valid x y
if x == y: expect_equals 0 copied.size
@@ -397,7 +397,7 @@ test_slice_string_at:
expect_equals s[i++] 'd'
expect_equals s[i++] '!'
)
- for i := 0; i < REPETITIONS; i++:
+ for i := ..REPETITIONS:
test_soen.call slice (i * short.size)
test_write_to_byte_array:
@@ -1384,7 +1384,7 @@ test_is_empty:
expect ("foobar".copy 0 0).is_empty
bytes := ByteArray 10000
- for i := 0; i < bytes.size; i++: bytes[i] = 'a'
+ for i := ..bytes.size: bytes[i] = 'a'
big_string := bytes.to_string
expect (not big_string.is_empty)
expect (big_string.copy 0 0).is_empty
diff --git a/tests/task_test.toit b/tests/task_test.toit
index 621884f0..888eeae1 100644
--- a/tests/task_test.toit
+++ b/tests/task_test.toit
@@ -16,7 +16,7 @@ test_sum
i := 0
n.repeat: respond: SUM += it; i++
self.send SUM
- for i := 0; i < n; i++:
+ for i := ..n:
task::
val := master.send i * 2
SUM -= val
diff --git a/tests/thread_test.toit b/tests/thread_test.toit
index 58827c9e..a56dfbba 100644
--- a/tests/thread_test.toit
+++ b/tests/thread_test.toit
@@ -18,12 +18,12 @@ test_send n:
channel := monitor.Channel split
sender := thread::
- for i := 0; i < n; i++:
+ for i := ..n:
channel.send i
yield
null
- for i := 0; i < split; i++:
+ for i := ..split:
expect_equals i channel.receive
received++
@@ -32,7 +32,7 @@ test_send n:
// thread is done.
expect_null sender.join
- for i := split; i < n; i++:
+ for i := split..n:
expect_equals i channel.receive
received++
return received
diff --git a/tests/tls_no_net_test.toit b/tests/tls_no_net_test.toit
index 0823266d..7cb0e57e 100644
--- a/tests/tls_no_net_test.toit
+++ b/tests/tls_no_net_test.toit
@@ -57,7 +57,7 @@ monitor Socket implements reader.Reader:
read:
await: not queue_.is_empty
l := queue_.first
- for i := 0; i < queue_.size - 1; i++:
+ for i := .. queue_.size - 1:
queue_[i] = queue_[i + 1]
queue_.resize queue_.size - 1
return l
diff --git a/tests/toitp/dispatch_snap_test.toit b/tests/toitp/dispatch_snap_test.toit
index 9797cd9a..840ec86b 100644
--- a/tests/toitp/dispatch_snap_test.toit
+++ b/tests/toitp/dispatch_snap_test.toit
@@ -32,7 +32,7 @@ main args:
// We expect two entries of a_method_a in the dispatch table.
foo_id := a_foo_info.id
found_foo := false;
- for i := 0; i < dispatch.size - 1; i++:
+ for i := .. dispatch.size - 1:
if dispatch[i] == foo_id:
found_foo = true
expect dispatch[i + 1] == foo_id
@@ -44,7 +44,7 @@ main args:
a_bar_id := a_bar_info.id
b_bar_id := b_bar_info.id
found_bar := false;
- for i := 0; i < dispatch.size - 1; i++:
+ for i := .. dispatch.size - 1:
if dispatch[i] == a_bar_id:
found_bar = true
expect dispatch[i + 1] == b_bar_id
diff --git a/tests/toitp/dispatch_toitp_test.toit b/tests/toitp/dispatch_toitp_test.toit
index 99f2882e..ecd50c9f 100644
--- a/tests/toitp/dispatch_toitp_test.toit
+++ b/tests/toitp/dispatch_toitp_test.toit
@@ -17,7 +17,7 @@ main args:
// Two ClassA.test_foo next to each other.
found_test_foo := false
- for i := 0; i < methods.size - 1; i++:
+ for i := .. methods.size - 1:
if methods[i] == "ClassA.test_foo":
expect methods[i + 1] == methods[i]
found_test_foo = true
@@ -26,7 +26,7 @@ main args:
// ClassA.test_bar followed by ClassB.test_bar.
found_test_bar := false
- for i := 0; i < methods.size - 1; i++:
+ for i := .. methods.size - 1:
if methods[i] == "ClassA.test_bar":
expect methods[i + 1] == "ClassB.test_bar"
found_test_bar = true
diff --git a/tests/toitp/literal_toitp_test.toit b/tests/toitp/literal_toitp_test.toit
index 01a64f71..d3c1d060 100644
--- a/tests/toitp/literal_toitp_test.toit
+++ b/tests/toitp/literal_toitp_test.toit
@@ -12,7 +12,7 @@ main args:
found_foo_string := false
found_int_literal := false
found_float_literal := false
- for i := 1; i < lines.size; i++:
+ for i := 1..lines.size:
line := lines[i]
if line == "": continue
colon_pos := line.index_of ": "
diff --git a/tests/type_propagation/deltablue_test.toit b/tests/type_propagation/deltablue_test.toit
index e97702c9..2d43269f 100644
--- a/tests/type_propagation/deltablue_test.toit
+++ b/tests/type_propagation/deltablue_test.toit
@@ -597,7 +597,7 @@ chain_test n/int -> none:
StayConstraint STRONG_DEFAULT last
edit := EditConstraint PREFERRED first
plan := planner.extract_plan_from_constraints [edit]
- for i := 0; i < 100; i++:
+ for i := ..100:
first.value = i
plan.execute
if last.value != i:
@@ -617,7 +617,7 @@ projection_test n/int -> none:
dst := null
dests := []
- for i := 0; i < n; i++:
+ for i := ..n:
src = Variable "src$i" i
dst = Variable "dst$i" i
dests.add dst
@@ -628,10 +628,10 @@ projection_test n/int -> none:
change dst 1050
if src.value != 5: throw "Projection 2 failed"
change scale 5
- for i := 0; i < n - 1; i++:
+ for i := .. n - 1:
if dests[i].value != i * 5 + 1000: throw "Projection 3 failed"
change offset 2000
- for i := 0; i < n - 1; i++:
+ for i := .. n - 1:
if dests[i].value != i * 5 + 2000: throw "Projection 4 failed"
change v/Variable new_value/int -> none:
diff --git a/tests/type_propagation/richards_test.toit b/tests/type_propagation/richards_test.toit
index 589958f9..4cfbac0c 100644
--- a/tests/type_propagation/richards_test.toit
+++ b/tests/type_propagation/richards_test.toit
@@ -371,7 +371,7 @@ class WorkerTask:
v1 = v1 == ID_HANDLER_A ? ID_HANDLER_B : ID_HANDLER_A
packet.id = v1
packet.a1 = 0
- for i := 0; i < DATA_SIZE; i++:
+ for i := ..DATA_SIZE:
if ++v2 > 26: v2 = 1
packet.a2[i] = v2
return scheduler.queue packet
diff --git a/tests/udp_test.toit b/tests/udp_test.toit
index 8e23c11f..ea99d8e3 100644
--- a/tests/udp_test.toit
+++ b/tests/udp_test.toit
@@ -32,7 +32,7 @@ ping_ping_test:
net.IpAddress.parse "127.0.0.1"
port
- for i := 0; i < times; i++:
+ for i := ..times:
socket.write "testing"
expect_equals "testing" socket.read.to_string
socket.close
@@ -41,7 +41,7 @@ echo_responder times ready:
socket := udp.Socket "127.0.0.1" 0
ready.send socket.local_address.port
- for i := 0; i < times; i++:
+ for i := ..times:
msg := socket.receive
socket.send msg
@@ -72,7 +72,7 @@ ping_ping_timeout_test:
net.IpAddress.parse "127.0.0.1"
port
- for i := 0; i < times; i++:
+ for i := ..times:
timer := Timer "testing" socket
socket.write "testing"
e := catch:
@@ -89,7 +89,7 @@ echo_resend_responder times ready:
socket := udp.Socket "127.0.0.1" 0
ready.send socket.local_address.port
- for i := 0; i < times; i++:
+ for i := ..times:
msg := socket.receive
if (i & 1) == 0:
socket.send msg
@@ -113,7 +113,7 @@ broadcast_test:
BROADCAST_ADDRESS
port
- for i := 0; i < times; i++:
+ for i := ..times:
socket.send msg
socket.close
diff --git a/third_party/benchmarks/toit/deltablue.toit b/third_party/benchmarks/toit/deltablue.toit
index e83c4be3..cb1437ac 100644
--- a/third_party/benchmarks/toit/deltablue.toit
+++ b/third_party/benchmarks/toit/deltablue.toit
@@ -600,7 +600,7 @@ chain_test n/int -> none:
StayConstraint STRONG_DEFAULT last
edit := EditConstraint PREFERRED first
plan := planner.extract_plan_from_constraints [edit]
- for i := 0; i < 100; i++:
+ for i := ..100:
first.value = i
plan.execute
if last.value != i:
@@ -620,7 +620,7 @@ projection_test n/int -> none:
dst := null
dests := []
- for i := 0; i < n; i++:
+ for i := ..n:
src = Variable "src$i" i
dst = Variable "dst$i" i
dests.add dst
@@ -631,10 +631,10 @@ projection_test n/int -> none:
change dst 1050
if src.value != 5: throw "Projection 2 failed"
change scale 5
- for i := 0; i < n - 1; i++:
+ for i := .. n - 1:
if dests[i].value != i * 5 + 1000: throw "Projection 3 failed"
change offset 2000
- for i := 0; i < n - 1; i++:
+ for i := .. n - 1:
if dests[i].value != i * 5 + 2000: throw "Projection 4 failed"
change v/Variable new_value/int -> none:
diff --git a/third_party/benchmarks/toit/richards.toit b/third_party/benchmarks/toit/richards.toit
index 1bbc256c..ed9fae9d 100644
--- a/third_party/benchmarks/toit/richards.toit
+++ b/third_party/benchmarks/toit/richards.toit
@@ -373,7 +373,7 @@ class WorkerTask:
v1 = v1 == ID_HANDLER_A ? ID_HANDLER_B : ID_HANDLER_A
packet.id = v1
packet.a1 = 0
- for i := 0; i < DATA_SIZE; i++:
+ for i := ..DATA_SIZE:
if ++v2 > 26: v2 = 1
packet.a2[i] = v2
return scheduler.queue packet
diff --git a/tools/image.toit b/tools/image.toit
index 4fab91d0..65c80ee5 100644
--- a/tools/image.toit
+++ b/tools/image.toit
@@ -256,7 +256,7 @@ class Image:
final_size := all_memory.size + relocation_bits.size
result := ByteArray final_size
out_index := 0
- for i := 0; i < all_memory.size; i++:
+ for i := ..all_memory.size:
if (i % (word_size * word_size * 8)) == 0:
index := i / word_size / 8
relocation_word := LITTLE_ENDIAN.read_uint relocation_bits word_size index
diff --git a/tools/lsp/server/protocol/change.toit b/tools/lsp/server/protocol/change.toit
index 2f7041ef..469dc2fd 100644
--- a/tools/lsp/server/protocol/change.toit
+++ b/tools/lsp/server/protocol/change.toit
@@ -68,7 +68,7 @@ class DidChangeTextDocumentParams extends MapWrapper:
*/
content_changes -> List/*<TextDocumentContentChangeEvent>*/:
return at_ "contentChanges":
- for i := 0; i < it.size; i++:
+ for i := ..it.size:
it[i] = TextDocumentContentChangeEvent it[i]
it
diff --git a/tools/lsp/server/summary.toit b/tools/lsp/server/summary.toit
index 6bc9ceff..5e6880df 100644
--- a/tools/lsp/server/summary.toit
+++ b/tools/lsp/server/summary.toit
@@ -580,7 +580,7 @@ class SummaryReader:
// TODO(1268, florian): remove this work-around and use the commented code instead.
// return List count block
result := List count
- for i := 0; i < count; i++:
+ for i := ..count:
result[i] = block.call i
return result
diff --git a/tools/lsp/server/uri_path_translator.toit b/tools/lsp/server/uri_path_translator.toit
index ef1e7fc0..75d13330 100644
--- a/tools/lsp/server/uri_path_translator.toit
+++ b/tools/lsp/server/uri_path_translator.toit
@@ -23,7 +23,7 @@ to_hex_char_ x:
percent_encode_ str:
encoded := ByteArray str.size * 3 // At most 3 times as big.
target_i := 0
- for i := 0; i < str.size; i++:
+ for i := ..str.size:
c := str.at --raw i
if c == '/' or c == '.' or
'a' <= c <= 'z' or
diff --git a/tools/mirror.toit b/tools/mirror.toit
index 6520ad09..3c2286f0 100644
--- a/tools/mirror.toit
+++ b/tools/mirror.toit
@@ -465,11 +465,11 @@ class MallocReport extends Mirror:
stringify -> string:
result := []
key_ result --terminal=false
- for i := 0; i < uses_list.size; i++:
+ for i := ..uses_list.size:
uses := uses_list[i]
fullnesses := fullnesses_list[i]
base := base_addresses[i]
- for j := 0; j < uses.size; j++:
+ for j := ..uses.size:
if uses[j] != 0 or fullnesses[j] != 0:
result.add "0x$(%08x base + j * granularity): $(%3d fullnesses[j])% $(plain_usage_description_ uses[j] fullnesses[j])"
if uses[j] & MEMORY_PAGE_MERGE_WITH_NEXT_ == 0:
@@ -509,13 +509,13 @@ class MallocReport extends Mirror:
terminal_stringify -> string:
result := []
key_ result --terminal=true
- for i := 0; i < uses_list.size; i++:
+ for i := ..uses_list.size:
uses := uses_list[i]
fullnesses := fullnesses_list[i]
base := base_addresses[i]
lowest := uses.size
highest := 0
- for j := 0; j < uses.size; j++:
+ for j := ..uses.size:
if uses[j] != 0 or fullnesses[j] != 0:
lowest = min lowest j
highest = max highest j
@@ -528,7 +528,7 @@ class MallocReport extends Mirror:
generate_line result/List uses/ByteArray fullnesses/ByteArray open/string allocation_end/string allocation_continue/string end/string is_data_line/bool -> none:
line := []
- for i := 0; i < uses.size; i++:
+ for i := ..uses.size:
use := uses[i]
if use == 0 and fullnesses[i] == 0: continue
symbols := ""
@@ -642,7 +642,7 @@ class HeapPage extends Mirror:
// Calls the block with arguments offset size use-character last_flag
do [block]:
offset := 0
- for i := 0; i < map.size; i++:
+ for i := ..map.size:
extra := 0
byte := map[i]
while byte & 0b1000_0000 != 0:
diff --git a/tools/stacktrace.toit b/tools/stacktrace.toit
index eb0d5a89..2cc2123b 100644
--- a/tools/stacktrace.toit
+++ b/tools/stacktrace.toit
@@ -124,7 +124,7 @@ main args/List:
star_printed := false
start := max symbol.address (address - 30)
if start != symbol.address: print "..."
- for add := start; add < address + 15; add++:
+ for add := start .. address + 15:
star := " "
if not star_printed and add >= address:
if disassembly_lines.contains add:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment