1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func TestContentPosition(t *testing.T) {
13 content := "foo\nš\nbar"
15 offset, wantLine, wantColumn int
23 for _, test := range tests {
24 pos, err := contentPosition(content, test.offset)
28 if pos.Line != test.wantLine {
29 t.Errorf("contentPosition(%q, %d): Line = %d, want %d", content, test.offset, pos.Line, test.wantLine)
31 if pos.Column != test.wantColumn {
32 t.Errorf("contentPosition(%q, %d): Column = %d, want %d", content, test.offset, pos.Column, test.wantColumn)
37 const exampleProgram = `
46 fmt.Println("Hello World.")
50 func TestClientEditing(t *testing.T) {
51 ws, err := NewSandbox(&SandboxConfig{Files: exampleProgram})
56 ctx := context.Background()
57 editor := NewEditor(ws, EditorConfig{})
58 if err := editor.OpenFile(ctx, "main.go"); err != nil {
61 if err := editor.EditBuffer(ctx, "main.go", []Edit{
70 got := editor.buffers["main.go"].text()
76 fmt.Println("Hola, mundo.")
80 t.Errorf("got text %q, want %q", got, want)