Skip to content

Commit da787ad

Browse files
committed
add test
1 parent e1acd2d commit da787ad

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: go/vimlparser_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,43 @@ func testParseVimLParser(t testing.TB) {
197197
n := NewVimLParser(false).parse(NewStringReader(lines))
198198
c.compile(n)
199199
}
200+
201+
func TestVimLParser_offset(t *testing.T) {
202+
defer recovert(t)
203+
const src = `
204+
205+
function! F()
206+
let x =
207+
\ 1
208+
209+
let x = "
210+
\1
211+
\2 <- tab
212+
\3 マルチバイト
213+
\4"
214+
endfunction
215+
216+
" END
217+
`
218+
const want = `function! F()
219+
let x =
220+
\ 1
221+
222+
let x = "
223+
\1
224+
\2 <- tab
225+
\3 マルチバイト
226+
\4"
227+
endfunction`
228+
229+
n := NewVimLParser(false).parse(NewStringReader(strings.Split(src, "\n")))
230+
f := n.body[0]
231+
start := f.pos
232+
end := f.endfunction.pos
233+
endfExArg := f.endfunction.ea
234+
end.offset += endfExArg.argpos.offset - endfExArg.cmdpos.offset
235+
236+
if got := src[start.offset:end.offset]; got != want {
237+
t.Errorf("got:\n%v\nwant:\n%v", got, want)
238+
}
239+
}

0 commit comments

Comments
 (0)