37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package lang
|
|
|
|
import "testing"
|
|
|
|
func TestAnalyzeProducesStructuredUndefinedDiagnostic(t *testing.T) {
|
|
source := `package demo fun main() { println(missing) }`
|
|
program, err := Parse(source)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, diagnostics := AnalyzeWithContext(program, nil)
|
|
if len(diagnostics) != 1 {
|
|
t.Fatalf("diagnostics = %#v", diagnostics)
|
|
}
|
|
diagnostic := diagnostics[0]
|
|
if diagnostic.Code != "undefined-symbol" || diagnostic.Severity != DiagnosticError || diagnostic.Message != "undefined identifier missing" {
|
|
t.Fatalf("unexpected diagnostic: %#v", diagnostic)
|
|
}
|
|
if got := source[diagnostic.Span.Start:diagnostic.Span.End]; got != "missing" {
|
|
t.Fatalf("diagnostic span = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestAnalyzeUsesAdditionalPackagePrograms(t *testing.T) {
|
|
current, err := Parse(`package demo fun main() { helper() }`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sibling, err := Parse(`package demo fun helper() { println("ok") }`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, diagnostics := AnalyzeWithContext(current, []*Program{sibling})
|
|
if len(diagnostics) != 0 {
|
|
t.Fatalf("package symbol was not resolved: %#v", diagnostics)
|
|
}
|
|
}
|