90 lines
1.4 KiB
Plaintext
90 lines
1.4 KiB
Plaintext
//NOTE: Not tested: null (neither true or false), Opaque, Any
|
|
{
|
|
//booleans
|
|
var value: Bool = true;
|
|
if (value) print "boolean";
|
|
else assert false, "boolean";
|
|
}
|
|
|
|
{
|
|
var value: Bool = false;
|
|
if (value) assert false, "boolean";
|
|
else print "boolean";
|
|
}
|
|
|
|
//integers
|
|
{
|
|
var value: Int = 42;
|
|
if (value) print "integer";
|
|
else assert false, "integer";
|
|
}
|
|
|
|
{
|
|
var value: Int = 0;
|
|
if (value) assert false, "integer";
|
|
else print "integer";
|
|
}
|
|
|
|
//floats
|
|
{
|
|
var value: Float = 42.8891;
|
|
if (value) print "float";
|
|
else assert false, "float";
|
|
}
|
|
|
|
{
|
|
var value: Float = 0;
|
|
if (value) assert false, "float";
|
|
else print "float";
|
|
}
|
|
|
|
//strings
|
|
{
|
|
var value: String = "foobar";
|
|
if (value) print "string";
|
|
else assert false, "string";
|
|
}
|
|
|
|
{
|
|
var value: String = ""; //empty string is truthy
|
|
if (value) print "string";
|
|
else assert false, "string";
|
|
}
|
|
|
|
//arrays
|
|
{
|
|
var value: Array = [1,2,3];
|
|
if (value) print "array";
|
|
else assert false, "array";
|
|
}
|
|
|
|
{
|
|
var value: Array = []; //empty array is truthy
|
|
if (value) print "array";
|
|
else assert false, "array";
|
|
}
|
|
|
|
//table
|
|
{
|
|
var value: Table = ["alpha":"bravo"];
|
|
if (value) print "table";
|
|
else assert false, "table";
|
|
}
|
|
|
|
{
|
|
var value: Table = [:]; //empty table is truthy
|
|
if (value) print "table";
|
|
else assert false, "table";
|
|
}
|
|
|
|
//function
|
|
{
|
|
fn identity(x) {
|
|
return x;
|
|
}
|
|
|
|
if (identity) print "function";
|
|
else assert false, "function";
|
|
}
|
|
|
|
//TODO: test library as API, would be cleaner than using asserts |