-
Notifications
You must be signed in to change notification settings - Fork 156
/
Tests.fs
2721 lines (2541 loc) · 72.6 KB
/
Tests.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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module FsAutoComplete.Tests.CodeFixTests.Tests
open Expecto
open Helpers
open Utils.ServerTests
open Utils.CursorbasedTests
open Ionide.LanguageServerProtocol.Types
open FsAutoComplete.CodeFix
let private addMissingEqualsToTypeDefinitionTests state =
serverTestList (nameof AddMissingEqualsToTypeDefinition) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle AddMissingEqualsToTypeDefinition.title
testCaseAsync "can add = to record def" <|
CodeFix.check server
"""
type Person $0{ Name : string; Age : int; City : string }
"""
(Diagnostics.expectCode "3360")
selectCodeFix
"""
type Person = { Name : string; Age : int; City : string }
"""
testCaseAsync "can add = to union def" <|
CodeFix.check server
"""
type Name $0Name of string
"""
(Diagnostics.expectCode "3360")
selectCodeFix
"""
type Name = Name of string
"""
])
let private addMissingFunKeywordTests state =
serverTestList (nameof AddMissingFunKeyword) state defaultConfigDto None (fun server -> [
testCaseAsync "can generate the fun keyword when error 10 is raised" <|
CodeFix.check server
"""
let doThing = x $0-> printfn "%s" x
"""
(Diagnostics.expectCode "10")
(CodeFix.ofKind "quickfix" >> CodeFix.withTitle AddMissingFunKeyword.title)
"""
let doThing = fun x -> printfn "%s" x
"""
])
let private addMissingInstanceMemberTests state =
serverTestList (nameof AddMissingInstanceMember) state defaultConfigDto None (fun server -> [
testCaseAsync "can add this member prefix" <|
CodeFix.check server
"""
type C () =
member $0Foo() = ()
"""
(Diagnostics.expectCode "673")
(CodeFix.ofKind "quickfix" >> CodeFix.withTitle AddMissingInstanceMember.title)
"""
type C () =
member x.Foo() = ()
"""
])
let private addMissingRecKeywordTests state =
serverTestList (nameof AddMissingRecKeyword) state defaultConfigDto None (fun server -> [
// `rec` in single function is handled in `MakeOuterBindingRecursive`
testCaseAsync "can add rec to mutual recursive function" <|
CodeFix.check server
"""
$0let a x = x
and b x = x
"""
(Diagnostics.expectCode "576")
(CodeFix.withTitle (AddMissingRecKeyword.title "a"))
"""
let rec a x = x
and b x = x
"""
])
let private addNewKeywordToDisposableConstructorInvocationTests state =
serverTestList (nameof AddNewKeywordToDisposableConstructorInvocation) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle AddNewKeywordToDisposableConstructorInvocation.title
testCaseAsync "can add new to Disposable" <|
CodeFix.check server
"""
open System.Threading.Tasks
let _ = $0Task<int>(fun _ -> 1)
"""
(Diagnostics.expectCode "760")
selectCodeFix
"""
open System.Threading.Tasks
let _ = new Task<int>(fun _ -> 1)
"""
testCaseAsync "can add new to Disposable with namespace" <|
CodeFix.check server
"""
let _ = System.Threading.Tasks.$0Task<int>(fun _ -> 1)
"""
(Diagnostics.expectCode "760")
selectCodeFix
"""
let _ = new System.Threading.Tasks.Task<int>(fun _ -> 1)
"""
testCaseAsync "doesn't trigger for not Disposable" <|
CodeFix.checkNotApplicable server
"""
let _ = System.$0String('.', 3)
"""
Diagnostics.acceptAll
selectCodeFix
])
let private addTypeToIndeterminateValueTests state =
serverTestList (nameof AddTypeToIndeterminateValue) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle AddTypeToIndeterminateValue.title
testCaseAsync "can add type annotation to error 72 ('Lookup on object of indeterminate type')" <|
CodeFix.check server
"""
let data = [
{| Name = "foo"; Value = 42 |}
{| Name = "bar"; Value = 13 |}
]
let res = List.filter (fun d -> $0d.Value > 20) data
"""
(Diagnostics.expectCode "72")
selectCodeFix
"""
let data = [
{| Name = "foo"; Value = 42 |}
{| Name = "bar"; Value = 13 |}
]
let res = List.filter (fun (d: {| Name: string; Value: int |}) -> d.Value > 20) data
"""
testCaseAsync "can add type annotation to error 3245 ('The input to a copy-and-update expression that creates an anonymous record must be either an anonymous record or a record')" <|
CodeFix.check server
"""
[1..5]
|> List.fold
(fun s i ->
match i % 2 with
| 0 -> {| $0s with Evens = s.Evens + 1 |}
| _ -> s
)
{| Evens = 0 |}
"""
(Diagnostics.expectCode "3245")
selectCodeFix
"""
[1..5]
|> List.fold
(fun (s: {| Evens: int |}) i ->
match i % 2 with
| 0 -> {| s with Evens = s.Evens + 1 |}
| _ -> s
)
{| Evens = 0 |}
"""
])
let private changeDerefBangToValueTests state =
serverTestList (nameof ChangeDerefBangToValue) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle ChangeDerefBangToValue.title
testCaseAsync "can replace ! with .Value" <|
CodeFix.check server
"""
let rv = ref 5
let v = $0!rv
"""
(Diagnostics.expectCode "3370")
selectCodeFix
"""
let rv = ref 5
let v = rv.Value
"""
testCaseAsync "can replace ! with .Value when parens" <|
CodeFix.check server
"""
let rv = ref 5
let v = $0!(rv)
"""
(Diagnostics.expectCode "3370")
selectCodeFix
"""
let rv = ref 5
let v = (rv).Value
"""
testCaseAsync "can replace ! with .Value when function in parens" <|
CodeFix.check server
"""
let fr a = ref a
let v = $0!(fr 5)
"""
(Diagnostics.expectCode "3370")
selectCodeFix
"""
let fr a = ref a
let v = (fr 5).Value
"""
testCaseAsync "can replace ! with .Value when space between ! and variable" <|
CodeFix.check server
"""
let rv = ref 5
let v = $0! rv
"""
(Diagnostics.expectCode "3370")
selectCodeFix
"""
let rv = ref 5
let v = rv.Value
"""
testCaseAsync "can replace ! with .Value when when parens and space between ! and variable" <|
CodeFix.check server
"""
let rv = ref 5
let v = $0! (rv)
"""
(Diagnostics.expectCode "3370")
selectCodeFix
"""
let rv = ref 5
let v = (rv).Value
"""
])
let private changeDowncastToUpcastTests state =
serverTestList (nameof ChangeDowncastToUpcast) state defaultConfigDto None (fun server -> [
let selectOperatorCodeFix = CodeFix.withTitle ChangeDowncastToUpcast.titleUpcastOperator
let selectFunctionCodeFix = CodeFix.withTitle ChangeDowncastToUpcast.titleUpcastFunction
testCaseAsync "can change :?> to :>" <|
CodeFix.check server
"""
type I = interface end
type C() = interface I
let v: I = C() $0:?> I
"""
(Diagnostics.expectCode "3198")
selectOperatorCodeFix
"""
type I = interface end
type C() = interface I
let v: I = C() :> I
"""
testCaseAsync "can change downcast to upcast" <|
CodeFix.check server
"""
type I = interface end
type C() = interface I
let v: I = $0downcast C()
"""
(Diagnostics.expectCode "3198")
selectFunctionCodeFix
"""
type I = interface end
type C() = interface I
let v: I = upcast C()
"""
()
])
let private changeEqualsInFieldTypeToColonTests state =
serverTestList (nameof ChangeEqualsInFieldTypeToColon) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle ChangeEqualsInFieldTypeToColon.title
testCaseAsync "can change = to : in single line" <|
CodeFix.check server
"""
type A = { Name : string; Key $0= int }
"""
(Diagnostics.expectCode "10")
selectCodeFix
"""
type A = { Name : string; Key : int }
"""
testCaseAsync "can change = to : in multi line" <|
CodeFix.check server
"""
type A = {
Name : string
Key $0= int
}
"""
(Diagnostics.expectCode "10")
selectCodeFix
"""
type A = {
Name : string
Key : int
}
"""
])
let private changePrefixNegationToInfixSubtractionTests state =
serverTestList (nameof ChangePrefixNegationToInfixSubtraction) state defaultConfigDto None (fun server -> [
testCaseAsync "converts negation to subtraction" <|
CodeFix.check server
"""
let getListWithoutFirstAndLastElement list =
let l = List.length list
list[ 1 .. $0l -1 ]
"""
(Diagnostics.expectCode "3")
(CodeFix.ofKind "quickfix" >> CodeFix.withTitle ChangePrefixNegationToInfixSubtraction.title)
"""
let getListWithoutFirstAndLastElement list =
let l = List.length list
list[ 1 .. l - 1 ]
"""
])
let private changeRefCellDerefToNotTests state =
serverTestList (nameof ChangeRefCellDerefToNot) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle ChangeRefCellDerefToNot.title
testCaseAsync "can change simple deref to not" <|
CodeFix.check server
"""
let x = 1
!$0x
"""
(Diagnostics.expectCode "1")
selectCodeFix
"""
let x = 1
not x
"""
testCaseAsync "can change simple deref with parens to not" <|
CodeFix.check server
"""
let x = 1
!($0x)
"""
(Diagnostics.expectCode "1")
selectCodeFix
"""
let x = 1
not (x)
"""
testCaseAsync "can change deref of binary expr to not" <|
CodeFix.check server
"""
let x = 1
!($0x = false)
"""
(Diagnostics.expectCode "1")
selectCodeFix
"""
let x = 1
not (x = false)
"""
])
let private changeTypeOfNameToNameOfTests state =
serverTestList (nameof ChangeTypeOfNameToNameOf) state defaultConfigDto None (fun server -> [
testCaseAsync "can suggest fix" <|
CodeFix.check server
"""
let x = $0typeof<Async<string>>.Name
"""
(Diagnostics.acceptAll)
(CodeFix.ofKind "refactor" >> CodeFix.withTitle ChangeTypeOfNameToNameOf.title)
"""
let x = nameof(Async<string>)
"""
])
let private convertBangEqualsToInequalityTests state =
serverTestList (nameof ConvertBangEqualsToInequality) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle ConvertBangEqualsToInequality.title
testCaseAsync "can change != to <>" <|
CodeFix.check server
"""
1 $0!= 2
"""
(Diagnostics.expectCode "43")
selectCodeFix
"""
1 <> 2
"""
])
let private convertCSharpLambdaToFSharpLambdaTests state =
serverTestList (nameof ConvertCSharpLambdaToFSharpLambda) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle ConvertCSharpLambdaToFSharpLambda.title
testCaseAsync "can convert csharp lambda in variable assignment with cursor on input" <|
CodeFix.check server
"""
let x = $0y => 1 + y
"""
Diagnostics.acceptAll
selectCodeFix
"""
let x = fun y -> 1 + y
"""
testCaseAsync "can convert csharp lambda in variable assignment with cursor on usage" <|
CodeFix.check server
"""
let x = y => 1 + $0y
"""
Diagnostics.acceptAll
selectCodeFix
"""
let x = fun y -> 1 + y
"""
//ENHANCEMENT: trigger on `=>`
itestCaseAsync "can convert csharp lambda in variable assignment with cursor on =>" <|
CodeFix.check server
"""
let x = y $0=> 1 + y
"""
Diagnostics.acceptAll
selectCodeFix
"""
let x = fun y -> 1 + y
"""
testCaseAsync "can convert csharp lambda in lambda with parens with cursor on input" <|
CodeFix.check server
"""
[1..10] |> List.map ($0x => 1 + x)
"""
Diagnostics.acceptAll
selectCodeFix
"""
[1..10] |> List.map (fun x -> 1 + x)
"""
testCaseAsync "can convert csharp lambda in lambda with parens with cursor on usage" <|
CodeFix.check server
"""
[1..10] |> List.map (x => 1 + $0x)
"""
Diagnostics.acceptAll
selectCodeFix
"""
[1..10] |> List.map (fun x -> 1 + x)
"""
testCaseAsync "keep multi-line lambda intact - cursor on input" <|
CodeFix.check server
"""
let x =
$0y =>
let a = 1 + y
a
"""
Diagnostics.acceptAll
selectCodeFix
"""
let x =
fun y ->
let a = 1 + y
a
"""
testCaseAsync "keep multi-line lambda intact - cursor on usage" <|
CodeFix.check server
"""
let x =
y =>
let a = 1 + $0y
a
"""
Diagnostics.acceptAll
selectCodeFix
"""
let x =
fun y ->
let a = 1 + y
a
"""
])
let private convertDoubleEqualsToSingleEqualsTests state =
serverTestList (nameof ConvertDoubleEqualsToSingleEquals) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle ConvertDoubleEqualsToSingleEquals.title
testCaseAsync "can replace == with =" <|
CodeFix.check server
"""
1 $0== 1
"""
(Diagnostics.expectCode "43")
selectCodeFix
"""
1 = 1
"""
testCaseAsync "doesn't replace existing operator == with =" <|
CodeFix.checkNotApplicable server
"""
let (==) a b = a = b
1 $0== 1
"""
Diagnostics.acceptAll
selectCodeFix
])
let private convertInvalidRecordToAnonRecordTests state =
serverTestList (nameof ConvertInvalidRecordToAnonRecord) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle ConvertInvalidRecordToAnonRecord.title
testCaseAsync "can convert single-line record with single field" <|
CodeFix.check server
"""
let v = { $0Name = "foo" }
"""
(Diagnostics.expectCode "39")
selectCodeFix
"""
let v = {| Name = "foo" |}
"""
testCaseAsync "can convert single-line record with two fields" <|
CodeFix.check server
"""
let v = { $0Name = "foo"; Value = 42 }
"""
(Diagnostics.expectCode "39")
selectCodeFix
"""
let v = {| Name = "foo"; Value = 42 |}
"""
testCaseAsync "can convert multi-line record with two fields" <|
CodeFix.check server
"""
let v = {
$0Name = "foo"
Value = 42
}
"""
(Diagnostics.expectCode "39")
selectCodeFix
"""
let v = {|
Name = "foo"
Value = 42
|}
"""
testCaseAsync "doesn't trigger for existing record" <|
CodeFix.checkNotApplicable server
"""
type V = { Name: string; Value: int }
let v = { $0Name = "foo"; Value = 42 }
"""
(Diagnostics.acceptAll)
selectCodeFix
testCaseAsync "doesn't trigger for anon record" <|
CodeFix.checkNotApplicable server
"""
let v = {| $0Name = "foo"; Value = 42 |}
"""
(Diagnostics.acceptAll)
selectCodeFix
])
let private convertPositionalDUToNamedTests state =
serverTestList (nameof ConvertPositionalDUToNamed) state defaultConfigDto None (fun server -> [
let selectCodeFix = CodeFix.withTitle ConvertPositionalDUToNamed.title
testCaseAsync "in parenthesized let binding" <|
CodeFix.check server
"""
type A = A of a: int * b: bool
let (A(a$0, b)) = A(1, true)
"""
Diagnostics.acceptAll
selectCodeFix
"""
type A = A of a: int * b: bool
let (A(a = a; b = b;)) = A(1, true)
"""
testCaseAsync "in simple match" <|
CodeFix.check server
"""
type A = A of a: int * b: bool
match A(1, true) with
| A(_, false) -> ()
| A(a$0, b) -> ()
"""
Diagnostics.acceptAll
selectCodeFix
"""
type A = A of a: int * b: bool
match A(1, true) with
| A(_, false) -> ()
| A(a = a; b = b;) -> ()
"""
testCaseAsync "in parenthesized match" <|
CodeFix.check server
"""
type A = A of a: int * b: bool
match A(1, true) with
| (A(_, false)) -> ()
| (A(a$0, b)) -> ()
"""
Diagnostics.acceptAll
selectCodeFix
"""
type A = A of a: int * b: bool
match A(1, true) with
| (A(_, false)) -> ()
| (A(a = a; b = b;)) -> ()
"""
testCaseAsync "when there is one new field on the DU" <|
CodeFix.check server
"""
type ThirdFieldWasJustAdded = ThirdFieldWasJustAdded of a: int * b: bool * c: char
let (ThirdFieldWasJustAdded($0a, b)) = ThirdFieldWasJustAdded(1, true, 'c')
"""
Diagnostics.acceptAll
selectCodeFix
"""
type ThirdFieldWasJustAdded = ThirdFieldWasJustAdded of a: int * b: bool * c: char
let (ThirdFieldWasJustAdded(a = a; b = b; c = _;)) = ThirdFieldWasJustAdded(1, true, 'c')
"""
testCaseAsync "when there are multiple new fields on the DU" <|
CodeFix.check server
"""
type U = U of aValue: int * boolean: int * char: char * dec: decimal * element: int
let (U($0a, b)) = failwith "..."
"""
Diagnostics.acceptAll
selectCodeFix
"""
type U = U of aValue: int * boolean: int * char: char * dec: decimal * element: int
let (U(aValue = a; boolean = b; char = _; dec = _; element = _;)) = failwith "..."
"""
testCaseAsync "when the existing pattern isn't formatted well" <|
CodeFix.check server
"""
type A = A of a: int * b: bool * c: bool * d: bool
let (A($0a,b, c, d)) = A(1, true, false, false)
"""
Diagnostics.acceptAll
selectCodeFix
"""
type A = A of a: int * b: bool * c: bool * d: bool
let (A(a = a;b = b; c = c; d = d;)) = A(1, true, false, false)
"""
testCaseAsync "when there are multiple SynLongIdent Pats" <|
CodeFix.check server
"""
type MyDiscUnion = Case1 of field1: int * field2: int
type MyC() =
let x = Case1 (1, 2)
member _.Func2 () =
match x with
| Case1(3$0, 4) -> ()
| _ -> ()
"""
Diagnostics.acceptAll
selectCodeFix
"""
type MyDiscUnion = Case1 of field1: int * field2: int
type MyC() =
let x = Case1 (1, 2)
member _.Func2 () =
match x with
| Case1(field1 = 3; field2 = 4;) -> ()
| _ -> ()
"""
testCaseAsync "when surrounding function takes union parameter" <|
CodeFix.check server
"""
type MyDiscUnion = X of field1: int * field2: int
let f () =
let x = X (1, 2)
match x with
| X(32$0, 23) -> ()
| _ -> ()
"""
Diagnostics.acceptAll
selectCodeFix
"""
type MyDiscUnion = X of field1: int * field2: int
let f () =
let x = X (1, 2)
match x with
| X(field1 = 32; field2 = 23;) -> ()
| _ -> ()
"""
])
let private addPrivateAccessModifierTests state =
let config = { defaultConfigDto with AddPrivateAccessModifier = Some true }
serverTestList (nameof AddPrivateAccessModifier) state config None (fun server ->
[ let selectCodeFix = CodeFix.withTitle AddPrivateAccessModifier.title
testCaseAsync "add private works for simple function"
<| CodeFix.check
server
"""
let f$0 x = x * x
"""
Diagnostics.acceptAll
selectCodeFix
"""
let private f x = x * x
"""
testCaseAsync "add private works for simple identifier"
<| CodeFix.check
server
"""
let x$0 = 23
"""
Diagnostics.acceptAll
selectCodeFix
"""
let private x = 23
"""
testCaseAsync "add private works for simple identifier used in other private function"
<| CodeFix.check
server
"""
module PMod =
let xx$0x = 10
module PMod2 =
let insidePMod2 = 23
let private a = 23
let private g z =
let sF y = y + xxx
z
"""
Diagnostics.acceptAll
selectCodeFix
"""
module PMod =
let private xxx = 10
module PMod2 =
let insidePMod2 = 23
let private a = 23
let private g z =
let sF y = y + xxx
z
"""
testCaseAsync "add private is not offered for already private functions"
<| CodeFix.checkNotApplicable
server
"""
let private f$0 x = x * x
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for function with reference outside its declaring module"
<| CodeFix.checkNotApplicable
server
"""
module MyModule =
let helper x = x + 10
let $0f x = helper x
MyModule.f 10
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private works for class type definition"
<| CodeFix.check
server
"""
type [<System.Obsolete>] MyCla$0ss() =
member _.X = 10
"""
Diagnostics.acceptAll
selectCodeFix
"""
type [<System.Obsolete>] private MyClass() =
member _.X = 10
"""
testCaseAsync "add private is not offered for class type definition with reference"
<| CodeFix.checkNotApplicable
server
"""
type MyCla$0ss() =
member _.X = 10
let _ = MyClass()
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for explicit ctor" // ref finding might not show us usages
<| CodeFix.checkNotApplicable
server
"""
type MyC(x: int) =
ne$0w() =
MyC(23)
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for member with reference outside its declaring class"
<| CodeFix.checkNotApplicable
server
"""
type MyClass() =
member _.$0X = 10
let myInst = MyClass()
myInst.X |> ignore
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for member with reference outside its declaring class when caret is on thisValue"
<| CodeFix.checkNotApplicable
server
"""
type MyClass() =
member _$0.X = 10
let myInst = MyClass()
myInst.X |> ignore
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for member when caret is in SynTypArDecl"
<| CodeFix.checkNotApplicable
server
"""
type MyC() =
member _.X<'T$0> a = a
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for class member when caret is on parameter"
<| CodeFix.checkNotApplicable
server
"""
type MyClass() =
member _.Func x$0 = x
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for let bindings inside a class"
<| CodeFix.checkNotApplicable
server
"""
type MyClass() =
let $0f x = x * x
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private works for class member"
<| CodeFix.check
server
"""
type MyClass() =
member _.$0X = 10
"""
Diagnostics.acceptAll
selectCodeFix
"""
type MyClass() =
member private _.X = 10
"""
testCaseAsync "add private works for autoproperty"
<| CodeFix.check
server
"""
type MyClass() =
member val Name$0 = "" with get, set
"""
Diagnostics.acceptAll
selectCodeFix
"""
type MyClass() =
member val private Name = "" with get, set
"""
testCaseAsync "add private is not offered for autoproperty with references outside its class"
<| CodeFix.checkNotApplicable
server
"""
type MyClass() =
member val Name$0 = "" with get, set
let myInst = MyClass()
myInst.Name |> ignore
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for DU type definition" // ref finding might not show us type inferred usages
<| CodeFix.checkNotApplicable
server
"""
type [<System.Obsolete>] MyDi$0scUnion =
| Case1
| Case2
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for member with reference outside its declaring DU"
<| CodeFix.checkNotApplicable
server
"""
type MyDiscUnion =
| Case1
| Case2
with
member _.F$0oo x = x
let x = MyDiscUnion.Case1
x.Foo 10
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for member with reference outside its declaring DU when caret is on thisValue"
<| CodeFix.checkNotApplicable
server
"""
type MyDiscUnion =
| Case1
| Case2
with
member $0_.Foo x = x
let x = MyDiscUnion.Case1
x.Foo 10
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private is not offered for DU member when caret is on parameter"
<| CodeFix.checkNotApplicable
server
"""
type MyDiscUnion =
| Case1
| Case2
with
member _.Foo $0x = x
"""
Diagnostics.acceptAll
selectCodeFix
testCaseAsync "add private works for DU member"
<| CodeFix.check
server
"""
type MyDiscUnion =
| Case1
| Case2
with
member _.Fo$0o x = x
"""
Diagnostics.acceptAll
selectCodeFix
"""
type MyDiscUnion =
| Case1
| Case2
with
member private _.Foo x = x
"""
testCaseAsync "add private is not offered for Record type definition" // ref finding might not show us type inferred usages
<| CodeFix.checkNotApplicable
server
"""
type [<System.Obsolete>] My$0Record =
{ Field1: int
Field2: string }
"""