mirror of
https://github.com/Smaug123/WoofWare.Expect
synced 2025-10-11 06:58:44 +00:00
Add Dot rendering (#23)
This commit is contained in:
104
WoofWare.Expect.Test/TestDot.fs
Normal file
104
WoofWare.Expect.Test/TestDot.fs
Normal file
@@ -0,0 +1,104 @@
|
||||
namespace WoofWare.Expect.Test
|
||||
|
||||
#nowarn 0044 // This construct is deprecated
|
||||
|
||||
open System
|
||||
open FsUnitTyped
|
||||
open WoofWare.Expect
|
||||
open NUnit.Framework
|
||||
open System.IO.Abstractions
|
||||
open System.IO.Abstractions.TestingHelpers
|
||||
|
||||
[<TestFixture>]
|
||||
module TestDot =
|
||||
let toFs (fs : IFileSystem) : Dot.IFileSystem =
|
||||
{ new Dot.IFileSystem with
|
||||
member _.DeleteFile s = fs.File.Delete s
|
||||
member _.WriteFile path contents = fs.File.WriteAllText (path, contents)
|
||||
member _.GetTempFileName () = fs.Path.GetTempFileName ()
|
||||
}
|
||||
|
||||
[<Test ; Explicit "requires graph-easy dependency">]
|
||||
let ``Basic dotfile, real graph-easy`` () =
|
||||
let s =
|
||||
"""digraph G {
|
||||
rankdir = TB
|
||||
bgcolor = transparent
|
||||
n2 [shape=box label="{{n2|Map|height=1}}" ]
|
||||
n1 [shape=box label="{{n1|Const|height=0}}" ]
|
||||
n1 -> n2
|
||||
}"""
|
||||
|
||||
expect {
|
||||
snapshot
|
||||
@"
|
||||
┌───────────────────────┐
|
||||
│ {{n1|Const|height=0}} │
|
||||
└───────────────────────┘
|
||||
│
|
||||
│
|
||||
▼
|
||||
┌───────────────────────┐
|
||||
│ {{n2|Map|height=1}} │
|
||||
└───────────────────────┘
|
||||
"
|
||||
|
||||
return Dot.render s
|
||||
}
|
||||
|
||||
[<Test>]
|
||||
let ``Basic dotfile`` () =
|
||||
let fs = MockFileSystem ()
|
||||
|
||||
let contents =
|
||||
"""digraph G {
|
||||
rankdir = TB
|
||||
bgcolor = transparent
|
||||
n2 [shape=box label="{{n2|Map|height=1}}" ]
|
||||
n1 [shape=box label="{{n1|Const|height=0}}" ]
|
||||
n1 -> n2
|
||||
}"""
|
||||
|
||||
let mutable started = false
|
||||
let mutable waited = false
|
||||
let mutable disposed = false
|
||||
|
||||
let expected =
|
||||
"┌───────────────────────┐
|
||||
│ {{n1|Const|height=0}} │
|
||||
└───────────────────────┘
|
||||
│
|
||||
│
|
||||
▼
|
||||
┌───────────────────────┐
|
||||
│ {{n2|Map|height=1}} │
|
||||
└───────────────────────┘
|
||||
"
|
||||
|
||||
let pr =
|
||||
{ new Dot.IProcess<IDisposable> with
|
||||
member _.Start _ =
|
||||
started <- true
|
||||
true
|
||||
|
||||
member _.Create exe args =
|
||||
exe |> shouldEqual "graph-easy"
|
||||
|
||||
args.StartsWith ("--as=boxarg --from=dot ", StringComparison.Ordinal)
|
||||
|> shouldEqual true
|
||||
|
||||
{ new IDisposable with
|
||||
member _.Dispose () = disposed <- true
|
||||
}
|
||||
|
||||
member _.WaitForExit p = waited <- true
|
||||
member _.ReadStandardOutput _ = expected
|
||||
}
|
||||
|
||||
Dot.render' pr (toFs fs) "graph-easy" contents
|
||||
|> _.TrimStart()
|
||||
|> shouldEqual expected
|
||||
|
||||
started |> shouldEqual true
|
||||
waited |> shouldEqual true
|
||||
disposed |> shouldEqual true
|
@@ -14,6 +14,7 @@
|
||||
<Compile Include="BulkUpdateExample.fs" />
|
||||
<Compile Include="SimpleTest.fs" />
|
||||
<Compile Include="TestDiff.fs" />
|
||||
<Compile Include="TestDot.fs" />
|
||||
<Compile Include="TestExceptionThrowing.fs" />
|
||||
<Compile Include="TestSurface.fs" />
|
||||
<Compile Include="TestSnapshotFinding\TestSnapshotFinding.fs" />
|
||||
@@ -40,6 +41,9 @@
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
|
||||
<PackageReference Include="NUnit" Version="4.3.2"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0"/>
|
||||
<!-- TODO: when ApiSurface accepts https://github.com/G-Research/ApiSurface/pull/116, upgrade these -->
|
||||
<PackageReference Include="System.IO.Abstractions" Version="4.2.13" />
|
||||
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="4.2.13" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user