You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
7 years ago
|
package acedoc
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func TestDelta(t *testing.T) {
|
||
|
type c struct {
|
||
|
name string
|
||
|
start string
|
||
|
expect string
|
||
|
delta Delta
|
||
|
}
|
||
|
|
||
|
cases := []c{
|
||
|
{"empty", "", "", Delta{}},
|
||
|
{"empty with content", "a", "a", Delta{}},
|
||
|
{"insert with no content", "a", "a", Insert(0, 1, "")},
|
||
|
{"insert", "a", "ab", Insert(0, 1, "b")},
|
||
|
{"insert across line", "a", "a\nb", Insert(0, 1, "\nb")},
|
||
|
{"insert new line", "ab", "a\nb", Insert(0, 1, "\n")},
|
||
|
{"insert lines at beginning", "ab", "\n\nab", Insert(0, 0, "\n\n")},
|
||
|
{"insert lines at end", "ab", "ab\n\n", Insert(0, 2, "\n\n")},
|
||
|
{"insert more lines", "a\nb", "a\n\n\nb", Insert(0, 1, "\n\n")},
|
||
|
|
||
|
{"remove", "a", "", Remove(0, 0, "a")},
|
||
|
{"remove across line", "a\nb", "a", Remove(0, 1, "\nb")},
|
||
|
}
|
||
|
|
||
|
for _, c := range cases {
|
||
|
t.Run(c.name, func(t *testing.T) {
|
||
|
doc := NewString(c.start)
|
||
|
err := doc.Apply(c.delta)
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if doc.Contents() != c.expect {
|
||
|
t.Errorf("unexpected output: %q, expected: %q", doc.Contents(), c.expect)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|