mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Build Wren for more targets, and run the test suite on both 32 and 64 bit builds. * Update the build config to test both with and without NAN_TAGGING defined. * Updatest `util/test.py` to take the executable suffix as a parameter. This allows the makefile to control which binaries will be tested. Adds a new target to the makefile to be run by travis, this runs the test suite against all of the configurations it builds. * Gcc on some 32 bit platforms was complaining about numeric overflows when -INFINITY was used. Update the logic for converting a double to a string to not explicitly check against the literal values. * Make CI builds run the tests on both 64 _and_ 32 bit builds. * If I limit the number of CPUs on my MBP I can get some of the tests to time out, I'm imagining that the specs of the Travis Macs means that the same is happening there too. Updated the test script to allow an extra few seconds for the test to complete successfully before killing it. * Due to slight differences in accuracy in some computations tests were failing on 32 bit builds. Stop comparing things quite as exactly in the cases where it is causing issues. For some reason 12.34 was refusing to compare equal to itself. Bad show 12.34 :-/. I've also updated the test so it doesn't leak handles even if the assertions fail. * Double-cast from `double` to `uint32_t` to prevent undefined behaviour on overflow of basic integers. This should hopefully prevent 32 bit test failures on Linux. * Move to a version of LibUV with a fix for the 32 bit build error on Travis.
190 lines
3.5 KiB
Plaintext
190 lines
3.5 KiB
Plaintext
// This file provides examples of syntactic constructs in wren, which is mainly
|
|
// interesting for testing syntax highlighters.
|
|
|
|
// This is a comment.
|
|
/* This is /* a nested */ comment. */
|
|
|
|
// Class definition with a toplevel name.
|
|
class SyntaxExample {
|
|
// Constructor
|
|
construct new() {
|
|
// Top-level name `IO`
|
|
System.print("I am a constructor!")
|
|
|
|
// Method calls
|
|
variables
|
|
fields()
|
|
|
|
// Block arguments
|
|
fields { block }
|
|
fields {|a, b| block }
|
|
fields(argument) { block }
|
|
fields(argument) {|a, b| block }
|
|
|
|
// Static method call
|
|
SyntaxExample.fields(1)
|
|
}
|
|
|
|
// Constructor with arguments
|
|
construct constructor(a, b) {
|
|
print(a, b)
|
|
field = a
|
|
}
|
|
|
|
// Method without arguments
|
|
variables {
|
|
// Valid local variable names.
|
|
var hi
|
|
var camelCase
|
|
var PascalCase
|
|
var abc123
|
|
var ALL_CAPS
|
|
}
|
|
|
|
// Method with empty argument list
|
|
fields() {
|
|
// Fields
|
|
_under_score = 1
|
|
_field = 2
|
|
}
|
|
|
|
// Static method with single argument
|
|
static fields(a) {
|
|
// Static field
|
|
__a = a
|
|
}
|
|
|
|
// Setter
|
|
field=(value) { _field = value }
|
|
|
|
// Method with arguments
|
|
print(a, b) { System.print(a + b) }
|
|
|
|
// Operators
|
|
+(other) { "infix + %(other)" }
|
|
-(other) { "infix - %(other)" }
|
|
*(other) { "infix * %(other)" }
|
|
/(other) { "infix / %(other)" }
|
|
%(other) { "infix \% %(other)" }
|
|
<(other) { "infix < %(other)" }
|
|
>(other) { "infix > %(other)" }
|
|
<=(other) { "infix <= %(other)" }
|
|
>=(other) { "infix >= %(other)" }
|
|
==(other) { "infix == %(other)" }
|
|
!=(other) { "infix != %(other)" }
|
|
&(other) { "infix & %(other)" }
|
|
|(other) { "infix | %(other)" }
|
|
|
|
! { "prefix !" }
|
|
~ { "prefix ~" }
|
|
- { "prefix -" }
|
|
}
|
|
|
|
// `class`, `is`
|
|
class ReservedWords is SyntaxExample {
|
|
reserved {
|
|
// `super`, `true`, `false`
|
|
super(true, false)
|
|
// `this`
|
|
this.foo
|
|
}
|
|
|
|
foo {
|
|
// `var`
|
|
var n = 27
|
|
// `while`, `if`, `else`
|
|
while (n != 1) if (n % 2 == 0) n = n / 2 else n = 3 * n + 1
|
|
|
|
// `for`, `in`
|
|
for (beatle in ["george", "john", "paul", "ringo"]) {
|
|
System.print(beatle)
|
|
// `break`
|
|
break
|
|
}
|
|
|
|
// `return`, `null`
|
|
return null
|
|
}
|
|
|
|
imports {
|
|
// `import`
|
|
import "hello"
|
|
// `import`, `for`
|
|
import "set" for Set
|
|
}
|
|
|
|
// `foreign`, `static`
|
|
// foreign static bar
|
|
// foreign baz(string)
|
|
// (Remove lines above to make this file compile)
|
|
}
|
|
|
|
class Literals is SyntaxExample {
|
|
booleans { true || false }
|
|
|
|
numbers {
|
|
0
|
|
1234
|
|
-5678
|
|
3.14159
|
|
1.0
|
|
-12.34
|
|
0x1000000
|
|
// Literals larger than 0x1000000 are only valid in 64 bit builds
|
|
// 0xdeadbeef
|
|
// 0x1234567890ABCDEF
|
|
}
|
|
|
|
strings {
|
|
"hi there"
|
|
// Escapes:
|
|
"\0" // The NUL byte: 0.
|
|
"\"" // A double quote character.
|
|
"\\" // A backslash.
|
|
"\a" // Alarm beep. (Who uses this?)
|
|
"\b" // Backspace.
|
|
"\f" // Formfeed.
|
|
"\n" // Newline.
|
|
"\r" // Carriage return.
|
|
"\t" // Tab.
|
|
"\v" // Vertical tab.
|
|
// Unicode code points
|
|
System.print("\u0041fgdg\u0b83\u00DE") // "AஃÞ"
|
|
// Unencoded bytes
|
|
System.print("\x48\x69\x2e") // "Hi."
|
|
}
|
|
|
|
ranges {
|
|
3..8 // inclusive
|
|
4...6 // half-inclusive
|
|
}
|
|
|
|
nothing { null }
|
|
|
|
lists {
|
|
var list = [1, "banana", true]
|
|
list[0] = 5
|
|
list[1..2]
|
|
}
|
|
|
|
maps {
|
|
var stringMap = {
|
|
"George": "Harrison",
|
|
"John": "Lennon",
|
|
"Paul": "McCartney",
|
|
"Ringo": "Starr"
|
|
}
|
|
var a = 1
|
|
var weirdMap = {
|
|
true: 1,
|
|
false: 0,
|
|
null: -1,
|
|
"str": "abc",
|
|
(1..5): 10,
|
|
a: 2,
|
|
_a: 3,
|
|
__a: 4
|
|
}
|
|
}
|
|
}
|