Skip to content

Commit 31950e1

Browse files
committed
Fixes for fable
1 parent cfbf11d commit 31950e1

File tree

4 files changed

+66
-51
lines changed

4 files changed

+66
-51
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
14.16.1

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/FsToolkit.ErrorHandling.Tests/Expect.fs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,51 @@ module Expect =
5858
else Tests.failtestf "Expected %A, was %A." v x
5959
}
6060

61-
let hasTaskValue v taskX =
62-
let x = taskX |> Async.AwaitTask |> Async.RunSynchronously
63-
if v = x then
64-
()
65-
else Tests.failtestf "Expected %A, was %A." v x
66-
67-
6861
let hasAsyncOkValue v asyncX = async {
6962
let! x = asyncX
7063
hasOkValue v x
7164
}
7265

73-
let hasTaskOkValue v taskX =
74-
let x = taskX |> Async.AwaitTask |> Async.RunSynchronously
75-
hasOkValue v x
76-
7766
let hasAsyncErrorValue v asyncX = async {
7867
let! x = asyncX
7968
hasErrorValue v x
8069
}
8170

82-
let hasTaskErrorValue v taskX =
83-
let x = taskX |> Async.AwaitTask |> Async.RunSynchronously
84-
hasErrorValue v x
85-
8671
let hasAsyncSomeValue v asyncX = async {
8772
let! x = asyncX
8873
hasSomeValue v x
8974
}
9075

91-
let hasTaskSomeValue v taskX =
92-
let x = taskX |> Async.AwaitTask |> Async.RunSynchronously
93-
hasSomeValue v x
94-
9576
let hasAsyncNoneValue asyncX = async {
9677
let! x = asyncX
9778
hasNoneValue x
9879
}
9980

81+
#if !FABLE_COMPILER
82+
let hasTaskValue v taskX =
83+
let x = taskX |> Async.AwaitTask |> Async.RunSynchronously
84+
if v = x then
85+
()
86+
else Tests.failtestf "Expected %A, was %A." v x
87+
88+
let hasTaskOkValue v taskX =
89+
let x = taskX |> Async.AwaitTask |> Async.RunSynchronously
90+
hasOkValue v x
91+
10092
let hasTaskNoneValue taskX =
10193
let x = taskX |> Async.AwaitTask |> Async.RunSynchronously
10294
hasNoneValue x
10395

96+
let hasTaskErrorValue v taskX =
97+
let x = taskX |> Async.AwaitTask |> Async.RunSynchronously
98+
hasErrorValue v x
99+
100+
let hasTaskSomeValue v taskX =
101+
let x = taskX |> Async.AwaitTask |> Async.RunSynchronously
102+
hasSomeValue v x
103+
104+
#endif
105+
104106
let same expected actual =
105107
Expect.equal actual expected "expected and actual should be same"
106108

tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ let makeDisposable () =
1414
{ new System.IDisposable
1515
with member this.Dispose() = () }
1616

17+
18+
// type Option<'a> = | Some of 'a | None
19+
1720
let ceTests =
1821
testList "CE Tests" [
1922
testCase "Return value" <| fun _ ->
23+
24+
2025
let expected = Some 42
2126
let actual = option {
2227
return 42
@@ -127,22 +132,24 @@ let ceTests =
127132
return data
128133
}
129134
Expect.equal actual (Some data) "Should be ok"
135+
#if !FABLE_COMPILER
130136
testCase "Nullable value" <| fun () ->
131137
let data = 42
132138
let actual = option {
133-
return! System.Nullable data
139+
let! value = System.Nullable<int> data
140+
return value
134141
}
135142
Expect.equal actual (Some data) ""
136143
testCase "Nullable null" <| fun () ->
137144
let actual = option {
138145
return! System.Nullable<_> ()
139146
}
140147
Expect.equal actual None ""
141-
148+
#endif
142149
testCase "string value" <| fun () ->
143150
let data = "hello"
144151
let actual = option {
145-
let! v = data
152+
let! v = data
146153
return v
147154
}
148155
Expect.equal actual (Some data) ""
@@ -197,6 +204,7 @@ let ``OptionCE applicative tests`` =
197204
}
198205
Expect.equal actual (Some 4) "Should be Some 4"
199206

207+
#if !FABLE_COMPILER
200208
testCase "Happy Path Nullable" <| fun () ->
201209
let actual = option {
202210
let! a = Nullable<_> 3
@@ -205,7 +213,7 @@ let ``OptionCE applicative tests`` =
205213
return a + b - c
206214
}
207215
Expect.equal actual (Some 4) "Should be Some 4"
208-
216+
#endif
209217
testCase "Happy Path null Objects" <| fun () ->
210218
// let hello = CustomClass
211219
let actual = option {
@@ -244,6 +252,7 @@ let ``OptionCE applicative tests`` =
244252
}
245253
Expect.equal actual (Some 6) "Should be Some"
246254

255+
#if !FABLE_COMPILER
247256
testCase "Happy Path Option.Some/Nullable" <| fun () ->
248257
let actual = option {
249258
let! a = Some 3
@@ -263,27 +272,29 @@ let ``OptionCE applicative tests`` =
263272
Expect.equal actual (Some 4) "Should be Some 4"
264273

265274

266-
testCase "Hapy Combo" <| fun () ->
275+
testCase "Happy Combo all" <| fun () ->
267276
let actual = option {
268277
let! a = Nullable<_> 3
269278
and! b = Some 2
270-
and! c = "Nullable<_>()"
279+
and! c = "hello"
271280
and! d = ResizeArray [1]
272281
and! e = CustomClass 5
273-
and! f = Uri "http://github.com"
274-
return a,b,c,d,e,f
282+
and! f = Uri "https://github.com/"
283+
return sprintf "%d %d %s %d %d %s" a b c (Seq.head d) e.getX (string f)
275284
}
276-
Expect.isSome actual "Should be Some"
277-
285+
286+
Expect.equal actual (Some "3 2 hello 1 5 https://github.com/") "Should be Some"
287+
#endif
278288
testCase "Fail Path Option.None" <| fun () ->
279289
let actual = option {
280290
let! a = Some 3
281291
and! b = Some 2
282292
and! c = None
283293
return a + b - c
284294
}
285-
Expect.isNone actual "Should be None"
286-
295+
Expect.equal actual None "Should be None"
296+
297+
#if !FABLE_COMPILER
287298
testCase "Fail Path Nullable" <| fun () ->
288299
let actual = option {
289300
let! a = Nullable 3
@@ -292,7 +303,7 @@ let ``OptionCE applicative tests`` =
292303
return a + b - c
293304
}
294305
Expect.equal actual (None) "Should be None"
295-
306+
#endif
296307
testCase "Fail Path Objects" <| fun () ->
297308
let c1 = CustomClass 3
298309
let c2 = CustomClass 2
@@ -318,15 +329,16 @@ let ``OptionCE applicative tests`` =
318329
}
319330
Expect.equal actual (None) "Should be None"
320331

332+
#if !FABLE_COMPILER
321333
testCase "Fail Path Option.Some/Nullable" <| fun () ->
322334
let actual = option {
323335
let! a = Nullable<_> 3
324336
and! b = Some 2
325337
and! c = Nullable<_>()
326338
return a + b - c
327339
}
328-
Expect.isNone actual "Should be None"
329-
340+
Expect.equal actual None "Should be None"
341+
#endif
330342
]
331343

332344
let allTests = testList "Option CE tests" [

0 commit comments

Comments
 (0)