mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Merge branch 'Ratstail91:main' into main
This commit is contained in:
@@ -10,4 +10,20 @@
|
||||
}
|
||||
|
||||
|
||||
//test function coercion
|
||||
{
|
||||
fn f(arg: float) {
|
||||
assert typeof arg == float, "argument coercion failed";
|
||||
}
|
||||
|
||||
f(42);
|
||||
|
||||
fn g(): float {
|
||||
return 42;
|
||||
}
|
||||
|
||||
assert typeof g() == float, "return coercion failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
|
||||
20
test/scripts/indexing-in-argument-list-bugfix.toy
Normal file
20
test/scripts/indexing-in-argument-list-bugfix.toy
Normal file
@@ -0,0 +1,20 @@
|
||||
fn max(lhs, rhs) {
|
||||
if (lhs > rhs) {
|
||||
return lhs;
|
||||
}
|
||||
else {
|
||||
return rhs;
|
||||
}
|
||||
}
|
||||
|
||||
var array = [42];
|
||||
|
||||
var result = null;
|
||||
|
||||
//problematic line
|
||||
result = max(0, array[0]);
|
||||
|
||||
assert result == 42, "Indexing in argument list failed";
|
||||
|
||||
|
||||
print "All good";
|
||||
@@ -144,8 +144,8 @@ import math;
|
||||
|
||||
// test atanh
|
||||
{
|
||||
assert chechIsInfinite(atanh(1)) == true, "atanh(1) failed";
|
||||
assert chechIsInfinite(atanh(-1)) == true, "atanh(-1) failed";
|
||||
assert checkIsInfinite(atanh(1)) == true, "atanh(1) failed";
|
||||
assert checkIsInfinite(atanh(-1)) == true, "atanh(-1) failed";
|
||||
assert epsilionCompare(atanh(0), 0), "atanh(0) failed";
|
||||
}
|
||||
|
||||
@@ -159,21 +159,21 @@ import math;
|
||||
}
|
||||
|
||||
|
||||
// test chechIsFinite
|
||||
// test checkIsFinite
|
||||
{
|
||||
assert chechIsFinite(NAN) == false, "chechIsFinite(NAN) failed";
|
||||
assert chechIsFinite(INFINITY) == false, "chechIsFinite(INFINITY) failed";
|
||||
assert chechIsFinite(0.0) == true, "chechIsFinite(0.0) failed";
|
||||
assert chechIsFinite(1) == true, "chechIsFinite(1) failed";
|
||||
assert checkIsFinite(NAN) == false, "checkIsFinite(NAN) failed";
|
||||
assert checkIsFinite(INFINITY) == false, "checkIsFinite(INFINITY) failed";
|
||||
assert checkIsFinite(0.0) == true, "checkIsFinite(0.0) failed";
|
||||
assert checkIsFinite(1) == true, "checkIsFinite(1) failed";
|
||||
}
|
||||
|
||||
|
||||
// test chechIsInfinite
|
||||
// test checkIsInfinite
|
||||
{
|
||||
assert chechIsInfinite(NAN) == false, "chechIsInfinite(NAN) failed";
|
||||
assert chechIsInfinite(INFINITY) == true, "chechIsInfinite(INFINITY) failed";
|
||||
assert chechIsInfinite(0.0) == false, "chechIsInfinite(0.0) failed";
|
||||
assert chechIsInfinite(1) == false, "chechIsInfinite(1) failed";
|
||||
assert checkIsInfinite(NAN) == false, "checkIsInfinite(NAN) failed";
|
||||
assert checkIsInfinite(INFINITY) == true, "checkIsInfinite(INFINITY) failed";
|
||||
assert checkIsInfinite(0.0) == false, "checkIsInfinite(0.0) failed";
|
||||
assert checkIsInfinite(1) == false, "checkIsInfinite(1) failed";
|
||||
}
|
||||
|
||||
// test epsilionCompare
|
||||
|
||||
14
test/scripts/short-circuit.toy
Normal file
14
test/scripts/short-circuit.toy
Normal file
@@ -0,0 +1,14 @@
|
||||
//These operators should short-circuit
|
||||
assert (true && false) == false, "(true && false) == false failed";
|
||||
assert (false && true) == false, "(false && true) == false failed";
|
||||
|
||||
assert (true || false) == true, "(true || false) == true failed";
|
||||
assert (false || true) == true, "(false || true) == true failed";
|
||||
|
||||
|
||||
//make sure the right value is being returned when chained
|
||||
assert "a" && "b" && "c" == "c", "chained && failed";
|
||||
assert "a" || "b" || "c" == "a", "chained || failed";
|
||||
|
||||
|
||||
print "All good";
|
||||
@@ -1,9 +0,0 @@
|
||||
//explicitly support && and || short circuits
|
||||
|
||||
assert 1 && 2 == 2, "&& short-circuit failed";
|
||||
|
||||
assert 1 || 2 == 1, "|| short-circuit failed";
|
||||
|
||||
|
||||
print "All good";
|
||||
|
||||
8
test/scripts/trailing-comma-bugfix.toy
Normal file
8
test/scripts/trailing-comma-bugfix.toy
Normal file
@@ -0,0 +1,8 @@
|
||||
var array = [
|
||||
1, 2, 3,
|
||||
4, 5, 6,
|
||||
7, 8, 9, //explicitly leave a trailing comma
|
||||
];
|
||||
|
||||
|
||||
print "All good";
|
||||
@@ -18,6 +18,7 @@ static void noPrintFn(const char* output) {
|
||||
//NO OP
|
||||
}
|
||||
|
||||
int failedAssertions = 0;
|
||||
int ignoredAssertions = 0;
|
||||
static void noAssertFn(const char* output) {
|
||||
if (strncmp(output, "!ignore", 7) == 0) {
|
||||
@@ -27,6 +28,7 @@ static void noAssertFn(const char* output) {
|
||||
fprintf(stderr, TOY_CC_ERROR "Assertion failure: ");
|
||||
fprintf(stderr, "%s", output);
|
||||
fprintf(stderr, "\n" TOY_CC_RESET); //default new line
|
||||
failedAssertions++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,6 +129,7 @@ int main() {
|
||||
"index-assignment-left-bugfix.toy",
|
||||
"index-dictionaries.toy",
|
||||
"index-strings.toy",
|
||||
"indexing-in-argument-list-bugfix.toy",
|
||||
"jumps.toy",
|
||||
"jumps-in-functions.toy",
|
||||
"logicals.toy",
|
||||
@@ -138,8 +141,9 @@ int main() {
|
||||
"panic-within-functions.toy",
|
||||
"polyfill-insert.toy",
|
||||
"polyfill-remove.toy",
|
||||
"short-circuiting-support.toy",
|
||||
"short-circuit.toy",
|
||||
"ternary-expressions.toy",
|
||||
"trailing-comma-bugfix.toy",
|
||||
"types.toy",
|
||||
NULL
|
||||
};
|
||||
@@ -160,7 +164,10 @@ int main() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
|
||||
return 0;
|
||||
if (failedAssertions == 0) {
|
||||
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
|
||||
}
|
||||
|
||||
return failedAssertions;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user