-
Notifications
You must be signed in to change notification settings - Fork 223
Open
Description
The following code should produce "delete" operations.
func TestDiffMatchPatchSemantics(t *testing.T) {
aLines := []string{
" .lock()\n",
" .unwrap()\n",
" .iter()\n",
" .rev()\n",
" .fold(vec![], |mut acc, event| {\n",
" // Group contiguous to the same\n",
" acc.push(ext::WorkspaceEvent::TextDocumentChange {\n",
" uri: \"\".into(),\n",
" hunks: vec![],\n",
" });\n",
" acc\n",
}
bLines := []string{
" .lock()\n",
" .unwrap()\n",
" .iter()\n",
" .rev()\n",
" .fold(vec![], |mut acc, event| {\n",
" // Group contiguous to the same uri\n",
" if let Some(last) = acc.last_mut() {\n",
" if last.uri == event.uri {\n",
" last.hunks.extend(event.hunks);\n",
" return acc;\n",
" }\n",
" }\n",
" acc.push(ext::WorkspaceEvent::TextDocumentChange {\n",
" uri: event.uri.clone(),\n",
" hunks: event.hunks,\n",
" });\n",
" acc\n",
}
a := strings.Join(aLines, "")
b := strings.Join(bLines, "")
dmp := diffmatchpatch.New()
charsA, charsB, lineArray := dmp.DiffLinesToChars(a, b)
diff := dmp.DiffMain(charsA, charsB, false)
diff = dmp.DiffCharsToLines(diff, lineArray)
for i, op := range diff {
fmt.Println(fmt.Sprintf("(%d)%s%s", i, op.Type.String(), op.Text))
}
}However, the output is the following and does not contain such delete operations.
(0)Equal .lock()
.unwrap()
.iter()
.rev()
.fold(vec![], |mut acc, event| {
(1)Insert // Group contiguous to the same uri
if let Some(last) = acc.last_mut() {
if last.uri == event.uri {
last.hunks.extend(event.hunks);
.lock()
(2)Equal // Group contiguous to the same
(3)Insert .lock()
(4)Equal acc.push(ext::WorkspaceEvent::TextDocumentChange {
(5)Insert .lock()
(6)Equal uri: "".into(),
(7)Insert acc.push(ext::WorkspaceEvent::TextDocumentChange {
.lock()
(8)Equal hunks: vec![],
(9)Insert hunks: event.hunks,
(10)Equal });
acc
Am I using the API wrong?
Metadata
Metadata
Assignees
Labels
No labels