mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Patched some very obscure bugs
This commit is contained in:
15
test/scripts/index-assignment-both-bugfix.toy
Normal file
15
test/scripts/index-assignment-both-bugfix.toy
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
|
||||
This ensures that when indexing on both sides of an assignment,
|
||||
it works correctly.
|
||||
|
||||
*/
|
||||
|
||||
var a = [1, 2, 3];
|
||||
var b = [4, 5, 6];
|
||||
|
||||
a[1] = b[1];
|
||||
|
||||
assert a == [1, 5, 3], "index assignment both failed";
|
||||
|
||||
print "All good";
|
||||
19
test/scripts/index-assignment-left-bugfix.toy
Normal file
19
test/scripts/index-assignment-left-bugfix.toy
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
|
||||
Compiler note:
|
||||
This is also to test a specific element in the compiler.
|
||||
It ensures that when doing indexing and assignment in one statement,
|
||||
the index is NOT on the right. If it is, then it is treated like a normal
|
||||
assignment.
|
||||
|
||||
*/
|
||||
|
||||
//polyfill the _insert function
|
||||
var a = [1, 2, 3];
|
||||
|
||||
var b = a[1];
|
||||
|
||||
assert b == 2, "index assignment left failed";
|
||||
|
||||
|
||||
print "All good";
|
||||
@@ -160,7 +160,8 @@ import compound;
|
||||
var a = [1, 2, 42, 3];
|
||||
|
||||
//results are zero-indexed
|
||||
assert a.indexOf(42) == 2, "_indexOf failed";
|
||||
assert a.indexOf(42) == 2, "_indexOf() failed";
|
||||
assert a.indexOf(4) == null, "_indexOf() == null failed";
|
||||
}
|
||||
|
||||
|
||||
|
||||
22
test/scripts/polyfill-insert.toy
Normal file
22
test/scripts/polyfill-insert.toy
Normal file
@@ -0,0 +1,22 @@
|
||||
//polyfill the _insert function
|
||||
fn _insert(self, k, v) {
|
||||
var tmp1 = v;
|
||||
var tmp2;
|
||||
for (var i = k; i < self.length(); i++) {
|
||||
tmp2 = self[i];
|
||||
self[i] = tmp1;
|
||||
tmp1 = tmp2;
|
||||
}
|
||||
|
||||
self.push(tmp1);
|
||||
return self;
|
||||
}
|
||||
|
||||
var a = [1, 2, 3];
|
||||
|
||||
a = a.insert(1, 42);
|
||||
|
||||
assert a == [1, 42, 2, 3], "polyfill insert failed";
|
||||
|
||||
|
||||
print "All good";
|
||||
23
test/scripts/polyfill-remove.toy
Normal file
23
test/scripts/polyfill-remove.toy
Normal file
@@ -0,0 +1,23 @@
|
||||
//polyfill the remove function
|
||||
fn _remove(self, k) {
|
||||
var result = [];
|
||||
|
||||
for (var i = 0; i <= k - 1; i++) {
|
||||
result.push( self[i] );
|
||||
}
|
||||
|
||||
for (var i = k + 1; i < self.length(); i++) {
|
||||
result.push( self[i] );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
var a = [1, 2, 3];
|
||||
|
||||
assert a.remove(0) == [2, 3], "polyfill remove(start) failed";
|
||||
assert a.remove(1) == [1, 3], "polyfill remove(middle) failed";
|
||||
assert a.remove(2) == [1, 2], "polyfill remove(end) failed";
|
||||
|
||||
|
||||
print "All good";
|
||||
Reference in New Issue
Block a user