Skip to content

Commit

Permalink
Test wasm/main.go
Browse files Browse the repository at this point in the history
Remove error checking, since the inputs are hard-coded and the outputs
expected. Then just call `main()` in a test. Basic coverage to ensure it
compiles and runs.

While at it, ignore the `pub` directory created by the playground
branch.
  • Loading branch information
theory committed Nov 5, 2024
1 parent ff53ac1 commit 4fdb132
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ go.work

# Build artifacts
_build/
pub/

# OS Stuff
.DS_Store
Expand Down
13 changes: 4 additions & 9 deletions internal/wasm/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@ package main
import (
"encoding/json"
"fmt"
"log"

"github.com/theory/jsonpath"
)

func main() {
// Parse a jsonpath query.
p, err := jsonpath.Parse(`$.foo`)
if err != nil {
log.Fatal(err)
}
p, _ := jsonpath.Parse(`$.foo`)

// Select values from unmarshaled JSON input.
result := p.Select([]byte(`{"foo": "bar"}`))

// Show the result.
items, err := json.Marshal(result)
if err != nil {
log.Fatal(err)
}
//nolint:errchkjson
items, _ := json.Marshal(result)

//nolint:forbidigo
fmt.Printf("%s\n", items)
}
10 changes: 10 additions & 0 deletions internal/wasm/wasm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"testing"
)

func TestMain(t *testing.T) {
t.Parallel()
main()
}

0 comments on commit 4fdb132

Please sign in to comment.