From 40fba1b3bc9da00d6483d15399a7ceba0f3ddace Mon Sep 17 00:00:00 2001 From: Morgan Kenyon Date: Sat, 8 Mar 2025 11:37:44 -0600 Subject: [PATCH] Adding some more examples and tests --- examples/addition.fs | 4 +--- examples/additionVars.fs | 6 ++++++ examples/multipleAdditions.fs | 4 ++++ examples/subtraction.fs | 4 ++++ test/AstToWasmTests.fs | 36 +++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 examples/additionVars.fs create mode 100644 examples/multipleAdditions.fs create mode 100644 examples/subtraction.fs diff --git a/examples/addition.fs b/examples/addition.fs index b3fbd99..8f31b4d 100644 --- a/examples/addition.fs +++ b/examples/addition.fs @@ -1,6 +1,4 @@ module Test let main () = - let first = 23 - let second = 89 - first + second + 9 + 11 diff --git a/examples/additionVars.fs b/examples/additionVars.fs new file mode 100644 index 0000000..b3fbd99 --- /dev/null +++ b/examples/additionVars.fs @@ -0,0 +1,6 @@ +module Test + +let main () = + let first = 23 + let second = 89 + first + second diff --git a/examples/multipleAdditions.fs b/examples/multipleAdditions.fs new file mode 100644 index 0000000..d2a1875 --- /dev/null +++ b/examples/multipleAdditions.fs @@ -0,0 +1,4 @@ +module Test + +let main () = + 9 + 11 + 4 + 6 diff --git a/examples/subtraction.fs b/examples/subtraction.fs new file mode 100644 index 0000000..4b83c05 --- /dev/null +++ b/examples/subtraction.fs @@ -0,0 +1,4 @@ +module Test + +let main () = + 10 - 5 diff --git a/test/AstToWasmTests.fs b/test/AstToWasmTests.fs index 4eb47be..3ab8115 100644 --- a/test/AstToWasmTests.fs +++ b/test/AstToWasmTests.fs @@ -18,6 +18,42 @@ let getModuleSymbols (moduleSymbols: ModuleSymbolList) = +[] +let ``Can run simple main function`` () = + let input = + $""" +module Test + +let main () = 23 +""" + + let declarations = getDeclarations checker input + let wasmBytes = astToWasm declarations + + //printWasm wasmBytes + + let response = wasmBytes |> runFuncInt32Return "main" + response.Should().Be(23) + +[] +let ``Can compile multiple functions`` () = + let input = + $""" +module Test + +let second () = 24 +let third () = 24 +let main () = 23 +""" + + let declarations = getDeclarations checker input + let wasmBytes = astToWasm declarations + + //printWasm wasmBytes + + let response = wasmBytes |> runFuncInt32Return "main" + response.Should().Be(23) + [] [] []