file/file_test.go

30 lines
540 B
Go
Raw Permalink Normal View History

2024-10-11 12:02:48 +08:00
package file_test
import (
"fmt"
"os"
"testing"
"apigo.cc/gojs"
_ "apigo.cc/gojs/file"
"github.com/ssgo/u"
)
func TestHash(t *testing.T) {
defer os.Remove("test.txt")
defer os.Remove("test2.txt")
r, err := gojs.Run(`
import file from 'apigo.cc/gojs/file'
file.write('test.txt', 'hello world')
file.rename('test.txt', 'test2.txt')
return file.read('test2.txt')
`, "")
if err != nil {
t.Fatal(err)
} else if r != "hello world" {
t.Fatal("read file error", r)
} else {
fmt.Println(u.BGreen("test succeess"))
}
}