forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFsiTests.fs
670 lines (476 loc) · 25.7 KB
/
FsiTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
namespace FSharp.Compiler.Service.Tests
open System
open System.IO
open FluentAssertions
open FSharp.Compiler.Interactive.Shell
open FSharp.Test
open Xunit
open System.Threading
type Sentinel () =
let x = ()
module MyModule =
let test(x: int) = ()
[<CollectionDefinition("FsiTests", DisableParallelization = true)>]
module FsiTests =
let createFsiSession (useOneDynamicAssembly: bool) =
// Initialize output and input streams
let inStream = new StringReader("")
let outStream = new CompilerOutputStream()
let errStream = new CompilerOutputStream()
// Build command line arguments & start FSI session
let argv = [| "C:\\fsi.exe" |]
let allArgs = Array.append argv [|"--noninteractive"; if useOneDynamicAssembly then "--multiemit-" else "--multiemit+" |]
let fsiConfig = FsiEvaluationSession.GetDefaultConfiguration()
FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, new StreamWriter(outStream), new StreamWriter(errStream), collectible = true)
[<Fact>]
let ``No bound values at the start of FSI session`` () =
use fsiSession = createFsiSession false
let values = fsiSession.GetBoundValues()
Assert.shouldBeEmpty values
[<Fact>]
let ``Bound value has correct name`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1")
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x" boundValue.Name
[<Fact>]
let ``Bound value has correct value`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let y = 2")
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe 2 boundValue.Value.ReflectionValue
[<Fact>]
let ``Bound value has correct type`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let z = 3")
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<int> boundValue.Value.ReflectionType
[<Fact>]
let ``Seven bound values are ordered and have their correct name`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1")
fsiSession.EvalInteraction("let y = 2")
fsiSession.EvalInteraction("let z = 3")
fsiSession.EvalInteraction("let a = 4")
fsiSession.EvalInteraction("let ccc = 5")
fsiSession.EvalInteraction("let b = 6")
fsiSession.EvalInteraction("let aa = 7")
let names = fsiSession.GetBoundValues() |> List.map (fun x -> x.Name)
Assert.shouldBe ["a";"aa";"b";"ccc";"x";"y";"z"] names
[<Fact>]
let ``Seven bound values are ordered and have their correct value`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1")
fsiSession.EvalInteraction("let y = 2")
fsiSession.EvalInteraction("let z = 3")
fsiSession.EvalInteraction("let a = 4")
fsiSession.EvalInteraction("let ccc = 5")
fsiSession.EvalInteraction("let b = 6")
fsiSession.EvalInteraction("let aa = 7")
let values = fsiSession.GetBoundValues() |> List.map (fun x -> x.Value.ReflectionValue)
Assert.shouldBeEquivalentTo [4;7;6;5;1;2;3] values
[<Fact>]
let ``Seven bound values are ordered and have their correct type`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1")
fsiSession.EvalInteraction("let y = 2")
fsiSession.EvalInteraction("let z = 3")
fsiSession.EvalInteraction("let a = 4.")
fsiSession.EvalInteraction("let ccc = 5")
fsiSession.EvalInteraction("let b = 6.f")
fsiSession.EvalInteraction("let aa = 7")
let types = fsiSession.GetBoundValues() |> List.map (fun x -> x.Value.ReflectionType)
Assert.shouldBe [typeof<float>;typeof<int>;typeof<float32>;typeof<int>;typeof<int>;typeof<int>;typeof<int>] types
[<Fact>]
let ``Able to find a bound value by the identifier`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1")
fsiSession.EvalInteraction("let y = 2")
fsiSession.EvalInteraction("let z = 3")
fsiSession.EvalInteraction("let a = 4")
fsiSession.EvalInteraction("let ccc = 5")
fsiSession.EvalInteraction("let b = 6")
fsiSession.EvalInteraction("let aa = 7")
let boundValueOpt = fsiSession.TryFindBoundValue "ccc"
Assert.shouldBeTrue boundValueOpt.IsSome
[<Fact>]
let ``Able to find a bound value by the identifier and has valid info`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1.")
fsiSession.EvalInteraction("let y = 2.")
fsiSession.EvalInteraction("let z = 3")
fsiSession.EvalInteraction("let a = 4.")
fsiSession.EvalInteraction("let ccc = 5.")
fsiSession.EvalInteraction("let b = 6.")
fsiSession.EvalInteraction("let aa = 7.")
let boundValue = (fsiSession.TryFindBoundValue "z").Value
Assert.shouldBe "z" boundValue.Name
Assert.shouldBe 3 boundValue.Value.ReflectionValue
Assert.shouldBe typeof<int> boundValue.Value.ReflectionType
[<Fact>]
let ``Not Able to find a bound value by the identifier`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1")
fsiSession.EvalInteraction("let y = 2")
fsiSession.EvalInteraction("let z = 3")
fsiSession.EvalInteraction("let a = 4")
fsiSession.EvalInteraction("let ccc = 5")
fsiSession.EvalInteraction("let b = 6")
fsiSession.EvalInteraction("let aa = 7")
let boundValueOpt = fsiSession.TryFindBoundValue "aaa"
Assert.shouldBeTrue boundValueOpt.IsNone
[<Fact>]
let ``The 'it' value does not exist at the start of a FSI session`` () =
use fsiSession = createFsiSession false
let boundValueOpt = fsiSession.TryFindBoundValue "it"
Assert.shouldBeTrue boundValueOpt.IsNone
[<Fact>]
let ``The 'it' bound value does exists after a value is not explicitly bound`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("456")
let boundValueOpt = fsiSession.TryFindBoundValue "it"
Assert.shouldBeTrue boundValueOpt.IsSome
[<Fact>]
let ``The 'it' value does exists after a value is not explicitly bound and has valid info`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("456")
let boundValue = (fsiSession.TryFindBoundValue "it").Value
Assert.shouldBe "it" boundValue.Name
Assert.shouldBe 456 boundValue.Value.ReflectionValue
Assert.shouldBe typeof<int> boundValue.Value.ReflectionType
[<Fact>]
let ``The latest shadowed value is only available`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1")
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe 1 boundValue.Value.ReflectionValue
Assert.shouldBe typeof<int> boundValue.Value.ReflectionType
fsiSession.EvalInteraction("let x = (1, 2)")
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe (1, 2) boundValue.Value.ReflectionValue
Assert.shouldBe typeof<int * int> boundValue.Value.ReflectionType
[<Fact>]
let ``The latest shadowed value is only available and can be found`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1")
let boundValue = (fsiSession.TryFindBoundValue "x").Value
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe 1 boundValue.Value.ReflectionValue
Assert.shouldBe typeof<int> boundValue.Value.ReflectionType
fsiSession.EvalInteraction("let x = (1, 2)")
let boundValue = (fsiSession.TryFindBoundValue "x").Value
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe (1, 2) boundValue.Value.ReflectionValue
Assert.shouldBe typeof<int * int> boundValue.Value.ReflectionType
[<Fact>]
let ``Values are successfully shadowed even with intermediate interactions`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("let x = 1")
fsiSession.EvalInteraction("let z = 100")
fsiSession.EvalInteraction("let x = (1, 2)")
fsiSession.EvalInteraction("let w = obj ()")
let boundValues = fsiSession.GetBoundValues()
Assert.shouldBe 3 boundValues.Length
let boundValue = boundValues |> List.find (fun x -> x.Name = "x")
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe (1, 2) boundValue.Value.ReflectionValue
Assert.shouldBe typeof<int * int> boundValue.Value.ReflectionType
let boundValue = (fsiSession.TryFindBoundValue "x").Value
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe (1, 2) boundValue.Value.ReflectionValue
Assert.shouldBe typeof<int * int> boundValue.Value.ReflectionType
[<Fact>]
let ``Creation of a simple bound value succeeds`` () =
use fsiSession = createFsiSession false
fsiSession.AddBoundValue("x", 1)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe typeof<int> boundValue.Value.ReflectionType
Assert.shouldBe 1 boundValue.Value.ReflectionValue
[<Fact>]
let ``Creation of a bound value succeeds with underscores in the identifier`` () =
use fsiSession = createFsiSession false
fsiSession.AddBoundValue("x_y_z", 1)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x_y_z" boundValue.Name
[<Fact>]
let ``Creation of a bound value succeeds with tildes in the identifier`` () =
use fsiSession = createFsiSession false
fsiSession.AddBoundValue("``hello world``", 1)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "``hello world``" boundValue.Name
[<Fact>]
let ``Creation of a bound value succeeds with 'it' as the identifier`` () =
use fsiSession = createFsiSession false
fsiSession.EvalInteraction("\"test\"")
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "it" boundValue.Name
Assert.shouldBe typeof<string> boundValue.Value.ReflectionType
fsiSession.AddBoundValue("it", 1)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "it" boundValue.Name
Assert.shouldBe typeof<int> boundValue.Value.ReflectionType
[<Fact>]
let ``Creation of a bound value fails with tildes in the identifier and with 'at' but has warning`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue("``hello @ world``", 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the name is not a valid identifier with 'at' in front`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue("@x", 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the name is not a valid identifier with 'at' in back`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue("x@", 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the name is null`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue(null, 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the name is empty`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue("", 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the name is whitespace`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue(" ", 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the name contains spaces`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue("x x", 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the name contains an operator at the end`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue("x+", 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the name contains an operator at the front`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue("+x", 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the name contains dots`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentException>(fun () -> fsiSession.AddBoundValue("x.x", 1)) |> ignore
[<Fact>]
let ``Creation of a bound value fails if the value passed is null`` () =
use fsiSession = createFsiSession false
Assert.Throws<ArgumentNullException>(fun () -> fsiSession.AddBoundValue("x", null) |> ignore) |> ignore
type CustomType = { X: int }
[<Fact>]
let ``Creation of a bound value succeeds if the value contains types from assemblies that are not referenced in the session, due to implicit resolution`` () =
use fsiSession = createFsiSession false
fsiSession.AddBoundValue("x", { X = 1 })
[<Fact>]
let ``Creation of a bound value succeeds if the value contains types from assemblies that are not referenced in the session, due to implicit resolution, and then doing some evaluation`` () =
use fsiSession = createFsiSession false
fsiSession.AddBoundValue("x", { X = 1 })
fsiSession.EvalInteraction("let y = { x with X = 5 }")
let boundValues = fsiSession.GetBoundValues()
Assert.shouldBe 2 boundValues.Length
let v1 = boundValues.[0]
let v2 = boundValues.[1]
Assert.shouldBe "x" v1.Name
Assert.shouldBe { X = 1 } v1.Value.ReflectionValue
Assert.shouldBe typeof<CustomType> v1.Value.ReflectionType
Assert.shouldBe "y" v2.Name
Assert.shouldBe { X = 5 } v2.Value.ReflectionValue
Assert.shouldBe typeof<CustomType> v2.Value.ReflectionType
[<Fact>]
let ``Creation of a bound value, of type ResizeArray<string>, succeeds`` () =
use fsiSession = createFsiSession false
let xs = ResizeArray()
xs.Add("banana")
xs.Add("apple")
fsiSession.AddBoundValue("xs", xs)
let boundValues = fsiSession.GetBoundValues()
Assert.shouldBe 1 boundValues.Length
let v1 = boundValues.[0]
Assert.shouldBe "xs" v1.Name
Assert.shouldBe xs v1.Value.ReflectionValue
Assert.shouldBe typeof<ResizeArray<string>> v1.Value.ReflectionType
[<Struct>]
type CustomStruct(x: int) =
member _.X = x
type CustomType2() =
member _.Message = "hello"
[<Fact>]
let ``Creation of a bound value succeeds if the value contains types from assemblies that are not referenced in the session, due to implicit resolution, and then use a member from it`` () =
use fsiSession = createFsiSession false
let value = CustomType2()
fsiSession.AddBoundValue("x", value)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe value boundValue.Value.ReflectionValue
Assert.shouldBe typeof<CustomType2> boundValue.Value.ReflectionType
fsiSession.EvalInteraction("let x = x.Message")
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe "hello" boundValue.Value.ReflectionValue
Assert.shouldBe typeof<string> boundValue.Value.ReflectionType
[<Fact>]
let ``Creation of a bound value succeeds if the value contains generic types from assemblies that are not referenced in the session, due to implicit resolution, and then use a member from it`` () =
use fsiSession = createFsiSession false
let value = ResizeArray<CustomType2>()
value.Add(CustomType2())
fsiSession.AddBoundValue("x", value)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe value boundValue.Value.ReflectionValue
Assert.shouldBe typeof<ResizeArray<CustomType2>> boundValue.Value.ReflectionType
fsiSession.EvalInteraction("let x = x.[0].Message")
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe "hello" boundValue.Value.ReflectionValue
Assert.shouldBe typeof<string> boundValue.Value.ReflectionType
[<Fact>]
let ``Creation of a bound value succeeds if the value contains two generic types from assemblies that are not referenced in the session, due to implicit resolution`` () =
use fsiSession = createFsiSession false
let value = ({ X = 1 }, CustomType2())
fsiSession.AddBoundValue("x", value)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe "x" boundValue.Name
Assert.shouldBe value boundValue.Value.ReflectionValue
Assert.shouldBe typeof<CustomType * CustomType2> boundValue.Value.ReflectionType
[<Fact>]
let ``Creation of a bound value fails if the value contains types from a dynamic assembly using single assembly emit`` () =
use fsiSession = createFsiSession true
fsiSession.AddBoundValue("fsiSession", fsiSession)
let res, _ = fsiSession.EvalInteractionNonThrowing("""
type TypeInDynamicAssembly() = class end
fsiSession.AddBoundValue("x", TypeInDynamicAssembly())""")
match res with
| Choice2Of2 ex -> Assert.shouldBe typeof<NotSupportedException> (ex.GetType())
| _ -> failwith "Expected an exception"
[<Fact>]
let ``Creation of a bound value fails if the value contains types from a dynamic assembly using ilwrite`` () =
use fsiSession = createFsiSession false
fsiSession.AddBoundValue("fsiSession", fsiSession)
let res, _ = fsiSession.EvalInteractionNonThrowing("""
type TypeInDynamicAssembly() = class end
fsiSession.AddBoundValue("x", TypeInDynamicAssembly())""")
match res with
| Choice2Of2 ex -> Assert.shouldBe typeof<InvalidOperationException> (ex.GetType())
| _ -> failwith "Expected an exception"
type internal NonPublicCustomType() = class end
[<Fact>]
let ``Creation of a bound value fails if the value's type is not public`` () =
use fsiSession = createFsiSession false
Assert.Throws<InvalidOperationException>(fun () -> fsiSession.AddBoundValue("x", NonPublicCustomType())) |> ignore
[<Fact>]
let ``Creation of a bound value succeeds if the value is a partial application function type`` () =
use fsiSession = createFsiSession false
fsiSession.AddBoundValue("createFsiSession", createFsiSession)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<bool -> FsiEvaluationSession> boundValue.Value.ReflectionType
[<Fact>]
let ``Creation of a bound value succeeds if the value is a partial application function type with four arguments`` () =
use fsiSession = createFsiSession false
let addXYZW x y z w = x + y + z + w
let addYZW = addXYZW 1
let addZW = addYZW 2
fsiSession.AddBoundValue("addZW", addZW)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<int -> int -> int> boundValue.Value.ReflectionType
[<Fact>]
let ``Creation of a bound value succeeds if the value is a lambda`` () =
use fsiSession = createFsiSession false
fsiSession.AddBoundValue("addXYZ", fun x y z -> x + y + z)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<int -> int -> int -> int> boundValue.Value.ReflectionType
type TestFSharpFunc() =
inherit FSharpFunc<int, int>()
override _.Invoke x = x
type Test2FSharpInheritFunc() =
inherit TestFSharpFunc()
[<Fact>]
let ``Creation of a bound value succeeds if the value is a type that inherits FSharpFunc`` () =
use fsiSession = createFsiSession false
fsiSession.AddBoundValue("test", Test2FSharpInheritFunc())
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<Test2FSharpInheritFunc> boundValue.Value.ReflectionType
[<Fact>]
let ``Creation of a bound value succeeds if the value is an array of a built-in value type``() =
use fsiSession = createFsiSession false
let arr = [|0; 1|]
fsiSession.AddBoundValue("boundMdArray", arr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<int[]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(arr, "") |> ignore
[<Fact>]
let ``Creation of a bound value succeeds if the value is an array of a built-in reference type``() =
use fsiSession = createFsiSession false
let arr = [|"zero"; "one"|]
fsiSession.AddBoundValue("boundMdArray", arr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<string[]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(arr, "") |> ignore
[<Fact>]
let ``Creation of a bound value succeeds if the value is an array of a custom value type``() =
use fsiSession = createFsiSession false
let arr = [|CustomStruct(1)|]
fsiSession.AddBoundValue("boundMdArray", arr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<CustomStruct[]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(arr, "") |> ignore
[<Fact>]
let ``Creation of a bound value succeeds if the value is an array of a custom reference type``() =
use fsiSession = createFsiSession false
let arr = [|CustomType2()|]
fsiSession.AddBoundValue("boundMdArray", arr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<CustomType2[]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(arr, "") |> ignore
[<Fact>]
let ``Creation of a bound value succeeds if the value is a multidimensional array of a built-in value type``() =
use fsiSession = createFsiSession false
let mdArr = array2D [[1; 0]; [0; 1]]
fsiSession.AddBoundValue("boundMdArray", mdArr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<int[,]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(mdArr, "") |> ignore
[<Fact>]
let ``Creation of a bound value succeeds if the value is a multidimensional array of a built-in reference type``() =
use fsiSession = createFsiSession false
let mdArr = array2D [["one"; "zero"]; ["zero"; "one"]]
fsiSession.AddBoundValue("boundMdArray", mdArr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<string[,]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(mdArr, "") |> ignore
[<Fact>]
let ``Creation of a bound value succeeds if the value is a multidimensional array of a custom value type``() =
use fsiSession = createFsiSession false
let mdArr = array2D [[CustomStruct(1); CustomStruct(1)]; [CustomStruct(1); CustomStruct(1)]]
fsiSession.AddBoundValue("boundMdArray", mdArr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<CustomStruct[,]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(mdArr, "") |> ignore
[<Fact>]
let ``Creation of a bound value succeeds if the value is a multidimensional array of a custom reference type``() =
use fsiSession = createFsiSession false
let mdArr = array2D [[CustomType2(); CustomType2()]; [CustomType2(); CustomType2()]]
fsiSession.AddBoundValue("boundMdArray", mdArr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<CustomType2[,]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(mdArr, "") |> ignore
[<TheoryForNETCOREAPP>]
[<InlineData(true)>]
[<InlineData(false)>]
let ``Evaluating simple reference and code succeeds``(useOneDynamicAssembly:bool) =
use fsiSession = createFsiSession useOneDynamicAssembly
let assemblyPath = typeof<Sentinel>.Assembly.Location.Replace("\\", "/")
let res, errors = fsiSession.EvalInteractionNonThrowing($"""
#r "{assemblyPath}"
FSharp.Compiler.Service.Tests.MyModule.test(3)""")
errors
|> Array.iter (fun e -> printfn "error: %A" e)
match res with
| Choice1Of2 v ->
let v =
match v with
| Some v -> sprintf "%A" v.ReflectionValue
| None -> "(none)"
printfn "value: %A" v
| Choice2Of2 e ->
printfn "exception: %A" e
raise e