forked from robpike/ivy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_test.go
47 lines (43 loc) · 978 Bytes
/
demo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2014 The Go 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 main_test
import (
"bytes"
"io"
"io/ioutil"
"testing"
"robpike.io/ivy/mobile"
)
/*
To update demo/demo.out:
(echo ')seed 0'; cat demo/demo.ivy) | ivy | sed 1d > demo/demo.out
*/
func TestDemo(t *testing.T) {
data, err := ioutil.ReadFile("demo/demo.ivy")
check := func() {
if err != nil {
t.Fatal(err)
}
}
check()
var buf bytes.Buffer
demo := mobile.NewDemo(string(data))
for {
result, err := demo.Next()
if err == io.EOF {
break
}
if err != nil {
t.Fatalf("demo execution error: %s", err)
}
buf.WriteString(result)
}
result := buf.String()
data, err = ioutil.ReadFile("demo/demo.out")
check()
if string(data) != result {
err = ioutil.WriteFile("demo.bad", buf.Bytes(), 0666)
t.Fatal("test output differs; run\n\tdiff demo.bad demo/demo.out\nfor details")
}
}