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

Commit a91ced3

Browse files
committed
wast: improve Scanner test
1 parent 4da8942 commit a91ced3

File tree

3 files changed

+55
-27
lines changed

3 files changed

+55
-27
lines changed

wast/doc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// Package wast provides an interface to Wagon for wast files.
5+
// Package wast provides functions to handle wast files.
6+
//
7+
// See https://webassembly.github.io/spec/core/text/
68
package wast

wast/scanner_test.go

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,66 @@
1+
// Copyright 2017 The go-interpreter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package wast
26

37
import (
4-
"flag"
58
"fmt"
69
"testing"
710
)
811

9-
var wastFile = flag.String("wast-file", "", "the wast file to test")
10-
1112
func TestScanner(t *testing.T) {
12-
if *wastFile == "" {
13-
t.Errorf("error: no input file")
14-
}
13+
for _, fname := range []string{
14+
// "../exec/testdata/spec/address.wast",
15+
"../exec/testdata/spec/block.wast",
16+
"../exec/testdata/spec/break-drop.wast",
17+
"../exec/testdata/spec/br_if.wast",
18+
// "../exec/testdata/spec/br_table.wast",
19+
// "../exec/testdata/spec/br.wast",
20+
"../exec/testdata/spec/call_indirect.wast",
21+
// "../exec/testdata/spec/endianness.wast",
22+
"../exec/testdata/spec/fac.wast",
23+
"../exec/testdata/spec/forward.wast",
24+
"../exec/testdata/spec/get_local.wast",
25+
"../exec/testdata/spec/globals.wast",
26+
"../exec/testdata/spec/if.wast",
27+
// "../exec/testdata/spec/loop.wast",
28+
"../exec/testdata/spec/memory_redundancy.wast",
29+
"../exec/testdata/spec/names.wast",
30+
"../exec/testdata/spec/nop.wast",
31+
"../exec/testdata/spec/resizing.wast",
32+
// "../exec/testdata/spec/return.wast",
33+
"../exec/testdata/spec/select.wast",
34+
"../exec/testdata/spec/switch.wast",
35+
"../exec/testdata/spec/tee_local.wast",
36+
"../exec/testdata/spec/traps_int_div.wast",
37+
"../exec/testdata/spec/traps_int_rem.wast",
38+
// "../exec/testdata/spec/traps_mem.wast",
39+
"../exec/testdata/spec/unwind.wast",
40+
} {
41+
t.Run(fname, func(t *testing.T) {
1542

16-
s := NewScanner(*wastFile)
17-
if len(s.Errors) > 0 {
18-
fmt.Println(s.Errors[0])
19-
return
20-
}
43+
s := NewScanner(fname)
44+
if len(s.Errors) > 0 {
45+
fmt.Println(s.Errors[0])
46+
return
47+
}
2148

22-
var tok *Token
23-
tok = s.Next()
24-
for tok.Kind != EOF {
25-
fmt.Printf("%d:%d %s\n", tok.Line, tok.Column, tok.String())
26-
tok = s.Next()
27-
}
28-
fmt.Printf("%d:%d %s\n", tok.Line, tok.Column, tok.String())
49+
var tok *Token
50+
tok = s.Next()
51+
for tok.Kind != EOF {
52+
fmt.Printf("%d:%d %s\n", tok.Line, tok.Column, tok.String())
53+
tok = s.Next()
54+
}
55+
fmt.Printf("%d:%d %s\n", tok.Line, tok.Column, tok.String())
2956

30-
for _, err := range s.Errors {
31-
fmt.Print(err)
32-
}
57+
for _, err := range s.Errors {
58+
fmt.Print(err)
59+
}
3360

34-
if len(s.Errors) > 0 {
35-
t.Errorf("wast: failed with %d errors", len(s.Errors))
61+
if len(s.Errors) > 0 {
62+
t.Errorf("wast: failed with %d errors", len(s.Errors))
63+
}
64+
})
3665
}
3766
}

wast/write.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// Package wast implements a WebAssembly text format.
65
package wast
76

8-
// See https://webassembly.github.io/spec/core/text/
9-
107
import (
118
"bufio"
129
"bytes"

0 commit comments

Comments
 (0)