(t *testing.T)
| 141 | } |
| 142 | |
| 143 | func TestGetField(t *testing.T) { |
| 144 | type S struct { |
| 145 | A int `docstore:"a"` |
| 146 | B any `docstore:"b"` |
| 147 | } |
| 148 | |
| 149 | want := 1 |
| 150 | for _, in := range []any{ |
| 151 | map[string]any{"a": want, "b": nil}, |
| 152 | &S{A: want, B: nil}, |
| 153 | } { |
| 154 | t.Run(fmt.Sprint(in), func(t *testing.T) { |
| 155 | doc, err := NewDocument(in) |
| 156 | if err != nil { |
| 157 | t.Fatal(err) |
| 158 | } |
| 159 | got, err := doc.GetField("a") |
| 160 | if err != nil { |
| 161 | t.Fatal(err) |
| 162 | } |
| 163 | if got != want { |
| 164 | t.Errorf("got %v, want %v", got, want) |
| 165 | } |
| 166 | |
| 167 | got, err = doc.GetField("b") |
| 168 | if err != nil { |
| 169 | t.Fatal(err) |
| 170 | } |
| 171 | if got != nil { |
| 172 | t.Errorf("got %v, want nil", got) |
| 173 | } |
| 174 | |
| 175 | _, err = doc.GetField("c") |
| 176 | if gcerrors.Code(err) != gcerrors.NotFound { |
| 177 | t.Fatalf("got %v, want NotFound", err) |
| 178 | } |
| 179 | }) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | func TestFieldNames(t *testing.T) { |
| 184 | type E struct { |
nothing calls this directly
no test coverage detected