Patience diff (#17)

This commit is contained in:
Patrick Stevens
2025-07-24 09:14:53 +01:00
committed by GitHub
parent ca74c4816b
commit e0153ab182
8 changed files with 470 additions and 25 deletions

View File

@@ -19,12 +19,9 @@ module SimpleTest =
let ``Example of a failing test`` () =
expect {
snapshot
@"snapshot mismatch! snapshot at filepath.fs:99 (Example of a failing test) was:
@"snapshot mismatch! snapshot at filepath.fs:99 (Example of a failing test) diff:
- 123
actual was:
+ 124"
return
@@ -64,26 +61,21 @@ actual was:
// Out of the box, comments in snapshots cause the JSON parser to throw, so the snapshot fails to match...
expect {
snapshot
@"snapshot mismatch! snapshot at file.fs:99 (Custom JSON output) was:
@"snapshot mismatch! snapshot at file.fs:99 (Custom JSON output) diff:
- [JSON failed to parse:] {
- // a key here
- ""a"":3
- }
actual was:
- // a key here
+ {
+ ""a"": 3
+ }"
""a"": 3
}"
return
Assert.Throws<ExpectException> (fun () ->
expectWithMockedFilePath ("file.fs", 99) {
snapshotJson
@"{
// a key here
""a"":3
// a key here
""a"": 3
}"
return Map.ofList [ "a", 3 ]

View File

@@ -0,0 +1,110 @@
namespace WoofWare.Expect.Test
open WoofWare.Expect
open NUnit.Framework
[<TestFixture>]
module TestDiff =
[<Test>]
let ``Basic diff`` () =
let textA =
[|
"The quick brown fox"
"jumps over"
"the lazy dog"
"Some unique line here"
"The end"
|]
let textB =
[|
"The quick brown fox"
"Some unique line here"
"jumps over"
"the lazy dog"
"Another line"
"The end"
|]
let diff = Diff.patienceLines textA textB
expect {
snapshot
@" 0 0 The quick brown fox
+ 1 Some unique line here
1 2 jumps over
2 3 the lazy dog
- 3 Some unique line here
+ 4 Another line
4 5 The end"
withFormat Diff.formatWithLineNumbers
return diff
}
expect {
snapshot
@" The quick brown fox
+ Some unique line here
jumps over
the lazy dog
- Some unique line here
+ Another line
The end"
withFormat Diff.format
return diff
}
[<Test>]
let ``An example from Incremental`` () =
let textA =
"""digraph G {
rankdir = TB
bgcolor = transparent
n4 [shape=Mrecord label="{{n4|BindMain|height=2}}" "fontname"="Sans Serif"]
n3 [shape=Mrecord label="{{n3|BindLhsChange|height=1}}" "fontname"="Sans Serif"]
n1 [shape=Mrecord label="{{n1|Const|height=0}}" "fontname"="Sans Serif"]
n2 [shape=Mrecord label="{{n2|Const|height=0}}" "fontname"="Sans Serif"]
n3 -> n4
n2 -> n4
n1 -> n3
}"""
let textB =
"""digraph G {
rankdir = TB
bgcolor = transparent
n4 [shape=box label="{{n4|BindMain|height=2}}" ]
n3 [shape=box label="{{n3|BindLhsChange|height=1}}" ]
n1 [shape=box label="{{n1|Const|height=0}}" ]
n2 [shape=box label="{{n2|Const|height=0}}" ]
n3 -> n4
n2 -> n4
n1 -> n3
}"""
let diff = Diff.patience textA textB
expect {
snapshot
@" digraph G {
rankdir = TB
bgcolor = transparent
- n4 [shape=Mrecord label=""{{n4|BindMain|height=2}}"" ""fontname""=""Sans Serif""]
- n3 [shape=Mrecord label=""{{n3|BindLhsChange|height=1}}"" ""fontname""=""Sans Serif""]
- n1 [shape=Mrecord label=""{{n1|Const|height=0}}"" ""fontname""=""Sans Serif""]
- n2 [shape=Mrecord label=""{{n2|Const|height=0}}"" ""fontname""=""Sans Serif""]
+ n4 [shape=box label=""{{n4|BindMain|height=2}}"" ]
+ n3 [shape=box label=""{{n3|BindLhsChange|height=1}}"" ]
+ n1 [shape=box label=""{{n1|Const|height=0}}"" ]
+ n2 [shape=box label=""{{n2|Const|height=0}}"" ]
n3 -> n4
n2 -> n4
n1 -> n3
}"
withFormat Diff.format
return diff
}

View File

@@ -13,6 +13,7 @@
<Compile Include="Assembly.fs" />
<Compile Include="BulkUpdateExample.fs" />
<Compile Include="SimpleTest.fs" />
<Compile Include="TestDiff.fs" />
<Compile Include="TestExceptionThrowing.fs" />
<Compile Include="TestSurface.fs" />
<Compile Include="TestSnapshotFinding\TestSnapshotFinding.fs" />