4bbfa6d6ab
When using the parser to do static analysis and editor integrations, it's still useful to be able to get the incomplete AST resulting from a parse error. Callers that intend to use the returned value to take real actions (as opposed to just analysis) must check diags.HasError() to determine if the returned file can be considered valid.
23 lines
446 B
Go
23 lines
446 B
Go
package json
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParse_nonObject(t *testing.T) {
|
|
src := `true`
|
|
file, diags := Parse([]byte(src), "")
|
|
if len(diags) != 1 {
|
|
t.Errorf("got %d diagnostics; want 1", len(diags))
|
|
}
|
|
if file == nil {
|
|
t.Errorf("got nil File; want actual file")
|
|
}
|
|
if file.Body == nil {
|
|
t.Fatalf("got nil Body; want actual body")
|
|
}
|
|
if file.Body.(*body).obj == nil {
|
|
t.Errorf("got nil Body object; want placeholder object")
|
|
}
|
|
}
|