diff --git a/yaml_test.go b/yaml_test.go new file mode 100644 index 0000000..73d3405 --- /dev/null +++ b/yaml_test.go @@ -0,0 +1,41 @@ +package main + +import ( + "testing" + "gopkg.in/yaml.v2" + "fmt" + "os" +) + + var raw_data = ` +a: Easy! +b: + c: 2 + d: [3, 4] +` + +var parsed_data map[interface{}]interface{} + +func TestMain(m *testing.M) { + err := yaml.Unmarshal([]byte(raw_data), &parsed_data) + if err != nil { + fmt.Println("Error parsing yaml: %v", err) + os.Exit(1) + } + + os.Exit(m.Run()) +} + +func TestRead_map_simple(t *testing.T) { + result := read_map(parsed_data, "b", []string{"c"}) + if( result != 2) { + t.Error("Excpted 2 but got ", result) + } +} + +func TestRead_map_array(t *testing.T) { + result := read_map(parsed_data, "b", []string{"d", "1"}) + if( result != 4) { + t.Error("Excpted 4 but got ", result) + } +}