more updates and renaming
Former-commit-id: 8c194821906b2170df92672fe9dfb9d710640659
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/hacdias/filemanager/utils"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@@ -169,9 +168,9 @@ func rawToPretty(config interface{}, parent *Block) *Content {
|
||||
}
|
||||
|
||||
for name, element := range cnf {
|
||||
if utils.IsMap(element) {
|
||||
if isMap(element) {
|
||||
objects = append(objects, handleObjects(element, parent, name))
|
||||
} else if utils.IsSlice(element) {
|
||||
} else if isSlice(element) {
|
||||
arrays = append(arrays, handleArrays(element, parent, name))
|
||||
} else {
|
||||
if name == "title" && parent.Name == mainName {
|
||||
|
||||
13
frontmatter/types.go
Normal file
13
frontmatter/types.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package frontmatter
|
||||
|
||||
import "reflect"
|
||||
|
||||
// isMap checks if some variable is a map
|
||||
func isMap(sth interface{}) bool {
|
||||
return reflect.ValueOf(sth).Kind() == reflect.Map
|
||||
}
|
||||
|
||||
// isSlice checks if some variable is a slice
|
||||
func isSlice(sth interface{}) bool {
|
||||
return reflect.ValueOf(sth).Kind() == reflect.Slice
|
||||
}
|
||||
49
frontmatter/types_test.go
Normal file
49
frontmatter/types_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package frontmatter
|
||||
|
||||
import "testing"
|
||||
|
||||
type interfaceToBool struct {
|
||||
Value interface{}
|
||||
Result bool
|
||||
}
|
||||
|
||||
var testIsMap = []*interfaceToBool{
|
||||
&interfaceToBool{"teste", false},
|
||||
&interfaceToBool{453478, false},
|
||||
&interfaceToBool{-984512, false},
|
||||
&interfaceToBool{true, false},
|
||||
&interfaceToBool{map[string]bool{}, true},
|
||||
&interfaceToBool{map[int]bool{}, true},
|
||||
&interfaceToBool{map[interface{}]bool{}, true},
|
||||
&interfaceToBool{[]string{}, false},
|
||||
}
|
||||
|
||||
func TestIsMap(t *testing.T) {
|
||||
for _, test := range testIsMap {
|
||||
if isMap(test.Value) != test.Result {
|
||||
t.Errorf("Incorrect value on IsMap for %v; want: %v; got: %v", test.Value, test.Result, !test.Result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testIsSlice = []*interfaceToBool{
|
||||
&interfaceToBool{"teste", false},
|
||||
&interfaceToBool{453478, false},
|
||||
&interfaceToBool{-984512, false},
|
||||
&interfaceToBool{true, false},
|
||||
&interfaceToBool{map[string]bool{}, false},
|
||||
&interfaceToBool{map[int]bool{}, false},
|
||||
&interfaceToBool{map[interface{}]bool{}, false},
|
||||
&interfaceToBool{[]string{}, true},
|
||||
&interfaceToBool{[]int{}, true},
|
||||
&interfaceToBool{[]bool{}, true},
|
||||
&interfaceToBool{[]interface{}{}, true},
|
||||
}
|
||||
|
||||
func TestIsSlice(t *testing.T) {
|
||||
for _, test := range testIsSlice {
|
||||
if isSlice(test.Value) != test.Result {
|
||||
t.Errorf("Incorrect value on IsSlice for %v; want: %v; got: %v", test.Value, test.Result, !test.Result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user