(t *testing.T)
| 168 | } |
| 169 | |
| 170 | func TestPathValue(t *testing.T) { |
| 171 | doc := ` |
| 172 | title: "Moby Dick" |
| 173 | chapter: |
| 174 | one: |
| 175 | title: "Loomings" |
| 176 | two: |
| 177 | title: "The Carpet-Bag" |
| 178 | three: |
| 179 | title: "The Spouter Inn" |
| 180 | ` |
| 181 | d, err := ReadValues([]byte(doc)) |
| 182 | if err != nil { |
| 183 | t.Fatalf("Failed to parse the White Whale: %s", err) |
| 184 | } |
| 185 | |
| 186 | if v, err := d.PathValue("chapter.one.title"); err != nil { |
| 187 | t.Errorf("Got error instead of title: %s\n%v", err, d) |
| 188 | } else if v != "Loomings" { |
| 189 | t.Errorf("No error but got wrong value for title: %s\n%v", err, d) |
| 190 | } |
| 191 | if _, err := d.PathValue("chapter.one.doesnotexist"); err == nil { |
| 192 | t.Errorf("Non-existent key should return error: %s\n%v", err, d) |
| 193 | } |
| 194 | if _, err := d.PathValue("chapter.doesnotexist.one"); err == nil { |
| 195 | t.Errorf("Non-existent key in middle of path should return error: %s\n%v", err, d) |
| 196 | } |
| 197 | if _, err := d.PathValue(""); err == nil { |
| 198 | t.Error("Asking for the value from an empty path should yield an error") |
| 199 | } |
| 200 | if v, err := d.PathValue("title"); err == nil { |
| 201 | if v != "Moby Dick" { |
| 202 | t.Error("Failed to return values for root key title") |
| 203 | } |
| 204 | } |
| 205 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…