Skip to content

Commit f0ca812

Browse files
committed
+ Basic tests
1 parent 3228a09 commit f0ca812

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/FSharpPlus/Control/Foldable.fs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ open FSharpPlus.Internals.Prelude
4242

4343
type ToSeq =
4444
inherit Default1
45-
static member ToSeq (x: seq<'T> , [<Optional>]_impl: ToSeq) = x
45+
static member ToSeq (x: seq<'T>, [<Optional>]_impl: ToSeq) =
46+
#if TEST_TRACE
47+
Traces.add "ToSeq seq"
48+
#endif
49+
x
50+
4651
static member ToSeq (x: Text.StringBuilder, _: ToSeq) = string x :> seq<char>
4752
static member ToSeq (x: string , _: ToSeq) = String.toSeq x
4853
static member ToSeq (x: option<'T>, [<Optional>]_impl: ToSeq) = match x with Some x -> Seq.singleton x | _ -> Seq.empty
@@ -56,7 +61,13 @@ type ToSeq =
5661
static member inline InvokeOnInstance (source: '``Foldable<'T>``) : seq<'T> = (^``Foldable<'T>``: (static member ToSeq : _ -> _) source)
5762

5863
type ToSeq with
59-
static member inline ToSeq (x: 'S when 'S :> Collections.IEnumerable, [<Optional>]_impl: Default2) = let _f i x : 'T = (^S : (member get_Item : int -> 'T) x, i) in Seq.cast<'T> x : seq<'T>
64+
static member inline ToSeq (x: 'S when 'S :> Collections.IEnumerable, [<Optional>]_impl: Default2) =
65+
#if TEST_TRACE
66+
Traces.add "ToSeq IEnumerable"
67+
#endif
68+
let _f i x : 'T = (^S : (member get_Item : int -> 'T) x, i)
69+
Seq.cast<'T> x : seq<'T>
70+
6071
static member inline ToSeq (x: 'Foldable , [<Optional>]_impl: Default1) = ToSeq.InvokeOnInstance x
6172
static member inline ToSeq (_: 'T when 'T: null and 'T: struct , _: Default1) = ()
6273

tests/FSharpPlus.Tests/FSharpPlus.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<Compile Include="Splits.fs" />
2323
<Compile Include="Monoid.fs" />
2424
<Compile Include="Parsing.fs" />
25+
<Compile Include="Folds.fs" />
2526
<Compile Include="Traversals.fs" />
2627
<Compile Include="Indexables.fs" />
2728
<Compile Include="Collections.fs" />

tests/FSharpPlus.Tests/Folds.fs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace FSharpPlus.Tests
2+
3+
#nowarn "686"
4+
5+
open System
6+
open System.Collections.ObjectModel
7+
open FSharpPlus
8+
open FSharpPlus.Data
9+
open FSharpPlus.Control
10+
open NUnit.Framework
11+
open Helpers
12+
open FSharpPlus.Math.Applicative
13+
open CSharpLib
14+
open System.Threading.Tasks
15+
#if TEST_TRACE
16+
open FSharpPlus.Internals
17+
#endif
18+
19+
module Folds =
20+
21+
[<Test>]
22+
let basicFolds () =
23+
#if TEST_TRACE
24+
Traces.reset()
25+
#endif
26+
let r1 = set [1..3] |> fold (+) 0
27+
let r2 = set [1..3] |> toSeq
28+
Assert.AreEqual (6, r1)
29+
CollectionAssert.AreEqual ([1; 2; 3], r2)
30+
#if TEST_TRACE
31+
CollectionAssert.AreEqual (["ToSeq seq"], Traces.get())
32+
#endif

0 commit comments

Comments
 (0)