1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package main
20
21 import (
22 "bytes"
23 "fmt"
24 "strconv"
25 "strings"
26 )
27
28 const ntest = 1024
29
30 func main() {
31 var decls, calls bytes.Buffer
32
33 for i := 1; i <= ntest; i++ {
34 s := strconv.Itoa(i)
35 decls.WriteString(strings.Replace(decl, "$", s, -1))
36 calls.WriteString(strings.Replace("call(test$)\n\t", "$", s, -1))
37 }
38
39 program = strings.Replace(program, "$DECLS", decls.String(), 1)
40 program = strings.Replace(program, "$CALLS", calls.String(), 1)
41 fmt.Print(program)
42 }
43
44 var program = `package main
45
46 var count int
47
48 func call(f func() bool) {
49 if f() {
50 count++
51 }
52 }
53
54 $DECLS
55
56 func main() {
57 $CALLS
58 if count != 0 {
59 println("failed", count, "case(s)")
60 }
61 }
62 `
63
64 const decl = `
65 type T$ [$]uint8
66 func test$() bool {
67 v := T${1}
68 return v == [$]uint8{2} || v != [$]uint8{1}
69 }`
70
View as plain text