Skip to content

Instantly share code, notes, and snippets.

@abcarroll
Created November 18, 2021 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abcarroll/bbf958808baff05fc5251707047e57e1 to your computer and use it in GitHub Desktop.
Save abcarroll/bbf958808baff05fc5251707047e57e1 to your computer and use it in GitHub Desktop.
@test "Assignment Expressions":
@test "Assign variable to variable":
let $x = $y;
@test "Assign variable to variable with simple type":
let $x: int = $y;
@test "Literals":
// TODO: Strings
@test "Integers":
@each-expression:
let $x = 0;
let $x = +0;
let $x = -0;
let $x = 1;
let $x = +1;
let $x = -1;
let $x = 9223372036854775807;
let $x = -9223372036854775807;
@test "Floating Point":
@each-expression:
// Number.MAX_VALUE and Number.MIN_VALUE in JS
let $x: f64 = 1.7976931348623157e+308;
let $x: f64 = 5e-324;
// Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER
let $x: f64 = 9007199254740991;
let $x: f64 = -9007199254740991;
let $x: f64 = 123.45;
let $x: f64 = 123e4;
let $x: f64 = 123e+4;
let $x: f64 = 123e-4;
let $x: f64 = 123.0e4;
let $x: f64 = 123.0e+4;
let $x: f64 = 123.0e-4;
let $x: f64 = 123.1e4;
let $x: f64 = 123.2e+4;
let $x: f64 = 123.3e-4;
@test "...must end with a numeral":
@each-expression(fail):
let $x = 0.;
let $x = +0.;
let $x = -0.;
let $y = 1.;
let $y = +1.;
let $y = -1.;
@test "Boolean Values"
@foreach expression:
let $x = true;
let $x = false;
@foreach expression fail:
// Ensure the literal constants cannot be in sequence and does not trigger string concat
let $x = true true;
let $x = true false;
let $x = true 1;
let $x = false 0;
let $x = 1 true;
let $x = 0 true;
@test "Null Value"
@foreach expression:
let $x = null;
null;
@foreach expression fail:
let $x = null null;
null null;
@group "Expression Parsing":
@foreach "Array Dimension Access with const index":
let $x = $a[0];
let $x = $abc[1];
@foreach "Array Dimension Access with Expression":
let $x = $a[$b + $c];
@test "Function call":
@test "with no arguments":
let $x = foo();
@test "with constant ordered arguments":
let $x = foo(1, 2, 3);
@test "with array dimension reference as arguments"
let $x = foo($a, $b[0]);
@test "Exponent is right-associative":
let $x = 1 ** 2 ** 3;
@test-each "... and parens works as expected":
let $x = (1 ** 2) ** 3;
// same as no parens
let $x = 1 ** (2 ** 3);
@group
@group "Conditional Statement Parsing":
@test "If Condition":
@test "without parens":
if $e == 1 {
$e = 2;
}
@test "without parens, with elseif":
if $f == 1 {
$f = 2;
} elseif $f == 3 {
$f = 4;
}
@test "without parens, with else only":
if $g == 1 {
$g = $g + $g;
} else {
$g = $g * $g;
}
@test "without parens, with elseif and else":
if $h == 1 {
$h = 2;
} elseif $h == 3 {
$h = 4;
} else {
$h = 5;
}
@test "without parens, with else and chained if"
if $i == 1 {
$i = 2;
} else if $i == 2 {
$i = 3;
} else if $i == 3 {
$i = 4;
}
@test "Function Declaration"
@test "Simple fn decl with if cond":
fn testIfCondition()
{
if 1{
}
if($yeah) {
}
if $foo {
}
if $foo{
}
}
@test "Basic arithmetic ordering"
let $x = $a - $b + $c / $d * $e;
let $x = ($a - $b) + $c / $d * $e;
let $x = ($a - ($b + $c)) / $d * $e;
@test "Unary Operators"
let $x = -5;
let $x = -5 + -5;
let $x = -0 + +0;
@! "with floating points":
let $x = +0.0 + -0.0;
let $x = -0.001e+3 - -0.009
@test "Binary Operators"
@test "Addition with zero":
let $x = 0 + 0;
let $x = -0 + 0;
let $x = -0 + +0;
let $x = -0 + -0;
let $x = +0 + 0;
let $x = +0 + +0;
let $x = +0 + -0;
@test "Subtraction with zero":
let $x = 0 - 0;
let $x = -0 - 0;
let $x = -0 - +0;
let $x = -0 - -0;
let $x = +0 - 0;
let $x = +0 - +0;
let $x = +0 - -0;
@test "All Unary Operators":
let $x = new Foo;
let $x = new Foo();
let $x = clone $x;
let $x = -$y;
let $x = +$y;
let $x = !$y;
let $x = ~$y;
@test "All binary operators":
// Multiplicative
let $x = $a * $b;
let $x = $a / $b;
let $x = $a % $b;
// Addititve
let $x = $a $b;
let $x = $a $b;
// Unsigned?
let $x = $a << $b;
let $x = $a >> $b;
let $x = $a < $b;
let $x = $a > $b;
let $x = $a <= $b;
let $x = $a <= $b;
let $x = $a == $b;
let $x = $a != $b;
let $x = $a === $b;
let $x = $a !== $b;
let $x = $a <=> $b;
let $x = $a is $b;
let $x = $a is not $b;
let $x = $a in $b;
let $x = $a not in $b;
let $x = $a & $b;
let $x = $a | $b;
let $x = $a ^ $b;
let $x = $a && $b;
let $x = $a || $b;
let $x = $a ?? $b;
let $x = $a ? $b : $c;
let $x = yield from $b;
let $x = delete $b;
let $x = yield $b;
@test "Anonymous Functions"
@test "Declare and assign to variable"
let $x = fn(s) {
return s.split("/\r?\n/");
};
@test "Then call"
@@includePrevious
let $s = $x("abc");
@test "
@test "Misc Tests":
$q = $abc[3] + $xyz * foo($a, $b[0]);
$w = 1 + 2 - 3 / 4 * 5;
$e = 10 << 1;
$r = 9 % 3;
$t = $abc[$q[1 + rand()]];
$y = 1 + 2 * 3;
$u = 1 * 2 - 3;
$i = $a[1 + 2 * 3];
$o = $a[1 * 2 * 3 + $a * 5];
$p = $a[$b[$c]];
$a = $a[(5 + 5) * 6 * $a];
$s = $a[5];
$d = $a[ 1 + $b[6] ];
$f = hello(1, 2);
$g = $a [ rand(1, 2) ];
$h = $a[rand($a[0], $b[1])];
$j = $a[rand(1, 2) + 1];
$k = 1 + 2 * 3;
$l = 1 * 2 - 3;
$z = foo(0);
$x = $a[1 + 2][2][3 + $q[$w[0][0]] + ha()][foo()];
$c = $a[foo() + bar()];
let $v = 0;
let $b = 10;
let $n: int = 2**3**4;
$q = $abc[3] + $xyz * foo($a, $b[0]);
$w = 1 + 2 - 3 / 4 * 5;
$e = 10 << 1;
$r = 9 % 3;
$t = $abc[$q[1 + rand()]];
$q = 1 + 2 * 3;
$w = 1 * 2 - 3;
$e = $a[1 + 2 * 3];
$r = $a[1 * 2 * 3 + $a * 5];
$t = $a[$b[$c]];
$y = $a[(5 + 5) * 6 * $a];
$u = $a[5];
$i = $a[ 1 + $b[6] ];
$o = hello(1, 2);
$p = $a [ rand(1, 2) ];
$a = $a[rand($a[0], $b[1])];
$s = $a[rand(1, 2) + 1];
$q = 1 + 2 * 3;
$w = 1 * 2 - 3;
$e = foo(0);
foo(0)[0](fn() { return 0; })(1, 2)[0];
$q = $a[1 + 2][2][3 + $q[$w[0][0]] + ha()][foo()];
$w = $a[foo() + bar()];
$e = $a->$b->$c;
fn testFnDecl()
{
let $x = 0;
let $y: int = 10;
let $z: string = "Hello World";
}
pub static fn testFnMore($a: int, $b: int): int
{
let $x = 5;
}
fn testFnAgain($a: int): string
{
let $z = 6;
}
fn complexTypeTest($a: map<string>, $b: string)
{
let $z = $a[ $b ];
return $z;
}
fn testIfCondAndComplexVarRef($x: int, $y: int)
{
let $r: int;
if $x > $y {
$r = $x;
}
return $r;
}
discriminant=b*b-4*a*c;
x = 1 + 5 * 3;
y=2**3**4;
z=-5;
yield x + d;
delete z;
3 in x;
3 !== 3;
$z = 5;
let $a = 6;
if($a == 1) {
$a = 2;
}
if($b == 1) {
$b = 2;
} elseif($a == 3) {
$b = 4;
}
if($c == 1) {
$c = 2;
} else {
$c = 4;
}
if($d == 1) {
$d = 2;
} elseif($d == 3) {
$d = 4;
} else {
$d = 5;
}
if $g == 1 {
$g = 2;
} else {
$g = 4;
}
if($i == 1) {
$i = 2;
} elseif $i == 3 {
$i = 4;
}
if $j == 1 {
$j = 2;
} elseif($j == 3) {
$j = 4;
}
if($k == 1) {
$k = 2;
} elseif $k == 3 {
$k = 4;
} else {
$k = 5;
}
if $m == 1 {
$m = 2;
} elseif($m == 3) {
$m = 4;
} else {
$m = 5;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment