mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Moved tests from scripts/ to test/scripts/
This commit is contained in:
31
test/scripts/arithmetic.toy
Normal file
31
test/scripts/arithmetic.toy
Normal file
@@ -0,0 +1,31 @@
|
||||
//test operators (integers)
|
||||
assert 1 + 1 == 2, "1 + 1 == 2";
|
||||
assert 1 - 1 == 0, "1 - 1 == 0";
|
||||
assert 2 * 2 == 4, "2 * 2 == 4";
|
||||
assert 1 / 2 == 0, "1 / 2 == 0"; //integer division
|
||||
assert 5 % 2 == 1, "5 % 2 == 1";
|
||||
|
||||
//test operators (floats)
|
||||
assert 1.0 + 1.0 == 2.0, "1.0 + 1.0 == 2.0";
|
||||
assert 1.0 - 1.0 == 0.0, "1.0 - 1.0 == 0.0";
|
||||
assert 2.0 * 2.0 == 4.0, "2.0 * 2.0 == 4.0";
|
||||
assert 1.0 / 2.0 == 0.5, "1.0 / 2.0 == 0.5";
|
||||
|
||||
|
||||
var a = 10;
|
||||
|
||||
a += 20;
|
||||
a -= 25;
|
||||
|
||||
assert a == 5, "+= or -= failed";
|
||||
|
||||
a *= 5;
|
||||
a /= 2;
|
||||
|
||||
assert a == 12, "*= or /= failed";
|
||||
|
||||
a %= 8;
|
||||
|
||||
assert a == 4, "%= failed";
|
||||
|
||||
print "All good";
|
||||
23
test/scripts/call-from-host.toy
Normal file
23
test/scripts/call-from-host.toy
Normal file
@@ -0,0 +1,23 @@
|
||||
//create a bunch of toy functions as literals to be called from C
|
||||
|
||||
fn answer() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
fn identity(x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
fn makeCounter() {
|
||||
var total = 0;
|
||||
|
||||
fn counter() {
|
||||
return ++total;
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
fn fail() {
|
||||
assert false, "Failed correctly";
|
||||
}
|
||||
37
test/scripts/casting.toy
Normal file
37
test/scripts/casting.toy
Normal file
@@ -0,0 +1,37 @@
|
||||
//boolean origin
|
||||
var b: bool = true;
|
||||
|
||||
assert bool b == true, "bool -> bool";
|
||||
assert int b == 1, "bool -> int";
|
||||
assert float b == 1, "bool -> float";
|
||||
assert string b == "true", "bool -> string";
|
||||
|
||||
|
||||
//integer origin
|
||||
var i: int = 42;
|
||||
|
||||
assert bool i == true, "int -> bool";
|
||||
assert int i == 42, "int -> int";
|
||||
assert float i == 42, "int -> float";
|
||||
assert string i == "42", "int -> string";
|
||||
|
||||
|
||||
//float origin
|
||||
var f: float = 3.14;
|
||||
|
||||
assert bool f == true, "float -> bool";
|
||||
assert int f == 3, "float -> int";
|
||||
assert float f == 3.14, "float -> float";
|
||||
assert string f == "3.14", "float -> string";
|
||||
|
||||
|
||||
//string origin
|
||||
var s: string = "78.9";
|
||||
|
||||
assert bool s == true, "string -> bool";
|
||||
assert int s == 78, "string -> int";
|
||||
assert float s == 78.9, "string -> float";
|
||||
assert string s == "78.9", "string -> string";
|
||||
|
||||
|
||||
print "All good";
|
||||
13
test/scripts/coercions.toy
Normal file
13
test/scripts/coercions.toy
Normal file
@@ -0,0 +1,13 @@
|
||||
//test int -> float coercion
|
||||
{
|
||||
var f: float = 0;
|
||||
|
||||
assert typeof f == float, "coercion on decl failed";
|
||||
|
||||
f = 42;
|
||||
|
||||
assert typeof f == float, "coercion on assign failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
27
test/scripts/comparisons.toy
Normal file
27
test/scripts/comparisons.toy
Normal file
@@ -0,0 +1,27 @@
|
||||
//test numbers
|
||||
assert 1 < 2, "1 < 2";
|
||||
assert 1 == 1, "1 == 1";
|
||||
assert 2 > 1, "2 > 1";
|
||||
assert 1 <= 2, "1 <= 2";
|
||||
assert 2 >= 1, "2 >= 1";
|
||||
|
||||
|
||||
//test variables
|
||||
var a = 1;
|
||||
var b = 2;
|
||||
|
||||
assert a < b, "a < b";
|
||||
assert a == a, "a == a";
|
||||
assert b > a, "b > a";
|
||||
assert a <= b, "a <= b";
|
||||
assert b >= a, "b >= a";
|
||||
|
||||
|
||||
//test negation
|
||||
assert !false, "!false";
|
||||
|
||||
var c = false;
|
||||
assert !c, "!c";
|
||||
|
||||
|
||||
print "All good";
|
||||
68
test/scripts/dot-and-matrix.toy
Normal file
68
test/scripts/dot-and-matrix.toy
Normal file
@@ -0,0 +1,68 @@
|
||||
//dot product
|
||||
var a = [1, 2, 3];
|
||||
var b = [4, 5, 6];
|
||||
|
||||
assert _length(a) == _length(b), "a and b lengths are wrong";
|
||||
|
||||
var acc = 0;
|
||||
for (var i = 0; i < _length(a); i++) {
|
||||
acc += _get(a, i) * _get(b, i);
|
||||
}
|
||||
|
||||
assert acc == 32, "dot product failed";
|
||||
|
||||
|
||||
//assume the args are matrices
|
||||
fn matrix(first, second) {
|
||||
//get the matrix size
|
||||
var l1 = _length(first); //rows
|
||||
var l2 = _length(_get(first, 0)); //cols
|
||||
|
||||
var l3 = _length(second); //rows
|
||||
var l4 = _length(_get(second, 0)); //cols
|
||||
|
||||
//pre-allocate the matrix
|
||||
var row = [];
|
||||
for (var j = 0; j < l4; j++) {
|
||||
_push(row, 0);
|
||||
}
|
||||
|
||||
var result = [];
|
||||
for (var i = 0; i < l1; i++) {
|
||||
_push(result, row);
|
||||
}
|
||||
|
||||
//assign the values
|
||||
for (var i = 0; i < _length(first); i++) {
|
||||
//select each element of "first"
|
||||
var firstElement = _get(first, i);
|
||||
|
||||
//for each element of second
|
||||
for (var i2 = 0; i2 < _length(second); i2++) {
|
||||
for (var j2 = 0; j2 < _length(_get(second, 0)); j2++) {
|
||||
|
||||
var val = _get(_get(first, i), i2) * _get(_get(second, i2), j2);
|
||||
|
||||
//TODO: needs better notation than this tmpRow variable
|
||||
var tmpRow = _get(result, i);
|
||||
_set(tmpRow, j2, val);
|
||||
_set(result, i, tmpRow);
|
||||
|
||||
//result[ i ][ j2 ] += first[i][i2] * second[i2][j2]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//matrix multiply
|
||||
var c = [[4], [5], [6]]; //this is a 3x1
|
||||
var d = [[1, 2, 3]]; //this is a 1x3
|
||||
|
||||
// c x d = 3x3
|
||||
// d x c = 1x1
|
||||
|
||||
assert matrix(c, d) == [[4,8,12],[5,10,15],[6,12,18]], "Matrix multiplication failed";
|
||||
|
||||
print "All good";
|
||||
20
test/scripts/dot-assignments-bugfix.toy
Normal file
20
test/scripts/dot-assignments-bugfix.toy
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
|
||||
NOTES: For some reason, this code results in the error:
|
||||
Undeclared variable "inner"
|
||||
|
||||
It only occurs under these very specific conditions.
|
||||
|
||||
It appears to be a compiler issue, see issue #38 for more info.
|
||||
|
||||
*/
|
||||
|
||||
fn _getValue(self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
var cache;
|
||||
cache = 42.getValue(); //assignment, rather than declaration, allows the bug
|
||||
|
||||
|
||||
print "All good";
|
||||
30
test/scripts/dot-chaining.toy
Normal file
30
test/scripts/dot-chaining.toy
Normal file
@@ -0,0 +1,30 @@
|
||||
//test function chaining with the dot operator
|
||||
|
||||
fn _identity(self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
fn _check(self) {
|
||||
assert self == 42, "dot chaining failed";
|
||||
return self;
|
||||
}
|
||||
|
||||
var val = 42;
|
||||
|
||||
val
|
||||
.identity()
|
||||
.check()
|
||||
.identity()
|
||||
.check()
|
||||
;
|
||||
|
||||
|
||||
//test the value is actually altered
|
||||
fn _increment(self) {
|
||||
return self + 1;
|
||||
}
|
||||
|
||||
assert 3.increment().increment() == 5, "dot chaining increment failed";
|
||||
|
||||
|
||||
print "All good";
|
||||
9
test/scripts/dottify-bugfix.toy
Normal file
9
test/scripts/dottify-bugfix.toy
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
fn _add(self, inc) {
|
||||
return self + inc;
|
||||
}
|
||||
|
||||
assert 1.add(2).add(3).add(4) == 10, "dottify bugfix failed";
|
||||
|
||||
|
||||
print "All good";
|
||||
77
test/scripts/functions.toy
Normal file
77
test/scripts/functions.toy
Normal file
@@ -0,0 +1,77 @@
|
||||
//test function return
|
||||
fn testFourtyTwo() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
assert testFourtyTwo() == 42, "function returns failed";
|
||||
|
||||
|
||||
//test function parameters
|
||||
fn identity(x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
assert identity("hello world") == "hello world", "identity function failed";
|
||||
|
||||
|
||||
//test closures
|
||||
fn make() {
|
||||
var counter = 0;
|
||||
|
||||
fn count() {
|
||||
return ++counter;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
var tally = make();
|
||||
|
||||
assert tally() == 1 && tally() == 2, "Closures failed";
|
||||
|
||||
|
||||
//test closures self-capture
|
||||
fn capture(count: int) {
|
||||
if (count > 5) {
|
||||
return count;
|
||||
}
|
||||
|
||||
return capture(count + 1);
|
||||
}
|
||||
|
||||
assert capture(0) == 6, "Self capture failed";
|
||||
|
||||
|
||||
//test expressions as arguments
|
||||
fn argFn() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
fn outerFn(val) {
|
||||
assert val == 42, "expression as argument failed";
|
||||
}
|
||||
|
||||
outerFn(argFn());
|
||||
|
||||
|
||||
//test extra parameters
|
||||
fn extra(one, two, ...rest) {
|
||||
assert rest == ["three", "four", "five", "six", "seven"], "rest parameters failed";
|
||||
}
|
||||
|
||||
extra("one", "two", "three", "four", "five", "six", "seven");
|
||||
|
||||
|
||||
//test underscore functions
|
||||
fn _example(self, a, b, c) {
|
||||
assert a == "a", "underscore failed (a)";
|
||||
assert b == "b", "underscore failed (b)";
|
||||
assert c == "c", "underscore failed (c)";
|
||||
return self;
|
||||
}
|
||||
|
||||
assert "hello world".example("a", "b", "c") == "hello world", "underscore call failed";
|
||||
|
||||
|
||||
|
||||
print "All good";
|
||||
52
test/scripts/imports-and-exports.toy
Normal file
52
test/scripts/imports-and-exports.toy
Normal file
@@ -0,0 +1,52 @@
|
||||
//test basic import/export
|
||||
{
|
||||
var variable: int = 42;
|
||||
export variable as field;
|
||||
}
|
||||
|
||||
{
|
||||
import field as value;
|
||||
assert value == 42, "import/export failed";
|
||||
}
|
||||
|
||||
|
||||
//test functions using import/export
|
||||
{
|
||||
fn f() {
|
||||
import field;
|
||||
|
||||
assert field == 42, "import in function failed";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//test importing/exporting of functions
|
||||
{
|
||||
fn func() {
|
||||
return 69;
|
||||
}
|
||||
|
||||
export func;
|
||||
}
|
||||
|
||||
{
|
||||
import func;
|
||||
assert func() == 69, "import/export of functions failed";
|
||||
}
|
||||
|
||||
|
||||
//test that variables retain their types with the typeof keyword
|
||||
{
|
||||
var t: type = int;
|
||||
|
||||
export t;
|
||||
}
|
||||
|
||||
{
|
||||
import t;
|
||||
|
||||
assert typeof t == type, "type retention failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
85
test/scripts/index-arrays.toy
Normal file
85
test/scripts/index-arrays.toy
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
//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:3] = "Holiday";
|
||||
|
||||
assert week == ["monday", "tuesday", "wednesday", "Holiday", "friday", "saturday", "sunday"], "basic replacement failed";
|
||||
}
|
||||
|
||||
|
||||
//test backwards
|
||||
{
|
||||
var week = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
|
||||
|
||||
assert week[::-1] == ["sunday", "saturday", "friday", "thursday", "wednesday", "tuesday", "monday"], "backwards failed";
|
||||
}
|
||||
|
||||
|
||||
//test array weird manipulation
|
||||
{
|
||||
var week = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
|
||||
|
||||
week[::-2] = ["first", "second", "third"];
|
||||
|
||||
assert week == ["monday", "tuesday", "third", "thursday", "second", "saturday", "first"], "array weird manipulation failed";
|
||||
}
|
||||
|
||||
|
||||
//test index arithmetic
|
||||
{
|
||||
var a = [1, 2, 3];
|
||||
|
||||
a[1] *= 3;
|
||||
|
||||
assert a == [1, 6, 3], "index arithmetic failed";
|
||||
}
|
||||
|
||||
|
||||
//test indexing with variables
|
||||
{
|
||||
var week = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
|
||||
|
||||
var first = 1;
|
||||
var second = 2;
|
||||
var third = -1;
|
||||
|
||||
assert week[first:second:third] == ["wednesday", "tuesday"], "indexing with variables failed";
|
||||
}
|
||||
|
||||
|
||||
//test nested indexing
|
||||
{
|
||||
var a = [[[0]]];
|
||||
|
||||
a[0][0][0] = 42;
|
||||
|
||||
assert a[0][0] == [42], "nested indexing failed";
|
||||
}
|
||||
|
||||
|
||||
//test combine example
|
||||
{
|
||||
fn combine(a, b, c) {
|
||||
return [a, b, c];
|
||||
}
|
||||
|
||||
assert combine(1, 2, 3) == [1, 2, 3], "combine example failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
43
test/scripts/index-dictionaries.toy
Normal file
43
test/scripts/index-dictionaries.toy
Normal file
@@ -0,0 +1,43 @@
|
||||
//test basic insertion
|
||||
{
|
||||
var d = [:];
|
||||
|
||||
d["foo"] = "bar";
|
||||
|
||||
assert d == ["foo":"bar"], "basic insertion failed";
|
||||
}
|
||||
|
||||
|
||||
//test index arithmetic
|
||||
{
|
||||
var d = ["one":1, "two":2, "three":3];
|
||||
|
||||
d["three"] *= 3;
|
||||
|
||||
assert d == ["one":1, "two":2, "three":9], "index arithmetic failed";
|
||||
}
|
||||
|
||||
|
||||
//test indexing with variables
|
||||
{
|
||||
var d = ["one":1, "two":2, "three":3];
|
||||
|
||||
var first = "two";
|
||||
|
||||
assert d[first] == 2, "indexing with variables failed";
|
||||
}
|
||||
|
||||
|
||||
//test nested indexing
|
||||
{
|
||||
var d = ["foo": ["bar": 0]];
|
||||
|
||||
d["foo"]["bar"] = 42;
|
||||
|
||||
print d;
|
||||
|
||||
assert d == ["foo": ["bar": 42]], "nested indexing failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
40
test/scripts/index-strings.toy
Normal file
40
test/scripts/index-strings.toy
Normal file
@@ -0,0 +1,40 @@
|
||||
//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
|
||||
var numbers = "0123456789";
|
||||
|
||||
numbers[::-2] = "abc";
|
||||
|
||||
assert numbers == "01234c6b8a", "string weird manipulation failed";
|
||||
|
||||
|
||||
//test indexing with variables
|
||||
var first = 11;
|
||||
var second = 15;
|
||||
var third = -1;
|
||||
|
||||
assert greeting[first:second:third] == "dlrow", "indexing with variables failed";
|
||||
|
||||
|
||||
print "All good";
|
||||
87
test/scripts/jumps-in-functions.toy
Normal file
87
test/scripts/jumps-in-functions.toy
Normal file
@@ -0,0 +1,87 @@
|
||||
fn sanity() {
|
||||
//test true jump
|
||||
if (true) {
|
||||
assert true, "if-then failed (1)";
|
||||
}
|
||||
else {
|
||||
assert false, "if-then failed (2)";
|
||||
}
|
||||
|
||||
|
||||
//test false jump
|
||||
if (false) {
|
||||
assert false, "if-then failed (3)";
|
||||
}
|
||||
else {
|
||||
assert true, "if-then failed (4)";
|
||||
}
|
||||
|
||||
|
||||
//test while loop
|
||||
var whileCounter = 0;
|
||||
while (whileCounter < 10) {
|
||||
whileCounter = whileCounter + 1;
|
||||
}
|
||||
|
||||
assert whileCounter == 10, "while-loop failed";
|
||||
|
||||
|
||||
//test for loop
|
||||
var forCache = 0;
|
||||
for (var i = 0; i < 20; i++) {
|
||||
forCache = i;
|
||||
}
|
||||
|
||||
assert forCache == 19, "for-loop failed";
|
||||
|
||||
|
||||
//test break - while
|
||||
var breakWhileCache = 0;
|
||||
while(true) {
|
||||
breakWhileCache = breakWhileCache + 1;
|
||||
|
||||
if (breakWhileCache >= 7) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert breakWhileCache == 7, "break-while failed";
|
||||
|
||||
|
||||
//test continue - while
|
||||
var continueWhileCache = 0;
|
||||
while (continueWhileCache < 10) {
|
||||
continueWhileCache = continueWhileCache + 1;
|
||||
|
||||
if (continueWhileCache >= 7) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert continueWhileCache < 7, "continue-while failed";
|
||||
}
|
||||
|
||||
|
||||
//test break - for
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (i >= 7) {
|
||||
break;
|
||||
}
|
||||
|
||||
assert i < 7, "break-for failed";
|
||||
}
|
||||
|
||||
|
||||
//test break - continue
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (i >= 7) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert i < 7, "continue-for failed";
|
||||
}
|
||||
|
||||
print "All good";
|
||||
}
|
||||
|
||||
//invoke the test
|
||||
sanity();
|
||||
82
test/scripts/jumps.toy
Normal file
82
test/scripts/jumps.toy
Normal file
@@ -0,0 +1,82 @@
|
||||
//test true jump
|
||||
if (true) {
|
||||
assert true, "if-then failed (1)";
|
||||
}
|
||||
else {
|
||||
assert false, "if-then failed (2)";
|
||||
}
|
||||
|
||||
|
||||
//test false jump
|
||||
if (false) {
|
||||
assert false, "if-then failed (3)";
|
||||
}
|
||||
else {
|
||||
assert true, "if-then failed (4)";
|
||||
}
|
||||
|
||||
|
||||
//test while loop
|
||||
var whileCounter = 0;
|
||||
while (whileCounter < 10) {
|
||||
whileCounter = whileCounter + 1;
|
||||
}
|
||||
|
||||
assert whileCounter == 10, "while-loop failed";
|
||||
|
||||
|
||||
//test for loop
|
||||
var forCache = 0;
|
||||
for (var i = 0; i < 20; i++) {
|
||||
forCache = i;
|
||||
}
|
||||
|
||||
assert forCache == 19, "for-loop failed";
|
||||
|
||||
|
||||
//test break - while
|
||||
var breakWhileCache = 0;
|
||||
while(true) {
|
||||
breakWhileCache = breakWhileCache + 1;
|
||||
|
||||
if (breakWhileCache >= 7) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert breakWhileCache == 7, "break-while failed";
|
||||
|
||||
|
||||
//test continue - while
|
||||
var continueWhileCache = 0;
|
||||
while (continueWhileCache < 10) {
|
||||
continueWhileCache = continueWhileCache + 1;
|
||||
|
||||
if (continueWhileCache >= 7) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert continueWhileCache < 7, "continue-while failed";
|
||||
}
|
||||
|
||||
|
||||
//test break - for
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (i >= 7) {
|
||||
break;
|
||||
}
|
||||
|
||||
assert i < 7, "break-for failed";
|
||||
}
|
||||
|
||||
|
||||
//test break - continue
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (i >= 7) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert i < 7, "continue-for failed";
|
||||
}
|
||||
|
||||
print "All good";
|
||||
50
test/scripts/lib/interactions.toy
Normal file
50
test/scripts/lib/interactions.toy
Normal file
@@ -0,0 +1,50 @@
|
||||
//test the standard library, under a number of different circumstances
|
||||
|
||||
//test basic import
|
||||
{
|
||||
import standard;
|
||||
|
||||
//this depends on external factors, so only check the length
|
||||
assert clock().length() == 24, "import library failed";
|
||||
}
|
||||
|
||||
|
||||
//test import within a function
|
||||
{
|
||||
fn f() {
|
||||
import standard;
|
||||
|
||||
assert clock != null, "import library within function failed";
|
||||
|
||||
return clock;
|
||||
}
|
||||
|
||||
//invoke
|
||||
assert f()().length() == 24, "import library within function and return failed";
|
||||
}
|
||||
|
||||
|
||||
//test closing over standard library element
|
||||
{
|
||||
import standard;
|
||||
|
||||
fn f() {
|
||||
assert clock != null, "import library outside function failed";
|
||||
|
||||
return clock;
|
||||
}
|
||||
|
||||
//invoke
|
||||
assert f()().length() == 24, "import library outside function and return failed";
|
||||
}
|
||||
|
||||
|
||||
//test importing as an alias
|
||||
{
|
||||
import standard as std;
|
||||
|
||||
assert std["clock"]().length() == 24, "import library as alias failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
10
test/scripts/lib/standard.toy
Normal file
10
test/scripts/lib/standard.toy
Normal file
@@ -0,0 +1,10 @@
|
||||
//test the standard library
|
||||
{
|
||||
import standard;
|
||||
|
||||
//this depends on external factors, so only check the length
|
||||
assert clock().length() == 24, "clock() import failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
56
test/scripts/lib/timer.toy
Normal file
56
test/scripts/lib/timer.toy
Normal file
@@ -0,0 +1,56 @@
|
||||
//test the timer library
|
||||
{
|
||||
//create a timer, manipulate it's values
|
||||
import timer;
|
||||
|
||||
//create a timer
|
||||
var timer: opaque = createTimer();
|
||||
|
||||
//set the timer
|
||||
timer.setTimer(42, 8891);
|
||||
|
||||
//check the timer values
|
||||
assert timer.getTimerSeconds() == 42, "getTimerSeconds() failed";
|
||||
assert timer.getTimerMicroseconds() == 42, "getTimerMicroseconds() failed";
|
||||
}
|
||||
|
||||
{
|
||||
//create a timer, run it for a short time
|
||||
import timer;
|
||||
|
||||
var timerA: opaque = createTimer();
|
||||
|
||||
timerA.startTimer();
|
||||
for (var i: int = 0; i < 1000 * 1000; i++);
|
||||
timerA.stopTimer();
|
||||
|
||||
//create another timer, run it for a longer time
|
||||
var timerB: opaque = createTimer();
|
||||
|
||||
timerB.startTimer();
|
||||
for (var i: int = 0; i < 1000 * 1000 * 10; i++);
|
||||
timerB.stopTimer();
|
||||
|
||||
//check to ensure that the second timer took longer than the first
|
||||
//WARNING: this has the small possibility of failing due to external factors
|
||||
var difference: opaque = timerA.compareTimer(timerB);
|
||||
|
||||
assert difference.getTimerSeconds() >= 0, "compareTimer() (seconds) failed";
|
||||
if (difference.getTimerSeconds() == 0) {
|
||||
assert difference.getTimerMicroseconds() >= 0, "compareTimer() (microseconds) failed";
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
//set a timer to check string representation
|
||||
import timer;
|
||||
|
||||
var timer: opaque = createTimer();
|
||||
|
||||
timer.setTimer(42, 999);
|
||||
|
||||
assert timer.timerToString() == "42.999", "timerToString() failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
6
test/scripts/logicals.toy
Normal file
6
test/scripts/logicals.toy
Normal file
@@ -0,0 +1,6 @@
|
||||
assert true && true, "boolean and failed";
|
||||
assert true || true, "boolean or failed";
|
||||
|
||||
assert false || true && true, "boolen precedence failed";
|
||||
|
||||
print "All good";
|
||||
339
test/scripts/long-array.toy
Normal file
339
test/scripts/long-array.toy
Normal file
@@ -0,0 +1,339 @@
|
||||
var arr: [string] = [
|
||||
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
"13",
|
||||
"14",
|
||||
"15",
|
||||
"16",
|
||||
"17",
|
||||
"18",
|
||||
"19",
|
||||
|
||||
"20",
|
||||
"21",
|
||||
"22",
|
||||
"23",
|
||||
"24",
|
||||
"25",
|
||||
"26",
|
||||
"27",
|
||||
"28",
|
||||
"29",
|
||||
|
||||
"30",
|
||||
"31",
|
||||
"32",
|
||||
"33",
|
||||
"34",
|
||||
"35",
|
||||
"36",
|
||||
"37",
|
||||
"38",
|
||||
"39",
|
||||
|
||||
"40",
|
||||
"41",
|
||||
"42",
|
||||
"43",
|
||||
"44",
|
||||
"45",
|
||||
"46",
|
||||
"47",
|
||||
"48",
|
||||
"49",
|
||||
|
||||
"50",
|
||||
"51",
|
||||
"52",
|
||||
"53",
|
||||
"54",
|
||||
"55",
|
||||
"56",
|
||||
"57",
|
||||
"58",
|
||||
"59",
|
||||
|
||||
"60",
|
||||
"61",
|
||||
"62",
|
||||
"63",
|
||||
"64",
|
||||
"65",
|
||||
"66",
|
||||
"67",
|
||||
"68",
|
||||
"69",
|
||||
|
||||
"70",
|
||||
"71",
|
||||
"72",
|
||||
"73",
|
||||
"74",
|
||||
"75",
|
||||
"76",
|
||||
"77",
|
||||
"78",
|
||||
"79",
|
||||
|
||||
"80",
|
||||
"81",
|
||||
"82",
|
||||
"83",
|
||||
"84",
|
||||
"85",
|
||||
"86",
|
||||
"87",
|
||||
"88",
|
||||
"89",
|
||||
|
||||
"90",
|
||||
"91",
|
||||
"92",
|
||||
"93",
|
||||
"94",
|
||||
"95",
|
||||
"96",
|
||||
"97",
|
||||
"98",
|
||||
"99",
|
||||
|
||||
//-------------------------
|
||||
|
||||
"100",
|
||||
"101",
|
||||
"102",
|
||||
"103",
|
||||
"104",
|
||||
"105",
|
||||
"106",
|
||||
"107",
|
||||
"108",
|
||||
"109",
|
||||
|
||||
"110",
|
||||
"111",
|
||||
"112",
|
||||
"113",
|
||||
"114",
|
||||
"115",
|
||||
"116",
|
||||
"117",
|
||||
"118",
|
||||
"119",
|
||||
|
||||
"120",
|
||||
"121",
|
||||
"122",
|
||||
"123",
|
||||
"124",
|
||||
"125",
|
||||
"126",
|
||||
"127",
|
||||
"128",
|
||||
"129",
|
||||
|
||||
"130",
|
||||
"131",
|
||||
"132",
|
||||
"133",
|
||||
"134",
|
||||
"135",
|
||||
"136",
|
||||
"137",
|
||||
"138",
|
||||
"139",
|
||||
|
||||
"140",
|
||||
"141",
|
||||
"142",
|
||||
"143",
|
||||
"144",
|
||||
"145",
|
||||
"146",
|
||||
"147",
|
||||
"148",
|
||||
"149",
|
||||
|
||||
"150",
|
||||
"151",
|
||||
"152",
|
||||
"153",
|
||||
"154",
|
||||
"155",
|
||||
"156",
|
||||
"157",
|
||||
"158",
|
||||
"159",
|
||||
|
||||
"160",
|
||||
"161",
|
||||
"162",
|
||||
"163",
|
||||
"164",
|
||||
"165",
|
||||
"166",
|
||||
"167",
|
||||
"168",
|
||||
"169",
|
||||
|
||||
"170",
|
||||
"171",
|
||||
"172",
|
||||
"173",
|
||||
"174",
|
||||
"175",
|
||||
"176",
|
||||
"177",
|
||||
"178",
|
||||
"179",
|
||||
|
||||
"180",
|
||||
"181",
|
||||
"182",
|
||||
"183",
|
||||
"184",
|
||||
"185",
|
||||
"186",
|
||||
"187",
|
||||
"188",
|
||||
"189",
|
||||
|
||||
"190",
|
||||
"191",
|
||||
"192",
|
||||
"193",
|
||||
"194",
|
||||
"195",
|
||||
"196",
|
||||
"197",
|
||||
"198",
|
||||
"199",
|
||||
|
||||
//-------------------------
|
||||
|
||||
"200",
|
||||
"201",
|
||||
"202",
|
||||
"203",
|
||||
"204",
|
||||
"205",
|
||||
"206",
|
||||
"207",
|
||||
"208",
|
||||
"209",
|
||||
|
||||
"210",
|
||||
"211",
|
||||
"212",
|
||||
"213",
|
||||
"214",
|
||||
"215",
|
||||
"216",
|
||||
"217",
|
||||
"218",
|
||||
"219",
|
||||
|
||||
"220",
|
||||
"221",
|
||||
"222",
|
||||
"223",
|
||||
"224",
|
||||
"225",
|
||||
"226",
|
||||
"227",
|
||||
"228",
|
||||
"229",
|
||||
|
||||
"230",
|
||||
"231",
|
||||
"232",
|
||||
"233",
|
||||
"234",
|
||||
"235",
|
||||
"236",
|
||||
"237",
|
||||
"238",
|
||||
"239",
|
||||
|
||||
"240",
|
||||
"241",
|
||||
"242",
|
||||
"243",
|
||||
"244",
|
||||
"245",
|
||||
"246",
|
||||
"247",
|
||||
"248",
|
||||
"249",
|
||||
|
||||
"250",
|
||||
"251",
|
||||
"252",
|
||||
"253",
|
||||
"254",
|
||||
"255",
|
||||
"256",
|
||||
"257",
|
||||
"258",
|
||||
"259",
|
||||
|
||||
"260",
|
||||
"261",
|
||||
"262",
|
||||
"263",
|
||||
"264",
|
||||
"265",
|
||||
"266",
|
||||
"267",
|
||||
"268",
|
||||
"269",
|
||||
|
||||
"270",
|
||||
"271",
|
||||
"272",
|
||||
"273",
|
||||
"274",
|
||||
"275",
|
||||
"276",
|
||||
"277",
|
||||
"278",
|
||||
"279",
|
||||
|
||||
"280",
|
||||
"281",
|
||||
"282",
|
||||
"283",
|
||||
"284",
|
||||
"285",
|
||||
"286",
|
||||
"287",
|
||||
"288",
|
||||
"289",
|
||||
|
||||
"290",
|
||||
"291",
|
||||
"292",
|
||||
"293",
|
||||
"294",
|
||||
"295",
|
||||
"296",
|
||||
"297",
|
||||
"298",
|
||||
"299"
|
||||
|
||||
];
|
||||
|
||||
print arr;
|
||||
4
test/scripts/long-dictionary.toy
Normal file
4
test/scripts/long-dictionary.toy
Normal file
@@ -0,0 +1,4 @@
|
||||
//NOTE: dictionaries are NOT stored in order
|
||||
var dict: [string : string] = ["0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9","10":"10","11":"11","12":"12","13":"13","14":"14","15":"15","16":"16","17":"17","18":"18","19":"19","20":"20","21":"21","22":"22","23":"23","24":"24","25":"25","26":"26","27":"27","28":"28","29":"29","30":"30","31":"31","32":"32","33":"33","34":"34","35":"35","36":"36","37":"37","38":"38","39":"39","40":"40","41":"41","42":"42","43":"43","44":"44","45":"45","46":"46","47":"47","48":"48","49":"49","50":"50","51":"51","52":"52","53":"53","54":"54","55":"55","56":"56","57":"57","58":"58","59":"59","60":"60","61":"61","62":"62","63":"63","64":"64","65":"65","66":"66","67":"67","68":"68","69":"69","70":"70","71":"71","72":"72","73":"73","74":"74","75":"75","76":"76","77":"77","78":"78","79":"79","80":"80","81":"81","82":"82","83":"83","84":"84","85":"85","86":"86","87":"87","88":"88","89":"89","90":"90","91":"91","92":"92","93":"93","94":"94","95":"95","96":"96","97":"97","98":"98","99":"99","100":"100","101":"101","102":"102","103":"103","104":"104","105":"105","106":"106","107":"107","108":"108","109":"109","110":"110","111":"111","112":"112","113":"113","114":"114","115":"115","116":"116","117":"117","118":"118","119":"119","120":"120","121":"121","122":"122","123":"123","124":"124","125":"125","126":"126","127":"127","128":"128","129":"129","130":"130","131":"131","132":"132","133":"133","134":"134","135":"135","136":"136","137":"137","138":"138","139":"139","140":"140","141":"141","142":"142","143":"143","144":"144","145":"145","146":"146","147":"147","148":"148","149":"149","150":"150","151":"151","152":"152","153":"153","154":"154","155":"155","156":"156","157":"157","158":"158","159":"159","160":"160","161":"161","162":"162","163":"163","164":"164","165":"165","166":"166","167":"167","168":"168","169":"169","170":"170","171":"171","172":"172","173":"173","174":"174","175":"175","176":"176","177":"177","178":"178","179":"179","180":"180","181":"181","182":"182","183":"183","184":"184","185":"185","186":"186","187":"187","188":"188","189":"189","190":"190","191":"191","192":"192","193":"193","194":"194","195":"195","196":"196","197":"197","198":"198","199":"199","200":"200","201":"201","202":"202","203":"203","204":"204","205":"205","206":"206","207":"207","208":"208","209":"209","210":"210","211":"211","212":"212","213":"213","214":"214","215":"215","216":"216","217":"217","218":"218","219":"219","220":"220","221":"221","222":"222","223":"223","224":"224","225":"225","226":"226","227":"227","228":"228","229":"229","230":"230","231":"231","232":"232","233":"233","234":"234","235":"235","236":"236","237":"237","238":"238","239":"239","240":"240","241":"241","242":"242","243":"243","244":"244","245":"245","246":"246","247":"247","248":"248","249":"249","250":"250","251":"251","252":"252","253":"253","254":"254","255":"255","256":"256","257":"257","258":"258","259":"259","260":"260","261":"261","262":"262","263":"263","264":"264","265":"265","266":"266","267":"267","268":"268","269":"269","270":"270","271":"271","272":"272","273":"273","274":"274","275":"275","276":"276","277":"277","278":"278","279":"279","280":"280","281":"281","282":"282","283":"283","284":"284","285":"285","286":"286","287":"287","288":"288","289":"289","290":"290","291":"291","292":"292","293":"293","294":"294","295":"295","296":"296","297":"297","298":"298","299":"299"];
|
||||
|
||||
print dict;
|
||||
335
test/scripts/long-literals.toy
Normal file
335
test/scripts/long-literals.toy
Normal file
@@ -0,0 +1,335 @@
|
||||
print 0;
|
||||
print 1;
|
||||
print 2;
|
||||
print 3;
|
||||
print 4;
|
||||
print 5;
|
||||
print 6;
|
||||
print 7;
|
||||
print 8;
|
||||
print 9;
|
||||
|
||||
print 10;
|
||||
print 11;
|
||||
print 12;
|
||||
print 13;
|
||||
print 14;
|
||||
print 15;
|
||||
print 16;
|
||||
print 17;
|
||||
print 18;
|
||||
print 19;
|
||||
|
||||
print 20;
|
||||
print 21;
|
||||
print 22;
|
||||
print 23;
|
||||
print 24;
|
||||
print 25;
|
||||
print 26;
|
||||
print 27;
|
||||
print 28;
|
||||
print 29;
|
||||
|
||||
print 30;
|
||||
print 31;
|
||||
print 32;
|
||||
print 33;
|
||||
print 34;
|
||||
print 35;
|
||||
print 36;
|
||||
print 37;
|
||||
print 38;
|
||||
print 39;
|
||||
|
||||
print 40;
|
||||
print 41;
|
||||
print 42;
|
||||
print 43;
|
||||
print 44;
|
||||
print 45;
|
||||
print 46;
|
||||
print 47;
|
||||
print 48;
|
||||
print 49;
|
||||
|
||||
print 50;
|
||||
print 51;
|
||||
print 52;
|
||||
print 53;
|
||||
print 54;
|
||||
print 55;
|
||||
print 56;
|
||||
print 57;
|
||||
print 58;
|
||||
print 59;
|
||||
|
||||
print 60;
|
||||
print 61;
|
||||
print 62;
|
||||
print 63;
|
||||
print 64;
|
||||
print 65;
|
||||
print 66;
|
||||
print 67;
|
||||
print 68;
|
||||
print 69;
|
||||
|
||||
print 70;
|
||||
print 71;
|
||||
print 72;
|
||||
print 73;
|
||||
print 74;
|
||||
print 75;
|
||||
print 76;
|
||||
print 77;
|
||||
print 78;
|
||||
print 79;
|
||||
|
||||
print 80;
|
||||
print 81;
|
||||
print 82;
|
||||
print 83;
|
||||
print 84;
|
||||
print 85;
|
||||
print 86;
|
||||
print 87;
|
||||
print 88;
|
||||
print 89;
|
||||
|
||||
print 90;
|
||||
print 91;
|
||||
print 92;
|
||||
print 93;
|
||||
print 94;
|
||||
print 95;
|
||||
print 96;
|
||||
print 97;
|
||||
print 98;
|
||||
print 99;
|
||||
|
||||
//-------------------------
|
||||
|
||||
print 100;
|
||||
print 101;
|
||||
print 102;
|
||||
print 103;
|
||||
print 104;
|
||||
print 105;
|
||||
print 106;
|
||||
print 107;
|
||||
print 108;
|
||||
print 109;
|
||||
|
||||
print 110;
|
||||
print 111;
|
||||
print 112;
|
||||
print 113;
|
||||
print 114;
|
||||
print 115;
|
||||
print 116;
|
||||
print 117;
|
||||
print 118;
|
||||
print 119;
|
||||
|
||||
print 120;
|
||||
print 121;
|
||||
print 122;
|
||||
print 123;
|
||||
print 124;
|
||||
print 125;
|
||||
print 126;
|
||||
print 127;
|
||||
print 128;
|
||||
print 129;
|
||||
|
||||
print 130;
|
||||
print 131;
|
||||
print 132;
|
||||
print 133;
|
||||
print 134;
|
||||
print 135;
|
||||
print 136;
|
||||
print 137;
|
||||
print 138;
|
||||
print 139;
|
||||
|
||||
print 140;
|
||||
print 141;
|
||||
print 142;
|
||||
print 143;
|
||||
print 144;
|
||||
print 145;
|
||||
print 146;
|
||||
print 147;
|
||||
print 148;
|
||||
print 149;
|
||||
|
||||
print 150;
|
||||
print 151;
|
||||
print 152;
|
||||
print 153;
|
||||
print 154;
|
||||
print 155;
|
||||
print 156;
|
||||
print 157;
|
||||
print 158;
|
||||
print 159;
|
||||
|
||||
print 160;
|
||||
print 161;
|
||||
print 162;
|
||||
print 163;
|
||||
print 164;
|
||||
print 165;
|
||||
print 166;
|
||||
print 167;
|
||||
print 168;
|
||||
print 169;
|
||||
|
||||
print 170;
|
||||
print 171;
|
||||
print 172;
|
||||
print 173;
|
||||
print 174;
|
||||
print 175;
|
||||
print 176;
|
||||
print 177;
|
||||
print 178;
|
||||
print 179;
|
||||
|
||||
print 180;
|
||||
print 181;
|
||||
print 182;
|
||||
print 183;
|
||||
print 184;
|
||||
print 185;
|
||||
print 186;
|
||||
print 187;
|
||||
print 188;
|
||||
print 189;
|
||||
|
||||
print 190;
|
||||
print 191;
|
||||
print 192;
|
||||
print 193;
|
||||
print 194;
|
||||
print 195;
|
||||
print 196;
|
||||
print 197;
|
||||
print 198;
|
||||
print 199;
|
||||
|
||||
//-------------------------
|
||||
|
||||
print 200;
|
||||
print 201;
|
||||
print 202;
|
||||
print 203;
|
||||
print 204;
|
||||
print 205;
|
||||
print 206;
|
||||
print 207;
|
||||
print 208;
|
||||
print 209;
|
||||
|
||||
print 210;
|
||||
print 211;
|
||||
print 212;
|
||||
print 213;
|
||||
print 214;
|
||||
print 215;
|
||||
print 216;
|
||||
print 217;
|
||||
print 218;
|
||||
print 219;
|
||||
|
||||
print 220;
|
||||
print 221;
|
||||
print 222;
|
||||
print 223;
|
||||
print 224;
|
||||
print 225;
|
||||
print 226;
|
||||
print 227;
|
||||
print 228;
|
||||
print 229;
|
||||
|
||||
print 230;
|
||||
print 231;
|
||||
print 232;
|
||||
print 233;
|
||||
print 234;
|
||||
print 235;
|
||||
print 236;
|
||||
print 237;
|
||||
print 238;
|
||||
print 239;
|
||||
|
||||
print 240;
|
||||
print 241;
|
||||
print 242;
|
||||
print 243;
|
||||
print 244;
|
||||
print 245;
|
||||
print 246;
|
||||
print 247;
|
||||
print 248;
|
||||
print 249;
|
||||
|
||||
print 250;
|
||||
print 251;
|
||||
print 252;
|
||||
print 253;
|
||||
print 254;
|
||||
print 255;
|
||||
print 256;
|
||||
print 257;
|
||||
print 258;
|
||||
print 259;
|
||||
|
||||
print 260;
|
||||
print 261;
|
||||
print 262;
|
||||
print 263;
|
||||
print 264;
|
||||
print 265;
|
||||
print 266;
|
||||
print 267;
|
||||
print 268;
|
||||
print 269;
|
||||
|
||||
print 270;
|
||||
print 271;
|
||||
print 272;
|
||||
print 273;
|
||||
print 274;
|
||||
print 275;
|
||||
print 276;
|
||||
print 277;
|
||||
print 278;
|
||||
print 279;
|
||||
|
||||
print 280;
|
||||
print 281;
|
||||
print 282;
|
||||
print 283;
|
||||
print 284;
|
||||
print 285;
|
||||
print 286;
|
||||
print 287;
|
||||
print 288;
|
||||
print 289;
|
||||
|
||||
print 290;
|
||||
print 291;
|
||||
print 292;
|
||||
print 293;
|
||||
print 294;
|
||||
print 295;
|
||||
print 296;
|
||||
print 297;
|
||||
print 298;
|
||||
print 299;
|
||||
|
||||
//-------------------------
|
||||
91
test/scripts/native-functions.toy
Normal file
91
test/scripts/native-functions.toy
Normal file
@@ -0,0 +1,91 @@
|
||||
|
||||
{
|
||||
//test arrays without types
|
||||
var array = [];
|
||||
|
||||
assert _length(array) == 0, "_length failed with array";
|
||||
|
||||
_push(array, 1);
|
||||
_push(array, 2);
|
||||
_push(array, 3);
|
||||
_push(array, 4);
|
||||
_push(array, "foo");
|
||||
|
||||
assert _length(array) == 5, "_push failed with array";
|
||||
assert _pop(array) == "foo", "_pop failed with array";
|
||||
|
||||
_set(array, 2, "bar");
|
||||
assert array == [1, 2, "bar", 4], "_set failed with array";
|
||||
assert _get(array, 3) == 4, "_get failed with array";
|
||||
|
||||
|
||||
//test dictionaries without types
|
||||
var dict = [:];
|
||||
|
||||
_set(dict, "key", "value");
|
||||
_set(dict, 1, 2);
|
||||
|
||||
assert dict == ["key":"value", 1:2], "_set failed with dictionaries";
|
||||
assert _get(dict, "key") == "value", "_get failed with dictionaries";
|
||||
|
||||
|
||||
//test _length
|
||||
assert _length(array) == 4 && _length(dict) == 2, "_length failed with array or dictionaries";
|
||||
|
||||
|
||||
//test clear
|
||||
_clear(array);
|
||||
_clear(dict);
|
||||
|
||||
assert _length(array) == 0 && _length(dict) == 0, "_clear failed with array or dictionaries";
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
//test arrays with types
|
||||
var array: [int] = [];
|
||||
|
||||
assert _length(array) == 0, "_length failed with array (+ types)";
|
||||
|
||||
_push(array, 1);
|
||||
_push(array, 2);
|
||||
_push(array, 3);
|
||||
_push(array, 4);
|
||||
_push(array, 10);
|
||||
|
||||
assert _length(array) == 5, "_push or failed with array (+ types)";
|
||||
assert _pop(array) == 10, "_pop failed with array (+ types)";
|
||||
|
||||
_set(array, 2, 70);
|
||||
assert array == [1, 2, 70, 4], "_set failed with array (+ types)";
|
||||
assert _get(array, 3) == 4, "_get failed with array (+ types)";
|
||||
|
||||
|
||||
//test dictionaries with types
|
||||
var dict: [string : string] = [:];
|
||||
|
||||
_set(dict, "key", "value");
|
||||
|
||||
assert dict == ["key":"value"], "_set failed with dictionaries (+ types)";
|
||||
assert _get(dict, "key") == "value", "_get failed with dictionaries (+ types)";
|
||||
|
||||
|
||||
//test length with types
|
||||
assert _length(array) == 4 && _length(dict) == 1, "_length failed with array or dictionaries (+ types)";
|
||||
|
||||
|
||||
//test clear with types
|
||||
_clear(array);
|
||||
_clear(dict);
|
||||
|
||||
assert _length(array) == 0 && _length(dict) == 0, "_clear failed with array or dictionaries (+ types)";
|
||||
}
|
||||
|
||||
{
|
||||
var str = "hello world";
|
||||
|
||||
assert _length(str) == 11, "_length failed with string";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
5
test/scripts/opaque-data-type.toy
Normal file
5
test/scripts/opaque-data-type.toy
Normal file
@@ -0,0 +1,5 @@
|
||||
//test the opaque data type works
|
||||
|
||||
var o: opaque = produce();
|
||||
|
||||
consume(o);
|
||||
8
test/scripts/panic-within-functions.toy
Normal file
8
test/scripts/panic-within-functions.toy
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
fn panic() {
|
||||
assert false, "!ignore panicking within a function";
|
||||
}
|
||||
|
||||
panic();
|
||||
panic();
|
||||
9
test/scripts/sample_code.toy
Normal file
9
test/scripts/sample_code.toy
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
|
||||
var complex: type = astype [string: [int]];
|
||||
var deep: type = astype [[[ int ]]];
|
||||
|
||||
|
||||
|
||||
|
||||
11
test/scripts/separate-exports.toy
Normal file
11
test/scripts/separate-exports.toy
Normal file
@@ -0,0 +1,11 @@
|
||||
//test exports
|
||||
var field: int = 42;
|
||||
|
||||
fn function() {
|
||||
return 69;
|
||||
}
|
||||
|
||||
export field;
|
||||
export function;
|
||||
|
||||
print "All good";
|
||||
10
test/scripts/separate-imports.toy
Normal file
10
test/scripts/separate-imports.toy
Normal file
@@ -0,0 +1,10 @@
|
||||
//test imports
|
||||
import field;
|
||||
//import function;
|
||||
|
||||
//assert field == 42, "import field failed";
|
||||
|
||||
//assert function() == 69, "import function failed";
|
||||
|
||||
print "All good";
|
||||
|
||||
25
test/scripts/types.toy
Normal file
25
test/scripts/types.toy
Normal file
@@ -0,0 +1,25 @@
|
||||
//basic types
|
||||
var t: type = int;
|
||||
var u: t = 42;
|
||||
|
||||
assert t == int, "types are not first class";
|
||||
assert u == 42, "first-class types are screwing with values";
|
||||
|
||||
|
||||
//differentiate by the "type" value
|
||||
var v: type = astype [int];
|
||||
var w = [int];
|
||||
var x = v;
|
||||
|
||||
assert w == [int], "defining an array of types failed";
|
||||
assert x == astype [int], "re-assigning a type value failed";
|
||||
|
||||
//complex type
|
||||
var complex: type = astype [string : [int]];
|
||||
var dict: complex = [
|
||||
"first array": [1, 2, 3],
|
||||
"second array": [4, 5, 6],
|
||||
"third array": [7, 8, 9]
|
||||
];
|
||||
|
||||
print "All good";
|
||||
Reference in New Issue
Block a user