fixup
This commit is contained in:
parent
269f4f52b1
commit
8868d3a0c3
2 changed files with 6 additions and 23 deletions
|
|
@ -93,12 +93,9 @@ func getBoardMap(path string, fs map[string]string, boardPath []string) (*d2ir.M
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBoardAtPosition(path string, fs map[string]string, pos d2ast.Position) ([]string, error) {
|
func GetBoardAtPosition(text string, pos d2ast.Position) ([]string, error) {
|
||||||
if _, ok := fs[path]; !ok {
|
r := strings.NewReader(text)
|
||||||
return nil, fmt.Errorf(`"%s" not found`, path)
|
ast, err := d2parser.Parse("", r, nil)
|
||||||
}
|
|
||||||
r := strings.NewReader(fs[path])
|
|
||||||
ast, err := d2parser.Parse(path, r, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package d2lsp_test
|
package d2lsp_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/d2ast"
|
"oss.terrastruct.com/d2/d2ast"
|
||||||
|
|
@ -294,29 +295,14 @@ layers: {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := d2lsp.GetBoardAtPosition(tt.path, tt.fs, tt.position)
|
got, err := d2lsp.GetBoardAtPosition(tt.fs[tt.path], tt.position)
|
||||||
assert.Success(t, err)
|
assert.Success(t, err)
|
||||||
if tt.want == nil {
|
if tt.want == nil {
|
||||||
assert.Equal(t, true, got == nil)
|
assert.Equal(t, true, got == nil)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, len(tt.want), len(got))
|
assert.Equal(t, len(tt.want), len(got))
|
||||||
assert.Equal(t, tt.want[0], got[0]) // board type
|
assert.True(t, slices.Equal(tt.want, got))
|
||||||
assert.Equal(t, tt.want[1], got[1]) // board id
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error cases
|
|
||||||
t.Run("invalid file", func(t *testing.T) {
|
|
||||||
fs := map[string]string{
|
|
||||||
"index.d2": "x ->",
|
|
||||||
}
|
|
||||||
_, err := d2lsp.GetBoardAtPosition("index.d2", fs, d2ast.Position{Line: 0, Column: 0})
|
|
||||||
assert.Error(t, err)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("file not found", func(t *testing.T) {
|
|
||||||
_, err := d2lsp.GetBoardAtPosition("notfound.d2", nil, d2ast.Position{Line: 0, Column: 0})
|
|
||||||
assert.Error(t, err)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue