fix tests
This commit is contained in:
parent
cbee75e3c3
commit
d87aa732a4
3 changed files with 36 additions and 10 deletions
|
@ -61,7 +61,3 @@ Hear goes content. It can be written in html, markdown or whatever what can be p
|
|||
* add meta as function, ex. today date
|
||||
* add meta with default value that should be used if other value is not set, ex. license
|
||||
* add search on Tree
|
||||
|
||||
### TODO
|
||||
|
||||
* test to read file content
|
||||
|
|
16
tree.go
16
tree.go
|
@ -67,11 +67,6 @@ func fixFormat(dir string) error {
|
|||
}
|
||||
|
||||
if info.Mode().IsRegular() {
|
||||
b, err := ioutil.ReadFile(path) // just pass the file name
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
osf, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -100,6 +95,11 @@ func fixFormat(dir string) error {
|
|||
err = ioutil.WriteFile(path, []byte(content), 0644)
|
||||
|
||||
// format split line
|
||||
b, err := ioutil.ReadFile(path) // just pass the file name
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
str := string(b)
|
||||
str = strings.Replace(str, "\n---\n", "\n\n---\n", 1)
|
||||
err = ioutil.WriteFile(path, []byte(str), 0644)
|
||||
|
@ -332,6 +332,7 @@ func ReadFileContent(file File) (string, error) {
|
|||
}
|
||||
|
||||
content := ""
|
||||
separator := ""
|
||||
removeEmptyLine := true
|
||||
isMetaPart := true
|
||||
scanner := bufio.NewScanner(osf)
|
||||
|
@ -356,7 +357,10 @@ func ReadFileContent(file File) (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
content = content + "\n" + line
|
||||
content = content + separator + line
|
||||
if separator == "" {
|
||||
separator = "\n"
|
||||
}
|
||||
}
|
||||
_ = osf.Close()
|
||||
|
||||
|
|
26
tree_test.go
26
tree_test.go
|
@ -69,6 +69,7 @@ func TestFixFormat(t *testing.T) {
|
|||
t.Fatal("No destination file 'file1.md'.")
|
||||
}
|
||||
str := string(b)
|
||||
t.Log(str)
|
||||
if !strings.Contains(str, "tags: t1,t2\ndescription: Če test file __va__\n") {
|
||||
t.Fatal("Empty lines has not been removed in file 'file1.md'.")
|
||||
}
|
||||
|
@ -190,3 +191,28 @@ func TestMissingOptions(t *testing.T) {
|
|||
t.Fatal("Changed old value for 'option2' in file 'file3.md'.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadingFileContent(t *testing.T) {
|
||||
err := os.Remove("./testdata/sunny1")
|
||||
if err != nil {
|
||||
}
|
||||
err = cp.Copy("./testdata/sunny", "./testdata/sunny1")
|
||||
if err != nil {
|
||||
t.Fatal("Couldn't prepare data for testing")
|
||||
}
|
||||
|
||||
tree, err := BuildTree("./testdata/sunny1", []string{})
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Got error: %v", err)
|
||||
}
|
||||
|
||||
if tree.Files[0].Name != "file1.md" {
|
||||
t.Errorf("File should be 'file1.md', got %v", tree.Files[0].Name)
|
||||
}
|
||||
|
||||
content, _ := ReadFileContent(tree.Files[0])
|
||||
if content != "# Če kažkas torietom būtė\n\n* lists\n\n__va__" {
|
||||
t.Error("File content is wrong...")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue