Fixed some indexing bugs

This commit is contained in:
2022-09-07 18:43:32 +01:00
parent 8f61575579
commit 9a55ff221a
7 changed files with 89 additions and 32 deletions

View File

@@ -2,14 +2,24 @@
var t: type = astype [int];
var u: type = astype [t];
fn makeCounter() {
var total: int = 0;
var a: u;
fn counter(): int {
return ++total;
}
t = astype [float]; //redefnition
return counter;
}
var b: u;
var tally = makeCounter();
print typeof a; //<[<int>]>
print typeof b; //<[<float>]>
print tally(); //1
print tally(); //2
print tally(); //3
export tally;
//heck yeah!
import tally as tally2;
print tally2(); //4

View File

@@ -1,8 +1,22 @@
//test basic indexing
{
var week = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
assert week[1] == "tuesday", "basic indexing failed (single element)";
assert week[1:1] == ["tuesday"], "basic indexing failed (single element as array)";
assert week[:] == ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"], "basic default indexing failed (first and second)";
assert week[::] == ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"], "basic default indexing failed (first, second and third)";
}
//test basic replacement
{
var week = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
week[3] = "Holiday";
week[3:3] = "Holiday";
assert week == ["monday", "tuesday", "wednesday", "Holiday", "friday", "saturday", "sunday"], "basic replacement failed";
}

View File

@@ -1,13 +1,24 @@
//test basic replacement
//test basic indexing
var greeting: string = "hello world";
assert greeting[1] == "e", "basic default index failed (first)";
assert greeting[:] == "hello world", "basic default index failed (first and second)";
assert greeting[::] == "hello world", "basic default index failed (first, second & third)";
assert greeting[0:4] == "hello", "basic indexing failed";
//test basic replacement
greeting[0:4] = "goodnight";
assert greeting == "goodnight world", "basic replacement failed";
//test backwards string
assert greeting[::-1] == "dlrow thgindoog", "backwards string failed";
assert greeting[11:15:-1] == "dlrow", "backwards indexed string failed";
//test string weird manipulation