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