Skip to content

Commit

Permalink
Added test for wat to wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
perimeko committed Jun 11, 2020
1 parent 18b9c6c commit faa4265
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
41 changes: 41 additions & 0 deletions go-owasm/api/lib_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package api

import (
"fmt"
"io/ioutil"
"testing"

"github.com/stretchr/testify/require"
)

func readWatFile(fileName string) []byte {
code, err := ioutil.ReadFile(fmt.Sprintf("./../wasm/%s.wat", fileName))
if err != nil {
panic(err)
}
return code
}

func readWasmFile(fileName string) []byte {
code, err := ioutil.ReadFile(fmt.Sprintf("./../wasm/%s.wasm", fileName))
if err != nil {
panic(err)
}
return code
}

func TestSuccessWatToOwasm(t *testing.T) {
code := readWatFile("test")
wasm, err := WatToWasm(code)
require.NoError(t, err)

expectedWasm := readWasmFile("test")
require.Equal(t, expectedWasm, wasm)
}

func TestFailInvalidWatContent(t *testing.T) {
code := []byte("invalid wat content")
wasm, err := WatToWasm(code)
require.Equal(t, ErrParseFail, err)
require.Equal(t, []byte(""), wasm)
}
Binary file added go-owasm/wasm/test.wasm
Binary file not shown.
26 changes: 26 additions & 0 deletions go-owasm/wasm/test.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(module
(type $t0 (func))
(type $t1 (func (param i64 i64 i64 i64)))
(import "env" "ask_external_data" (func $ask_external_data (type $t1)))
(func $prepare (export "prepare") (type $t0)
(local $l0 i64)
i64.const 1
i64.const 1
i32.const 1024
i64.extend_u/i32
tee_local $l0
i64.const 10
call $ask_external_data
i64.const 2
i64.const 3
get_local $l0
i64.const 10
call $ask_external_data
i64.const 4
i64.const 5
get_local $l0
i64.const 10
call $ask_external_data)
(table $T0 1 1 anyfunc)
(memory $memory (export "memory") 17)
(data (i32.const 1024) "helloworld"))

0 comments on commit faa4265

Please sign in to comment.