1// Test file for Pony syntax highlighting, released under MIT License 2 3primitive Red fun apply(): U32 => 0xFFFF0000 4 5primitive Colours 6 fun black(): U32 => 0xFF000000 7 fun red(): U32 => 0xFFFF0000 8 9primitive Black 10primitive Blue 11 12type Colour is (Black | Blue ) 13 14primitive ColourList 15 fun tag apply(): Array[Colour] => 16 [Black; Blue] 17 18for colour in ColourList().values() do 19end 20 21type EGLEvent is (U8, F32, F32) 22(var code, var x, var y) = @getEvent[EGLEvent]() 23 24primitive _XDisplayHandle 25primitive _EGLDisplayHandle 26 27let x_dpy = @XOpenDisplay[Pointer[_XDisplayHandle]](U32(0)) 28if x_dpy.is_null() then 29 env.out.print("XOpenDisplay failed") 30end 31 32let e_dpy = @eglGetDisplay[Pointer[_EGLDisplayHandle]](x_dpy) 33if e_dpy.is_null() then 34 env.out.print("eglGetDisplay failed") 35end 36 37primitive _EGLConfigHandle 38let a = Array[U16](8) 39a.push(0x3040) 40a.push(0b01011) 41let config = Pointer[_EGLConfigHandle] 42if @eglChooseConfig[U32](e_dpy, a, config, U32(1), Pointer[U32]) == 0 then 43 env.out.print("eglChooseConfig failed") 44end 45 46 47actor Main 48 new create(env: Env) => 49 // The no of arguments 50 env.out.print(env.args.size().string()) 51 for value in env.args.values() do 52 env.out.print(value) 53 end 54 // Access the arguments the first one will always be the the appication name 55 try env.out.print(env.args(0)?) end 56 57actor Main 58 new create(env: Env) => 59 var options = Options(env) 60 61 options 62 .add("output", "o", StringArgument) 63 64 env.out.print(options.has_argument()) 65 66 for option in options do 67 match option 68 | ("output", var arg: String) => _outputFileName = arg.string() 69 | let err: ParseError => 70 err.report(env.out) 71 env.out.print( 72 """ 73 pony-embed [OPTIONS] 74 --output name string output filename. 75 """ 76 ) 77 end 78 end 79 80use "ponytest" 81 82actor Main is TestList 83 new create(env: Env) => PonyTest(env, this) 84 new make() => None 85 86 fun tag tests(test: PonyTest) => 87 test(_TestAddition) 88 89class iso _TestAddition is UnitTest 90 """ 91 Adding 2 numbers 92 """ 93 fun name(): String => "u32/add" 94 95 fun apply(h: TestHelper): TestResult => 96 h.expect_eq[U32](2 + 2, 4) 97 98fun tag log(msg: String, verbose: Bool = false) 99be fail() => 100be assert_failed(msg: String) => 101fun tag assert_true(actual: Bool, msg: String = "") ? 102fun tag expect_true(actual: Bool, msg: String = ""): Bool 103fun tag expect_eq[A: (Equatable[A] #read & Stringable)] 104 (expect: A, actual: A, msg: String = ""): Bool 105fun tag expect_eq[A: (Equatable[A] #unknown & Stringable)] 106 (expect: A, actual: A, msg: String = ""): Bool 107 108fun add(other: A): A 109fun sub(other: A): A 110fun mul(other: A): A 111fun div(other: A): A 112fun mod(other: A): A 113fun eq(other: A): Bool 114fun ne(other: A): Bool 115fun lt(other: A): Bool 116fun le(other: A): Bool 117fun ge(other: A): Bool 118fun gt(other: A): Bool 119fun shl(other: A): A 120fun shr(other: A): A 121fun op_and(other:A): A 122fun op_or(other: A): A 123fun op_xor(othr: A): A 124 125class Test 126 fun alpha() => 127 """ 128 """ 129 130let dice: Array[U32] = [1; 2; 3 131 4 132 5 133 6 134] 135 136actor Main 137 fun foo(n:U32): {ref(U32): U32} => 138 var s: Array[U32] = Array[U32].init(n, 1) 139 {ref(i:U32)(s): U32 => 140 try 141 s(0) = s(0) + i 142 s(0) 143 else 144 0 145 end 146 } 147 148 new create(env:Env) => 149 var f = foo(5) 150 env.out.print(f(10).string()) 151 env.out.print(f(20).string()) 152 153/* nested /* commentary */ */ 154// single comment 155 156class A 157class _A 158x' 159x'' 160x'.string() 161'\uaaaa' 162'\Ubbbbbb' 163'\xcc' 164'\'' 165'\n' 166"\uaaaaa" 167"\Ubbbbbbb" 168"\xccc" 169"\"" 170"\n" 17134.4 17234.4e43 17343e4 1740x3040 1750xaF 1760b01 1773_43_4 1780x0_4 179 180fun create(): U32 => 0 181fun iso create(): U32 => 0 182fun \\ abc \\ iso create(): U32 => 0 183class \\ packet, blah \\ iso Xyz 184if \\ likely \\ a then 185end 186 187a.endnormal 188 189print();print() 190 191/* syntactically false: */ 192 193class _aA 194class _a 195class a 1960b2332 1970b 1980x 1990xgf 2000f00 2013. 202.3 2033.e3 2043_ 2053__43_4 206'' 207'\u' 208'\ua' 209'\uaaa' 210'\uaaaaa' 211'\uyyyy' 212"\u" 213"\ua" 214"\uaaa" 215"\uyyyy" 216a'a 217 218class badType 219print(); 220