package xlib import ( "testing" ) //CodePageDetect func TestCodePageDetect(t *testing.T) { res, err := CodePageDetect("test.txt", "~X~") if err != nil { t.Errorf(" on file '%s' return error: %v", "test.txt", err) } if res != Cp866 { t.Errorf(" on file '%s' expected 866 got: %s", "test.txt", CodePageAsString(res)) } res, err = CodePageDetect("test.txt") if res != CpWindows1251 { t.Errorf(" on file '%s' expected 1251 got: %s", "test.txt", CodePageAsString(res)) } _, err = CodePageDetect("-.-") if err == nil { t.Errorf(" on file '-.-' must return error, but return nil") } res, _ = CodePageDetect("test2.txt") if res != CpEmpty { t.Errorf(" on file 'test2.txt' expect CpEmpty got: %s", CodePageAsString(res)) } res, err = CodePageDetect("test3.txt") if (res != CpEmpty) || (err != nil) { t.Errorf(" on file 'test3.txt' expect CpEmpty and no error got: %s and %v", CodePageAsString(res), err) } } //SeekFileToString func TestSeekFileToString(t *testing.T) { _, _, err := SeekFileToString("-.-", "-") if err == nil { t.Errorf(" on file '-.-' must return error, but return nil") } index, scanner, err := SeekFileToString("test.txt", "~A") if scanner == nil { t.Errorf(" on file 'test.txt' return scanner == nil") } scanner.Scan() if scanner.Text() != "" { t.Errorf(" on line: %d must be string ''\n", index) } index, scanner, err = SeekFileToString("test.txt", "") if index >= 0 { t.Errorf(" on empty seek str == '' must return index < 0 [-1], return: %d", index) } index, scanner, err = SeekFileToString("test3.txt", "~") if index >= 0 { t.Errorf(" on file 'test3.txt' and seek str == '~' must return index < 0 [-1], return: %d", index) } } //ReplaceCpFile func TestReplaceCpFile(t *testing.T) { err := ReplaceCpFile("", 0, 1) if err == nil { t.Errorf(" on empty file name expected error, got: %v", err) } err = ReplaceCpFile("", 0, 0) if err != nil { t.Errorf(" on fromCp == toCp expected error, got: %v", err) } } //FileExists func TestFileExists(t *testing.T) { if FileExists("-.-") { t.Errorf(" return true on non exist file '-.-'") } if !FileExists("test.txt") || !FileExists("test2.txt") || !FileExists("test3.txt") { t.Error(" return false on exist files: test.txt, test2.txt, test3.txt") } } //FindFilesExt func TestFindFilesExt(t *testing.T) { //fl := make([]string, 0, 10) //fl := nil _, err := FindFilesExt(nil, ".", "txt") if err == nil { t.Errorf(" on nil input fileList nust return err, return: %v", err) } fl := make([]string, 0, 10) n, err := FindFilesExt(&fl, ".", ".txt") if n != 3 { t.Errorf(" on current folder must found 3 '.txt', return: %d", n) } }