@@ -17,6 +17,35 @@ import (
1717
1818var update = flag .Bool ("update" , false , "Update tests" )
1919
20+ // replace "@path" with content of file
21+ func replaceTextFile (t * testing.T , v any , readFile func (s string ) ([]byte , error )) any {
22+ switch v := v .(type ) {
23+ case []any :
24+ a := make ([]any , len (v ))
25+ for i , ve := range v {
26+ a [i ] = replaceTextFile (t , ve , readFile )
27+ }
28+ return a
29+ case map [string ]any :
30+ a := make (map [string ]any , len (v ))
31+ for k , ve := range v {
32+ a [k ] = replaceTextFile (t , ve , readFile )
33+ }
34+ return a
35+ case string :
36+ if _ , path , found := strings .Cut (v , "@" ); found {
37+ if b , err := readFile (path ); err == nil {
38+ return string (b )
39+ } else {
40+ t .Fatal (err )
41+ }
42+ }
43+ return v
44+ default :
45+ return v
46+ }
47+ }
48+
2049func TestLSP (t * testing.T ) {
2150 difftest .TestWithOptions (t , difftest.Options {
2251 Path : "testdata" ,
@@ -53,7 +82,8 @@ func TestLSP(t *testing.T) {
5382
5483 stdinBuf := & bytes.Buffer {}
5584 for _ , r := range requests {
56- reqB , err := json .Marshal (& r .Request )
85+ rr := replaceTextFile (t , r .Request , readFile )
86+ reqB , err := json .Marshal (& rr )
5787 if err != nil {
5888 t .Fatal (err )
5989 }
0 commit comments