Add ability to mock out curried functions (#58)

This commit is contained in:
Patrick Stevens
2023-12-31 12:28:51 +00:00
committed by GitHub
parent ff2c08d54f
commit 7b3bd32323
8 changed files with 298 additions and 126 deletions

View File

@@ -10,7 +10,7 @@ module TestMockGenerator =
[<Test>]
let ``Example of use: IPublicType`` () =
let mock =
let mock : IPublicType =
{ PublicTypeMock.Empty with
Mem1 = fun (s, count) -> List.replicate count s
}
@@ -19,3 +19,16 @@ module TestMockGenerator =
Assert.Throws<NotImplementedException> (fun () -> mock.Mem2 "hi" |> ignore<int>)
mock.Mem1 ("hi", 3) |> shouldEqual [ "hi" ; "hi" ; "hi" ]
[<Test>]
let ``Example of use: curried args`` () =
let mock : Curried<_> =
{ CurriedMock.Empty () with
Mem1 = fun i c -> Array.replicate i c |> String
Mem2 = fun (i, s) c -> String.concat $"%c{c}" (List.replicate i s)
Mem3 = fun (i, s) c -> String.concat $"%c{c}" (List.replicate i s)
}
mock.Mem1 3 'a' |> shouldEqual "aaa"
mock.Mem2 (3, "hi") 'a' |> shouldEqual "hiahiahi"
mock.Mem3 (3, "hi") 'a' |> shouldEqual "hiahiahi"