Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Commit

Permalink
wast: improve Scanner test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Feb 27, 2020
1 parent 87ec291 commit b91d2df
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 27 deletions.
4 changes: 3 additions & 1 deletion wast/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package wast provides an interface to Wagon for wast files.
// Package wast provides functions to handle wast files.
//
// See https://webassembly.github.io/spec/core/text/
package wast
75 changes: 52 additions & 23 deletions wast/scanner_test.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,66 @@
// Copyright 2017 The go-interpreter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package wast

import (
"flag"
"fmt"
"testing"
)

var wastFile = flag.String("wast-file", "", "the wast file to test")

func TestScanner(t *testing.T) {
if *wastFile == "" {
t.Errorf("error: no input file")
}
for _, fname := range []string{
// "../exec/testdata/spec/address.wast",
"../exec/testdata/spec/block.wast",
"../exec/testdata/spec/break-drop.wast",
"../exec/testdata/spec/br_if.wast",
// "../exec/testdata/spec/br_table.wast",
// "../exec/testdata/spec/br.wast",
"../exec/testdata/spec/call_indirect.wast",
// "../exec/testdata/spec/endianness.wast",
"../exec/testdata/spec/fac.wast",
"../exec/testdata/spec/forward.wast",
"../exec/testdata/spec/get_local.wast",
"../exec/testdata/spec/globals.wast",
"../exec/testdata/spec/if.wast",
// "../exec/testdata/spec/loop.wast",
"../exec/testdata/spec/memory_redundancy.wast",
"../exec/testdata/spec/names.wast",
"../exec/testdata/spec/nop.wast",
"../exec/testdata/spec/resizing.wast",
// "../exec/testdata/spec/return.wast",
"../exec/testdata/spec/select.wast",
"../exec/testdata/spec/switch.wast",
"../exec/testdata/spec/tee_local.wast",
"../exec/testdata/spec/traps_int_div.wast",
"../exec/testdata/spec/traps_int_rem.wast",
// "../exec/testdata/spec/traps_mem.wast",
"../exec/testdata/spec/unwind.wast",
} {
t.Run(fname, func(t *testing.T) {

s := NewScanner(*wastFile)
if len(s.Errors) > 0 {
fmt.Println(s.Errors[0])
return
}
s := NewScanner(fname)
if len(s.Errors) > 0 {
fmt.Println(s.Errors[0])
return
}

var tok *Token
tok = s.Next()
for tok.Kind != EOF {
fmt.Printf("%d:%d %s\n", tok.Line, tok.Column, tok.String())
tok = s.Next()
}
fmt.Printf("%d:%d %s\n", tok.Line, tok.Column, tok.String())
var tok *Token
tok = s.Next()
for tok.Kind != EOF {
fmt.Printf("%d:%d %s\n", tok.Line, tok.Column, tok.String())
tok = s.Next()
}
fmt.Printf("%d:%d %s\n", tok.Line, tok.Column, tok.String())

for _, err := range s.Errors {
fmt.Print(err)
}
for _, err := range s.Errors {
fmt.Print(err)
}

if len(s.Errors) > 0 {
t.Errorf("wast: failed with %d errors", len(s.Errors))
if len(s.Errors) > 0 {
t.Errorf("wast: failed with %d errors", len(s.Errors))
}
})
}
}
3 changes: 0 additions & 3 deletions wast/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package wast implements a WebAssembly text format.
package wast

// See https://webassembly.github.io/spec/core/text/

import (
"bufio"
"bytes"
Expand Down

0 comments on commit b91d2df

Please sign in to comment.