mmanela / diffplex

DiffPlex is Netstandard 1.0+ C# library to generate textual diffs.
Apache License 2.0
990 stars 183 forks source link

spurious blank lines at end #111

Closed daveyostcom closed 1 month ago

daveyostcom commented 1 year ago

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
mmanela commented 11 months ago

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
SimonCropp commented 1 month ago

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