Precompute canonical paths before sorting
This commit is contained in:
@@ -90,6 +90,26 @@ func TestDiagnosticsAreCanonicalAndDetached(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalDiagnosticsSortEscapedPaths(t *testing.T) {
|
||||
primary := &Location{SourceID: "source-1", Line: 1, Column: 1}
|
||||
diagnostics := []Diagnostic{
|
||||
{Code: "same", Severity: SeverityError, Path: Keys("a/b"), Message: "same", Primary: primary},
|
||||
{Code: "same", Severity: SeverityError, Path: Keys("a~b"), Message: "same", Primary: primary},
|
||||
{Code: "z", Severity: SeverityError, Path: Keys("same"), Message: "same", Primary: primary},
|
||||
{Code: "a", Severity: SeverityError, Path: Keys("same"), Message: "same", Primary: primary},
|
||||
}
|
||||
canonical := canonicalDiagnostics(diagnostics)
|
||||
want := []string{"/a~0b", "/a~1b", "/same", "/same"}
|
||||
for i, diagnostic := range canonical {
|
||||
if got := diagnostic.Path.String(); got != want[i] {
|
||||
t.Fatalf("diagnostic[%d] path = %q, want %q", i, got, want[i])
|
||||
}
|
||||
}
|
||||
if canonical[2].Code != "a" || canonical[3].Code != "z" {
|
||||
t.Fatalf("same-path code order = %q, %q", canonical[2].Code, canonical[3].Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteDiagnosticsEscapesControls(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user