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 as function, ex. today date
|
||||||
* add meta with default value that should be used if other value is not set, ex. license
|
* add meta with default value that should be used if other value is not set, ex. license
|
||||||
* add search on Tree
|
* 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() {
|
if info.Mode().IsRegular() {
|
||||||
b, err := ioutil.ReadFile(path) // just pass the file name
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
osf, err := os.Open(path)
|
osf, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -100,6 +95,11 @@ func fixFormat(dir string) error {
|
||||||
err = ioutil.WriteFile(path, []byte(content), 0644)
|
err = ioutil.WriteFile(path, []byte(content), 0644)
|
||||||
|
|
||||||
// format split line
|
// format split line
|
||||||
|
b, err := ioutil.ReadFile(path) // just pass the file name
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
str := string(b)
|
str := string(b)
|
||||||
str = strings.Replace(str, "\n---\n", "\n\n---\n", 1)
|
str = strings.Replace(str, "\n---\n", "\n\n---\n", 1)
|
||||||
err = ioutil.WriteFile(path, []byte(str), 0644)
|
err = ioutil.WriteFile(path, []byte(str), 0644)
|
||||||
|
@ -332,6 +332,7 @@ func ReadFileContent(file File) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
content := ""
|
content := ""
|
||||||
|
separator := ""
|
||||||
removeEmptyLine := true
|
removeEmptyLine := true
|
||||||
isMetaPart := true
|
isMetaPart := true
|
||||||
scanner := bufio.NewScanner(osf)
|
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()
|
_ = 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'.")
|
t.Fatal("No destination file 'file1.md'.")
|
||||||
}
|
}
|
||||||
str := string(b)
|
str := string(b)
|
||||||
|
t.Log(str)
|
||||||
if !strings.Contains(str, "tags: t1,t2\ndescription: Če test file __va__\n") {
|
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'.")
|
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'.")
|
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