Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ obj/
*.vspscc
*.vssscc
Ankh.NoLoad
*.userprefs

# NuGet
!.nuget/*
Expand Down Expand Up @@ -88,4 +89,4 @@ _ReSharper*/

# Ignore the NuGet build folder, it's only needed when building the package
_NuGetBuild/*
.idea/
.idea/
5 changes: 3 additions & 2 deletions ExtCore.Tests/Collections.HashMap.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,9 @@ module MapModule =

// reference keys
let refMap = HashMap.ofSeq [for c in ["."; ".."; "..."; "...."] do yield (c, c.Length) ]
let resultRefMap = HashMap.foldBack (fun x y z -> x + y.ToString() + z) refMap "right"
Assert.AreEqual(".1..2...3....4right", resultRefMap)
let resultRefMap = HashMap.foldBack (fun x y z -> (x,y) :: z) refMap [("initial",83)]
CollectionAssert.AreEquivalent([("initial",83);("....",4);("...",3);("..",2);(".",1)], resultRefMap)
Assert.AreEqual(("initial",83), resultRefMap |> Array.ofSeq |> Array.last)

// One-element HashMap
let oeleMap = HashMap.ofSeq [(1, "one")]
Expand Down
133 changes: 133 additions & 0 deletions ExtCore.Tests/Control.Compatibility.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
(*

Copyright 2013 Jack Pappas

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*)

namespace Tests.ExtCore.Control.Compatibility

open System
open System.Runtime.CompilerServices
open ExtCore.Control
open ExtCore.Compatibility
open ExtCore.Control.Compatibility
open NUnit.Framework

/// Test fixture which tests that the .Using() member of AsyncChoiceBuilder
/// disposes the supplied resource at the correct point in the program's execution.
[<TestFixture; Sealed>]
type AsyncChoiceBuilderDisposeFixture() =
let disposed = StrongBox (false)

let createDisposable (disposed : StrongBox<bool>) =
{ new IDisposable with
member __.Dispose () =
printfn "disposing!"
disposed.Value <- true }

let createAsyncChoiceDisposable() =
async { return Choice1Of2(createDisposable disposed) }

let waitAsyncChoice() =
asyncChoice {
printfn "waiting"
}

let shouldNotBeDisposed() =
printfn "Should not be disposed. Checking..."
Assert.IsFalse(disposed.Value)

let createAsyncDisposable() = async { return (createDisposable disposed) }

let waitAsync() =
async {
printfn "waiting"
}

[<SetUp>]
member __.Setup () : unit =
disposed.Value <- false

[<TearDown>]
member __.Teardown () : unit =
printfn "Should be disposed. Checking..."
Assert.IsTrue(disposed.Value)

// asyncChoice wrong behavior
[<Test>]
member __.UsingAsyncChoice() : unit =
asyncChoice {
use! d = createAsyncChoiceDisposable()
shouldNotBeDisposed()
let! a = waitAsyncChoice()
shouldNotBeDisposed()
}
|> Async.RunSynchronously
|> Choice.get
|> ignore

// async - expected behavior
[<Test>]
member __.UsingAsync() : unit =
async {
use! d = createAsyncDisposable()
shouldNotBeDisposed()
do! waitAsync()
shouldNotBeDisposed()
}
|> Async.RunSynchronously
|> ignore


/// <summary>
/// Tests for <see cref="ExtCore.Control.ChoiceBuilder"/>.
/// </summary>
module ChoiceBuilder =
/// <summary>Tests for <see cref="ExtCore.Control.ChoiceBuilder.For"/>.</summary>
module ``ChoiceBuilder_For`` =
[<Test>]
let ``simple test`` () : unit =
let count = ref 0
let data = [| 1..3 |]
let result = choice {
for i in data do
incr count
return true
}

// Check the loop iteration count is correct.
assertEqual 3 !count

// Check the result of the computation.
assertEqual (Choice1Of2 true) result

/// <summary>Tests for <see cref="ExtCore.Control.ChoiceBuilder.While"/>.</summary>
module ``ChoiceBuilder_While`` =
[<Test>]
let ``simple test`` () : unit =
let count = ref 0
let data = [| 1..3 |]
let result = choice {
while !count < 3 do
incr count
return true
}

// Check the loop iteration count is correct.
assertEqual 3 !count

// Check the result of the computation.
assertEqual (Choice1Of2 true) result

132 changes: 132 additions & 0 deletions ExtCore.Tests/Control.Result.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
(*

Copyright 2013 Jack Pappas

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*)

namespace Tests.ExtCore.Control

open System
open System.Runtime.CompilerServices
open ExtCore.Control
open NUnit.Framework


/// Test fixture which tests that the .Using() member of AsyncResultBuilder
/// disposes the supplied resource at the correct point in the program's execution.
[<TestFixture; Sealed>]
type AsyncResultBuilderDisposeFixture() =
let disposed = StrongBox (false)

let createDisposable (disposed : StrongBox<bool>) =
{ new IDisposable with
member __.Dispose () =
printfn "disposing!"
disposed.Value <- true }

let createAsyncResultDisposable() =
async { return Ok(createDisposable disposed) }

let waitAsyncResult() =
asyncResult {
printfn "waiting"
}

let shouldNotBeDisposed() =
printfn "Should not be disposed. Checking..."
Assert.IsFalse(disposed.Value)

let createAsyncDisposable() = async { return (createDisposable disposed) }

let waitAsync() =
async {
printfn "waiting"
}

[<SetUp>]
member __.Setup () : unit =
disposed.Value <- false

[<TearDown>]
member __.Teardown () : unit =
printfn "Should be disposed. Checking..."
Assert.IsTrue(disposed.Value)

// asyncResult wrong behavior
[<Test>]
member __.UsingAsyncChoice() : unit =
asyncResult {
use! d = createAsyncResultDisposable()
shouldNotBeDisposed()
let! a = waitAsyncResult()
shouldNotBeDisposed()
}
|> Async.RunSynchronously
|> Result.get
|> ignore

// async - expected behavior
[<Test>]
member __.UsingAsync() : unit =
async {
use! d = createAsyncDisposable()
shouldNotBeDisposed()
do! waitAsync()
shouldNotBeDisposed()
}
|> Async.RunSynchronously
|> ignore

/// <summary>
/// Tests for <see cref="ExtCore.Control.ResultBuilder"/>.
/// </summary>
module ResultBuilder =
/// <summary>Tests for <see cref="ExtCore.Control.ResultBuilder.For"/>.</summary>
module ``ResultBuilder_For`` =
[<Test>]
let ``simple test`` () : unit =
let count = ref 0
let data = [| 1..3 |]
let result = result {
for i in data do
incr count
return true
}

// Check the loop iteration count is correct.
assertEqual 3 !count

// Check the result of the computation.
assertEqual (Ok true) result

/// <summary>Tests for <see cref="ExtCore.Control.ResultBuilder.While"/>.</summary>
module ``ResultBuilder_While`` =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove <summary> tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit extra, that's why?

[<Test>]
let ``simple test`` () : unit =
let count = ref 0
let data = [| 1..3 |]
let result = result {
while !count < 3 do
incr count
return true
}

// Check the loop iteration count is correct.
assertEqual 3 !count

// Check the result of the computation.
assertEqual (Ok true) result


Loading