(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func TestLocate(t *testing.T) { |
| 42 | var buf bytes.Buffer |
| 43 | en := NewWriter(&buf) |
| 44 | en.WriteMapHeader(2) |
| 45 | en.WriteString("thing_one") |
| 46 | en.WriteString("value_one") |
| 47 | en.WriteString("thing_two") |
| 48 | en.WriteFloat64(2.0) |
| 49 | en.Flush() |
| 50 | |
| 51 | field := Locate("thing_one", buf.Bytes()) |
| 52 | if len(field) == 0 { |
| 53 | t.Fatal("field not found") |
| 54 | } |
| 55 | |
| 56 | if !HasKey("thing_one", buf.Bytes()) { |
| 57 | t.Fatal("field not found") |
| 58 | } |
| 59 | |
| 60 | var zbuf bytes.Buffer |
| 61 | w := NewWriter(&zbuf) |
| 62 | w.WriteString("value_one") |
| 63 | w.Flush() |
| 64 | |
| 65 | if !bytes.Equal(zbuf.Bytes(), field) { |
| 66 | t.Errorf("got %q; wanted %q", field, zbuf.Bytes()) |
| 67 | } |
| 68 | |
| 69 | zbuf.Reset() |
| 70 | w.WriteFloat64(2.0) |
| 71 | w.Flush() |
| 72 | field = Locate("thing_two", buf.Bytes()) |
| 73 | if len(field) == 0 { |
| 74 | t.Fatal("field not found") |
| 75 | } |
| 76 | if !bytes.Equal(zbuf.Bytes(), field) { |
| 77 | t.Errorf("got %q; wanted %q", field, zbuf.Bytes()) |
| 78 | } |
| 79 | |
| 80 | field = Locate("nope", buf.Bytes()) |
| 81 | if len(field) != 0 { |
| 82 | t.Fatalf("wanted a zero-length returned slice") |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func TestReplace(t *testing.T) { |
| 87 | // there are 4 cases that need coverage: |
nothing calls this directly
no test coverage detected
searching dependent graphs…