mirror of
https://github.com/mikefarah/yq.git
synced 2025-03-15 16:37:46 +00:00
gofmt'ed
This commit is contained in:
parent
ccd95146fe
commit
9869a41122
15
yaml.go
15
yaml.go
@ -2,13 +2,13 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"log"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"strings"
|
"gopkg.in/yaml.v2"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -64,7 +64,7 @@ func read_file(filename string) []byte {
|
|||||||
|
|
||||||
func read_map(context map[interface{}]interface{}, head string, tail []string) interface{} {
|
func read_map(context map[interface{}]interface{}, head string, tail []string) interface{} {
|
||||||
value := context[head]
|
value := context[head]
|
||||||
if (len(tail) > 0) {
|
if len(tail) > 0 {
|
||||||
return recurse(value, tail[0], tail[1:len(tail)])
|
return recurse(value, tail[0], tail[1:len(tail)])
|
||||||
} else {
|
} else {
|
||||||
return value
|
return value
|
||||||
@ -86,10 +86,9 @@ func recurse(value interface{}, head string, tail []string) interface{} {
|
|||||||
|
|
||||||
func read_array(array []interface{}, head int64, tail []string) interface{} {
|
func read_array(array []interface{}, head int64, tail []string) interface{} {
|
||||||
value := array[head]
|
value := array[head]
|
||||||
if (len(tail) > 0) {
|
if len(tail) > 0 {
|
||||||
return recurse(value, tail[0], tail[1:len(tail)])
|
return recurse(value, tail[0], tail[1:len(tail)])
|
||||||
} else {
|
} else {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
"os"
|
"os"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var raw_data = `
|
var raw_data = `
|
||||||
@ -28,14 +28,14 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
func TestRead_map_simple(t *testing.T) {
|
func TestRead_map_simple(t *testing.T) {
|
||||||
result := read_map(parsed_data, "b", []string{"c"})
|
result := read_map(parsed_data, "b", []string{"c"})
|
||||||
if( result != 2) {
|
if result != 2 {
|
||||||
t.Error("Excpted 2 but got ", result)
|
t.Error("Excpted 2 but got ", result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRead_map_array(t *testing.T) {
|
func TestRead_map_array(t *testing.T) {
|
||||||
result := read_map(parsed_data, "b", []string{"d", "1"})
|
result := read_map(parsed_data, "b", []string{"d", "1"})
|
||||||
if( result != 4) {
|
if result != 4 {
|
||||||
t.Error("Excpted 4 but got ", result)
|
t.Error("Excpted 4 but got ", result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user