-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile_test.go
53 lines (42 loc) · 1.15 KB
/
file_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
48
49
50
51
52
53
package main
import (
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/test"
)
func TestLoad(t *testing.T) {
w := test.NewWindow(nil)
edit := &textEdit{window: w, changed: binding.NewBool()}
ui := edit.makeUI()
w.SetContent(ui)
r, err := storage.Reader(storage.NewFileURI("./testdata/test.txt"))
assert.Nil(t, err)
err = edit.load(r)
assert.Nil(t, err)
assert.Equal(t, "Test content", edit.entry.Text)
}
func TestSave(t *testing.T) {
w := test.NewWindow(nil)
edit := &textEdit{window: w, changed: binding.NewBool()}
ui := edit.makeUI()
w.SetContent(ui)
out, err := storage.Writer(storage.NewFileURI("./testdata/test2.txt"))
assert.Nil(t, err)
defer os.Remove("./testdata/test2.txt")
edit.entry.SetText("Testing")
err = edit.saveAs(out)
assert.Nil(t, err)
out.Close()
data, err := ioutil.ReadFile("./testdata/test2.txt")
assert.Nil(t, err)
assert.Equal(t, "Testing", string(data))
edit.entry.SetText("Testing2")
edit.save()
data, err = ioutil.ReadFile("./testdata/test2.txt")
assert.Nil(t, err)
assert.Equal(t, "Testing2", string(data))
}