package clipboard_test import ( "git.noahlan.cn/noahlan/ntool/nfs" "git.noahlan.cn/noahlan/ntool/nstr" "git.noahlan.cn/noahlan/ntool/nsys/clipboard" "git.noahlan.cn/noahlan/ntool/ntest/assert" "testing" ) func TestClipboard_WriteFromFile(t *testing.T) { cb := clipboard.New() if ok := cb.Available(); !ok { assert.False(t, ok) t.Skipf("skip test on program '%s' not found", clipboard.GetReaderBin()) return } srcFile := "testdata/testcb.txt" srcStr := string(nfs.MustReadFile(srcFile)) assert.NotEmpty(t, srcStr) err := cb.WriteFromFile(srcFile) assert.NoErr(t, err) err = cb.WriteFromFile("path/to/not-exists.txt") assert.Err(t, err) readStr, err := cb.ReadString() assert.NoErr(t, err) assert.Eq(t, srcStr, nstr.Trim(readStr)) dstFile := "testdata/read-from-cb.txt" assert.NoErr(t, nfs.RmFileIfExist(dstFile)) err = cb.ReadToFile(dstFile) assert.NoErr(t, err) dstStr := string(nfs.MustReadFile(dstFile)) assert.Eq(t, srcStr, nstr.Trim(dstStr)) }