1package file
2
3import "testing"
4
5func TestPosition(t *testing.T) {
6	const SRC = `line1
7line2
8line3`
9	f := NewFile("", SRC, 0)
10
11	tests := []struct {
12		offset int
13		line   int
14		col    int
15	}{
16		{0, 1, 1},
17		{2, 1, 3},
18		{2, 1, 3},
19		{6, 2, 1},
20		{7, 2, 2},
21		{12, 3, 1},
22		{12, 3, 1},
23		{13, 3, 2},
24		{13, 3, 2},
25		{16, 3, 5},
26		{17, 3, 6},
27	}
28
29	for i, test := range tests {
30		if p := f.Position(test.offset); p.Line != test.line || p.Column != test.col {
31			t.Fatalf("%d. Line: %d, col: %d", i, p.Line, p.Column)
32		}
33	}
34}
35
36func TestFileConcurrency(t *testing.T) {
37	const SRC = `line1
38line2
39line3`
40	f := NewFile("", SRC, 0)
41	go func() {
42		f.Position(12)
43	}()
44	f.Position(2)
45}
46