// a few odd tests of mcode transpiler for parsing expressions // most tests are in the core file ⎕ 'ok 0' ⍎.de `∇ foo // cmt1 ⍺ ⎕ 'ok 1' ∇ goo // cmt2 ⎕ 'ok 2' // cmt 3 ⎕ 'ok 3' ⎕ ⎕.src 'foo' ` ⎕ 'mexec test' ⍎.de `0 ⊢ 1` ⎕ 'expression builder tests:' 0 ⊢ 1 0 ⊢ 1 ⊢ ⎕ 2 ( 0 ⊢ 1 ) ⎕ 2 ( ⊢ 1 ) ⎕ 2 2 { 'F' } 1 2 { 'F' } ¨ [ 1 ] let‗ x x = { ⊢ ⍵ } x = { ⊢ ⍵ } 2 ⎕ { 0 ⊢ ⍵ } 2 { ⊢ 0 } 1 // cmt ⎕ -1 ⊢ -1 π ⊢.'a' 1 ⎕ 'x' ((_a,_w,_d)=>2)(1,3,null) 1 { 2 } 3 1 { ⎕ ⍵ } 2 1 { ( ⎕ ⍺ ) + ⎕ ⍵ } 2 ⎕ 'y' let‗a={};a.b=1 ⎕ a.b +. 1 ⊢ [ 1 2 ] ∇ ⊙.foo // cmt 1 ⍔ 0 // cmt 2 async‗function‗hoo() // test hybrid function let‗ r=1 ⍔ r hoo() ⊙.M ← [ 1, 0, // cmt1 0, 1 /* cmt2 */ ] ⎕ ⊙.M class‗obj1 // JS OOP test a=1 // fld m1() // method ⍔ ∆.a let‗b = new‗obj1() 'b.m1' ⎕ b.m1() { { 2 } ⊢ 1 } ⊢ 0 // call chain ∇.a ⊙.testTimer1 : p ⎕ 'timer wait' // not sync'd with IDE // p = new‗Promise‗(r=>setTimeout(()=>r(0),1200)) // use await‗ in ∇.a async fn // await‗ p ⎕ 'timer done' // ⊙.testTimer1 0 ∇ ⊙.t mcode.setBusy();setTimeout(()=>mcode.done('waited '+⍵+'ms'),⍵) // data = await‗ mcode.isBusy(); ⊙.t 1000 // testTimerIDE ∇.a ⊙.testErrorAsync // foo // JShint sees error // mcode.foo() // JS eval TypeError // throw‗ 'throw test 1' // handled by _.errorFn try throw‗ 'throw test 2' // handled below catch(e) 'error (local)' ⎕ e ⊙.testErrorAsync 0 // OOP tests ⍂ ⊙.Foo = class a = 'ok' // a is common to all instances ⍢.s x,y,z // x,y,z are initialized per instance ⍢ m // method m ⎕ 'm' ⍔ ⍵ ⊙.f = [ 1 2 3 ] ⍙.n ⊙.Foo // new instance using ⍫ macro ⊙.g = ⍙.n ⊙.Foo ⊙.g.m 1 // call method 'm' on instance 'g' ⎕ ⊙.f // show contents of instance 'f' ⎕ ⊙.g // show contents of instance 'g' // inner and outer product syntax test ⎕ 0 + 1 // built-in + ⎕ 0 +. 1 // vectorized + ⎕ 0 +.× 1 // inner product ⎕ 0 ∘.+ 1 // outer product ⎕ [ 0 1 ] ∘.× [ 2 3 ] ⎕ 'tests done' ⍔ 0 /* test tips: 1) keep tests short, use /// stop pragma as needed 2) use /// stop pragma to stop parsing just after the test; usually at the top of the file 3) focus on one change/fix at a time 4) use debug flag via mexec or locally to enable logging 5) beware of JavaScript quirks like variable shadowing, silent type conversion, etc. 6) see jshintReporter to check output code, it's usually right 7) note that ⍂ addPrim will not affect the current parsing pass - another ⍎ exec is required */