diffplex icon indicating copy to clipboard operation
diffplex copied to clipboard

spurious blank lines at end

Open daveyostcom opened this issue 2 years ago • 1 comments

In the output from the program below, the line with the "" and the blank line after it should not be there:

Changes: 2
  "a"
x "b"
√ "x"
  "c"
  ""

––––––––––
open System.Text
open DiffPlex.DiffBuilder
open DiffPlex.DiffBuilder.Model

let prefix lineType =
  match lineType with
  | ChangeType.Unchanged -> "  "
  | ChangeType.Inserted  -> "√ "
  | ChangeType.Deleted   -> "x "
  | ChangeType.Modified  -> "≠ "
  | ChangeType.Imaginary -> "i "
  | _ -> failwith "Unknown line type in prefix" 

let tallyChange lineType =
  match lineType with
  | ChangeType.Unchanged -> 0
  | ChangeType.Inserted  -> 1
  | ChangeType.Deleted   -> 1
  | ChangeType.Modified  -> 1
  | ChangeType.Imaginary -> 0
  | _ -> failwith "Unknown line type in noteChanged" 

let show (diff: DiffPaneModel) =
  let lines = diff.Lines
  let sb = StringBuilder()
  for line in lines do
    sb.Append((prefix line.Type) + "\"" + line.Text + "\"" + "\n") |> ignore
  let n =
    diff.Lines
    |> Seq.map (fun line -> (tallyChange line.Type))
    |> Seq.sum
  printfn "Changes: %d" n
  printfn "%s" (sb.ToString())
  printfn "––––––––––"

let test() =
  let expected = "a\nb\nc\n"
  let actual   = "a\nx\nc\n"
  let diff = InlineDiffBuilder.Diff(expected, actual, false)
  show diff

[<EntryPoint>]
let main argv =
  test()
  0

daveyostcom avatar Aug 14 '23 22:08 daveyostcom

It looks like it is working correct to me when I run it. It detects 5 lines (since the new line is at the end, creates another line) And it marks them correctly here

image

With this output image

mmanela avatar Sep 03 '23 18:09 mmanela

suggest we close this. unless a failing test (as a PullRequest) can be provided

SimonCropp avatar Jul 07 '24 11:07 SimonCropp