]> git.lizzy.rs Git - micro.git/blob - internal/buffer/line_array_test.go
Add default binding for FindLiteral
[micro.git] / internal / buffer / line_array_test.go
1 package buffer
2
3 import (
4         "strings"
5         "testing"
6
7         "github.com/stretchr/testify/assert"
8 )
9
10 var unicode_txt = `An preost wes on leoden, Laȝamon was ihoten
11 He wes Leovenaðes sone -- liðe him be Drihten.
12 He wonede at Ernleȝe at æðelen are chirechen,
13 Uppen Sevarne staþe, sel þar him þuhte,
14 Onfest Radestone, þer he bock radde.`
15
16 var la *LineArray
17
18 func init() {
19         reader := strings.NewReader(unicode_txt)
20         la = NewLineArray(uint64(len(unicode_txt)), FFAuto, reader)
21 }
22
23 func TestSplit(t *testing.T) {
24         la.insert(Loc{17, 1}, []byte{'\n'})
25         assert.Equal(t, len(la.lines), 6)
26         sub1 := la.Substr(Loc{0, 1}, Loc{17, 1})
27         sub2 := la.Substr(Loc{0, 2}, Loc{30, 2})
28
29         assert.Equal(t, []byte("He wes Leovenaðes"), sub1)
30         assert.Equal(t, []byte(" sone -- liðe him be Drihten."), sub2)
31 }
32
33 func TestJoin(t *testing.T) {
34         la.remove(Loc{47, 1}, Loc{0, 2})
35         assert.Equal(t, len(la.lines), 5)
36         sub := la.Substr(Loc{0, 1}, Loc{47, 1})
37         bytes := la.Bytes()
38
39         assert.Equal(t, []byte("He wes Leovenaðes sone -- liðe him be Drihten."), sub)
40         assert.Equal(t, unicode_txt, string(bytes))
41 }
42
43 func TestInsert(t *testing.T) {
44         la.insert(Loc{20, 3}, []byte(" foobar"))
45         sub1 := la.Substr(Loc{0, 3}, Loc{50, 3})
46
47         assert.Equal(t, []byte("Uppen Sevarne staþe, foobar sel þar him þuhte,"), sub1)
48
49         la.insert(Loc{25, 2}, []byte("H̼̥̯͇͙̕͘͞e̸̦̞̠̣̰͙̼̥̦̼̖̬͕͕̰̯̫͇̕ĺ̜̠̩̯̯͙̼̭̠͕̮̞͜l̶͓̫̞̮͈͞ͅo̸͔͙̳̠͈̮̼̳͙̥̲͜͠"))
50
51         sub2 := la.Substr(Loc{0, 2}, Loc{60, 2})
52         assert.Equal(t, []byte("He wonede at Ernleȝe at æH̼̥̯͇͙̕͘͞e̸̦̞̠̣̰͙̼̥̦̼̖̬͕͕̰̯̫͇̕ĺ̜̠̩̯̯͙̼̭̠͕̮̞͜l̶͓̫̞̮͈͞ͅo̸͔͙̳̠͈̮̼̳͙̥̲͜͠ðelen are chirechen,"), sub2)
53 }
54
55 func TestRemove(t *testing.T) {
56         la.remove(Loc{20, 3}, Loc{27, 3})
57         la.remove(Loc{25, 2}, Loc{30, 2})
58
59         bytes := la.Bytes()
60         assert.Equal(t, unicode_txt, string(bytes))
61 }