generated from tpl/purs
moar
This commit is contained in:
@@ -4,10 +4,12 @@ import Prelude
|
||||
|
||||
import Effect (Effect)
|
||||
import Test.Mujoco.XML.Node.Prop as Test.Mujoco.XML.Node.Prop
|
||||
import Test.Mujoco.MJCF as Test.Mujoco.MJCF
|
||||
import Test.Spec.Reporter.Console (consoleReporter)
|
||||
import Test.Spec.Runner.Node (runSpecAndExitProcess)
|
||||
|
||||
main :: Effect Unit
|
||||
main =
|
||||
runSpecAndExitProcess [consoleReporter] do
|
||||
Test.Mujoco.MJCF.spec
|
||||
Test.Mujoco.XML.Node.Prop.spec
|
||||
|
||||
26
test/Mujoco.MJCF.purs
Normal file
26
test/Mujoco.MJCF.purs
Normal file
@@ -0,0 +1,26 @@
|
||||
module Test.Mujoco.MJCF where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Error.Class (try)
|
||||
import Data.Either (isLeft)
|
||||
import Effect.Aff (Aff)
|
||||
import Effect.Class (liftEffect)
|
||||
import Mujoco.MJCF as X
|
||||
import Mujoco.Wasm (renderSpec)
|
||||
import Mujoco.XML.Node (Node)
|
||||
import Test.Assert (assertTrue)
|
||||
import Test.Spec (Spec, describe, it)
|
||||
|
||||
ok :: Node -> Aff Unit
|
||||
ok = void <<< renderSpec
|
||||
|
||||
fail :: Node -> Aff Unit
|
||||
fail = (liftEffect <<< assertTrue <<< isLeft) <=< (try <<< renderSpec)
|
||||
|
||||
spec :: Spec Unit
|
||||
spec =
|
||||
describe "MJCF" do
|
||||
it "</>" $ fail $ X.empty
|
||||
it "<mujoco>" $ ok $ X.mujoco {} unit
|
||||
it "<worldbody>" $ ok $ X.mujoco {} $ X.worldbody {} unit
|
||||
10
test/Mujoco.Wasm.js
Normal file
10
test/Mujoco.Wasm.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import load_mujoco from 'mujoco_wasm/mujoco_wasm.js'
|
||||
|
||||
/** @typedef {import('mujoco_wasm').MainModule} Mujoco */
|
||||
/** @typedef {import('mujoco_wasm').MjSpec} Spec */
|
||||
|
||||
/** @type {() => Promise<Mujoco>} */
|
||||
export const loadMujoco = () => load_mujoco()
|
||||
|
||||
/** @type {(mj: Mujoco) => (xml: String) => () => Spec} */
|
||||
export const parseXMLString = m => xml => () => m.parseXMLString(xml)
|
||||
21
test/Mujoco.Wasm.purs
Normal file
21
test/Mujoco.Wasm.purs
Normal file
@@ -0,0 +1,21 @@
|
||||
module Mujoco.Wasm where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Promise (Promise)
|
||||
import Control.Promise as Promise
|
||||
import Effect (Effect)
|
||||
import Effect.Aff (Aff)
|
||||
import Effect.Class (liftEffect)
|
||||
import Mujoco.XML.Node as XML
|
||||
|
||||
foreign import data Mujoco :: Type
|
||||
foreign import data Spec :: Type
|
||||
|
||||
foreign import loadMujoco :: Effect (Promise Mujoco)
|
||||
foreign import parseXMLString :: Mujoco -> String -> Effect Spec
|
||||
|
||||
renderSpec :: XML.Node -> Aff Spec
|
||||
renderSpec node = do
|
||||
mj <- Promise.toAffE loadMujoco
|
||||
liftEffect $ parseXMLString mj $ XML.render node
|
||||
Reference in New Issue
Block a user