-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathTests.hs
More file actions
1310 lines (1218 loc) · 35.9 KB
/
Tests.hs
File metadata and controls
1310 lines (1218 loc) · 35.9 KB
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
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
module Language.Haskell.Stylish.Step.Data.Tests
( tests
) where
import Language.Haskell.Stylish.Step.Data
import Language.Haskell.Stylish.Tests.Util (assertSnippet, testStep)
import Test.Framework (Test, testGroup)
import Test.Framework.Providers.HUnit (testCase)
import Test.HUnit (Assertion, (@=?))
tests :: Test
tests = testGroup "Language.Haskell.Stylish.Step.Data.Tests"
[ testCase "case 00" case00
, testCase "case 01" case01
, testCase "case 02" case02
, testCase "case 03" case03
, testCase "case 04" case04
, testCase "case 05" case05
, testCase "case 06" case06
, testCase "case 07" case07
, testCase "case 08" case08
, testCase "case 09" case09
, testCase "case 10" case10
, testCase "case 11" case11
, testCase "case 12" case12
, testCase "case 13" case13
, testCase "case 14" case14
, testCase "case 15" case15
, testCase "case 16" case16
, testCase "case 17" case17
, testCase "case 18" case18
, testCase "case 19" case19
, testCase "case 20 (issue 262)" case20
, testCase "case 21" case21
, testCase "case 22" case22
, testCase "case 23" case23
, testCase "case 24" case24
, testCase "case 25" case25
, testCase "case 26" case26
, testCase "case 27" case27
, testCase "case 28" case28
, testCase "case 29" case29
, testCase "case 30" case30
, testCase "case 31" case31
, testCase "case 32" case32
, testCase "case 33" case33
, testCase "case 34" case34
, testCase "case 35" case35
, testCase "case 36" case36
, testCase "case 37" case37
, testCase "case 38" case38
, testCase "case 39" case39
, testCase "case 40" case40
, testCase "case 41" case41
, testCase "case 42" case42
, testCase "case 43" case43
, testCase "case 44" case44
, testCase "case 45" case45
, testCase "case 46" case46
, testCase "case 47" case47
, testCase "case 48" case48
, testCase "case 49" case49
, testCase "case 50" case50
, testCase "case 51" case51
, testCase "case 52" case52
, testCase "case 53" case53
, testCase "case 54" case54
, testCase "case 55" case55
, testCase "case 56" case56
, testCase "case 57" case57
, testCase "case 58" case58
]
case00 :: Assertion
case00 = expected @=? testStep (step sameSameStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo"
]
expected = input
case01 :: Assertion
case01 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo = Foo { a :: Int }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo"
, " = Foo"
, " { a :: Int"
, " }"
]
case02 :: Assertion
case02 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo = Foo { a :: Int, a2 :: String }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo"
, " = Foo"
, " { a :: Int"
, " , a2 :: String"
, " }"
]
case03 :: Assertion
case03 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo a = Foo { a :: a, a2 :: String }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo a"
, " = Foo"
, " { a :: a"
, " , a2 :: String"
, " }"
]
case04 :: Assertion
case04 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo a = Foo { a :: a, a2 :: String } | Bar { b :: a }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo a"
, " = Foo"
, " { a :: a"
, " , a2 :: String"
, " }"
, " | Bar"
, " { b :: a"
, " }"
]
case05 :: Assertion
case05 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo = Foo {"
, " a :: Int"
, " , a2 :: String"
, " }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo"
, " = Foo"
, " { a :: Int"
, " , a2 :: String"
, " }"
]
case06 :: Assertion
case06 = expected @=? testStep (step sameSameStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo = Foo Int String"
]
expected = input
case07 :: Assertion
case07 = expected @=? testStep (step sameSameStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Phantom a = Phantom"
]
expected = input
case08 :: Assertion
case08 = expected @=? testStep (step sameSameStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Phantom a ="
, " Phantom"
]
expected = unlines
[ "module Herp where"
, ""
, "data Phantom a = Phantom"
]
case09 :: Assertion
case09 = expected @=? testStep (step indentIndentStyle4) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo a b = Foo { a :: a, a2 :: String } | Bar { b :: a, c:: b }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo a b"
, " = Foo"
, " { a :: a"
, " , a2 :: String"
, " }"
, " | Bar"
, " { b :: a"
, " , c :: b"
, " }"
]
case10 :: Assertion
case10 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo = Foo { a :: Int } deriving (Eq, Generic) deriving (Show)"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo"
, " = Foo"
, " { a :: Int"
, " }"
, " deriving (Eq, Generic)"
, " deriving (Show)"
]
case11 :: Assertion
case11 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "{-# LANGUAGE DerivingStrategies #-}"
, "module Herp where"
, ""
, "data Foo = Foo { a :: Int } deriving stock (Show)"
]
expected = unlines
[ "{-# LANGUAGE DerivingStrategies #-}"
, "module Herp where"
, ""
, "data Foo"
, " = Foo"
, " { a :: Int"
, " }"
, " deriving stock (Show)"
]
case12 :: Assertion
case12 = expected @=? testStep (step indentIndentStyle4) input
where
input = unlines
[ "module Herp where"
, ""
, "data Point = Point { pointX, pointY :: Double , pointName :: String} deriving (Show)"
]
expected = unlines
[ "module Herp where"
, ""
, "data Point"
, " = Point"
, " { pointX, pointY :: Double"
, " , pointName :: String"
, " }"
, " deriving (Show)"
]
case13 :: Assertion
case13 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "-- this is a comment"
, "data Foo = Foo { a :: Int }"
]
expected = unlines
[ "module Herp where"
, ""
, "-- this is a comment"
, "data Foo"
, " = Foo"
, " { a :: Int"
, " }"
]
case14 :: Assertion
case14 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "{- this is"
, " a comment -}"
, "data Foo = Foo { a :: Int }"
]
expected = unlines
[ "module Herp where"
, ""
, "{- this is"
, " a comment -}"
, "data Foo"
, " = Foo"
, " { a :: Int"
, " }"
]
case15 :: Assertion
case15 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo a = Foo"
, " { a :: a, -- comment"
, " a2 :: String"
, " }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo a"
, " = Foo"
, " { a :: a -- comment"
, " , a2 :: String"
, " }"
]
case16 :: Assertion
case16 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo = Foo {"
, " a :: Int -- ^ comment"
, " }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo"
, " = Foo"
, " { a :: Int"
, " -- ^ comment"
, " }"
]
case17 :: Assertion
case17 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo a = Foo"
, " { a :: a,"
, "-- comment"
, " a2 :: String"
, " }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo a"
, " = Foo"
, " { a :: a"
, " -- comment"
, " , a2 :: String"
, " }"
]
case18 :: Assertion
case18 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo a = Foo"
, " { a :: a,"
, "-- ^ comment"
, " a2 :: String"
, " }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo a"
, " = Foo"
, " { a :: a"
, " -- ^ comment"
, " , a2 :: String"
, " }"
]
case19 :: Assertion
case19 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo a = Foo"
, " { firstName, lastName :: String,"
, "-- ^ names"
, " age :: Int"
, " }"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo a"
, " = Foo"
, " { firstName, lastName :: String"
, " -- ^ names"
, " , age :: Int"
, " }"
]
-- | Should not break Enums (data without records) formatting
--
-- See https://github.com/jaspervdj/stylish-haskell/issues/262
case20 :: Assertion
case20 = input @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Tag = Title | Text deriving (Eq, Show)"
]
case21 :: Assertion
case21 = assertSnippet (step sameSameStyle)
[ "data Foo a"
, " = Foo { a :: Int,"
, " a2 :: String"
, " -- ^ some haddock"
, " }"
, " | Bar { b :: a } deriving (Eq, Show)"
, " deriving (ToJSON)"
]
[ "data Foo a = Foo { a :: Int"
, " , a2 :: String"
, " -- ^ some haddock"
, " }"
, " | Bar { b :: a"
, " }"
, " deriving (Eq, Show)"
, " deriving (ToJSON)"
]
case22 :: Assertion
case22 = assertSnippet (step sameIndentStyle)
[ "data Foo a"
, " = Foo { a :: Int,"
, " a2 :: String"
, " -- ^ some haddock"
, " }"
, " | Bar { b :: a } deriving (Eq, Show)"
, " deriving (ToJSON)"
]
[ "data Foo a = Foo"
, " { a :: Int"
, " , a2 :: String"
, " -- ^ some haddock"
, " }"
, " | Bar"
, " { b :: a"
, " }"
, " deriving (Eq, Show)"
, " deriving (ToJSON)"
]
case23 :: Assertion
case23 = assertSnippet (step indentSameStyle)
[ "data Foo a"
, " = Foo { a :: Int,"
, " a2 :: String"
, " -- ^ some haddock"
, " }"
, " | Bar { b :: a } deriving (Eq, Show)"
, " deriving (ToJSON)"
]
[ "data Foo a"
, " = Foo { a :: Int"
, " , a2 :: String"
, " -- ^ some haddock"
, " }"
, " | Bar { b :: a"
, " }"
, " deriving (Eq, Show)"
, " deriving (ToJSON)"
]
case24 :: Assertion
case24 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "data Foo a"
, " = Foo { a :: Int,"
, " a2 :: String"
, " -- ^ some haddock"
, " }"
, " | Bar { b :: a } deriving (Eq, Show)"
, " deriving (ToJSON)"
]
expected = unlines
[ "data Foo a"
, " = Foo"
, " { a :: Int"
, " , a2 :: String"
, " -- ^ some haddock"
, " }"
, " | Bar"
, " { b :: a"
, " }"
, " deriving (Eq, Show)"
, " deriving (ToJSON)"
]
case25 :: Assertion
case25 = expected @=? testStep (step indentIndentStyle { cBreakSingleConstructors = False }) input
where
input = unlines
[ "data Foo a"
, " = Foo { a :: Int,"
, " a2 :: String"
, " -- ^ some haddock"
, " }"
, " deriving (Eq, Show)"
, " deriving (ToJSON)"
]
expected = unlines
[ "data Foo a = Foo"
, " { a :: Int"
, " , a2 :: String"
, " -- ^ some haddock"
, " }"
, " deriving (Eq, Show)"
, " deriving (ToJSON)"
]
case26 :: Assertion
case26 = expected @=? testStep (step indentIndentStyle) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo = Foo { a :: Int } deriving (FromJSON) via Bla Foo"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo"
, " = Foo"
, " { a :: Int"
, " }"
, " deriving (FromJSON) via Bla Foo"
]
case27 :: Assertion
case27 = expected @=? testStep (step sameIndentStyle { cBreakEnums = True }) input
where
input = unlines
[ "module Herp where"
, ""
, "data Foo = Foo | Bar | Baz deriving (Eq, Show)"
]
expected = unlines
[ "module Herp where"
, ""
, "data Foo"
, " = Foo"
, " | Bar"
, " | Baz"
, " deriving (Eq, Show)"
]
case28 :: Assertion
case28 = expected @=? testStep (step sameIndentStyle { cBreakEnums = True }) input
where
input = unlines
[ "module Some.Types where"
, ""
, "newtype BankCode = BankCode {"
, " unBankCode :: Text"
, " }"
, " deriving stock (Generic, Eq, Show)"
, " deriving anyclass (Newtype)"
, ""
, "newtype CheckDigit = CheckDigit { unCheckDigit :: Text }"
, " deriving stock (Generic, Eq, Show)"
, " deriving anyclass (Newtype)"
, ""
, "newtype WrappedInt = WrappedInt Int"
, " deriving stock (Generic, Eq, Show)"
, " deriving anyclass (Newtype)"
, ""
, "data MandateStatus"
, " = Approved"
, " | Failed"
, " | UserCanceled"
, " | Inactive"
, " deriving stock (Generic, Show, Eq, Enum, Bounded)"
, " deriving (ToJSON, FromJSON) via SnakeCaseCapsEnumEncoding MandateStatus"
]
expected = unlines
[ "module Some.Types where"
, ""
, "newtype BankCode = BankCode { unBankCode :: Text }"
, " deriving stock (Eq, Generic, Show)"
, " deriving anyclass (Newtype)"
, ""
, "newtype CheckDigit = CheckDigit { unCheckDigit :: Text }"
, " deriving stock (Eq, Generic, Show)"
, " deriving anyclass (Newtype)"
, ""
, "newtype WrappedInt = WrappedInt Int"
, " deriving stock (Eq, Generic, Show)"
, " deriving anyclass (Newtype)"
, ""
, "data MandateStatus"
, " = Approved"
, " | Failed"
, " | UserCanceled"
, " | Inactive"
, " deriving stock (Bounded, Enum, Eq, Generic, Show)"
, " deriving (FromJSON, ToJSON) via SnakeCaseCapsEnumEncoding MandateStatus"
]
case29 :: Assertion
case29 = expected @=? testStep (step sameIndentStyle) input
where
input = unlines
[ "module Some.Types where"
, ""
, "data NonEmpty a"
, " = a :| [a]"
]
expected = unlines
[ "module Some.Types where"
, ""
, "data NonEmpty a = a :| [a]"
]
case30 :: Assertion
case30 = expected @=? testStep (step sameIndentStyle { cBreakEnums = True }) input
where
expected = input
input = unlines
[ "data ReasonCode"
, " = MissingTenantId"
, " -- Transaction errors:"
, " | TransactionDoesNotExist"
, " | TransactionAlreadyExists"
, " -- Engine errors:"
, " | EnginePersistenceError"
, " | EngineValidationError"
, " -- | Transaction was created in Info mode"
, " | RegisteredByNetworkEngine"
, " -- | Transaction was created in Routing mode"
, " | SentToNetworkEngine"
, " -- Network connection reasons:"
, " | SentToNetworkConnection"
, " | ReceivedByNetworkConnection"
, " | ValidatedByNetworkConnection"
]
case31 :: Assertion
case31 = expected @=? testStep (step indentIndentStyle { cBreakEnums = True }) input
where
expected = input
input = unlines
[ "data ConfiguredLogger"
, " -- | Logs to file"
, " = LogTo FilePath"
, " -- | Logs to stdout"
, " | LogToConsole"
, " -- | No logging, discards all messages"
, " | NoLogging"
, " deriving stock (Generic, Show)"
]
case32 :: Assertion
case32 = expected @=? testStep (step indentIndentStyle { cBreakEnums = True }) input
where
expected = input
input = unlines
[ "data RejectionReason"
, " -- InvalidState"
, " = CancellationFailed"
, " | TotalAmountConfirmationInvalid"
, " -- InvalidApiUsage"
, " | AccessTokenNotActive"
, " | VersionNotFound"
, " -- ValidationFailed"
, " | BankAccountExists"
, " deriving stock (Eq, Generic, Show)"
, " deriving (FromJSON, ToJSON) via SnakeCaseLowercaseEnumEncoding RejectionReason"
]
case33 :: Assertion
case33 = expected @=? testStep (step indentIndentStyle { cBreakEnums = True, cBreakSingleConstructors = False }) input
where
input = unlines
[ "module Some.Types where"
, ""
, "newtype NonEmpty a = NonEmpty { unNonEmpty :: a }"
]
expected = unlines
[ "module Some.Types where"
, ""
, "newtype NonEmpty a"
, " = NonEmpty { unNonEmpty :: a }"
]
case34 :: Assertion
case34 = expected @=? testStep (step indentIndentStyle { cVia = Indent 2 }) input
where
input = unlines
[ "module Some.Types where"
, ""
, "newtype NonEmpty a = NonEmpty { unNonEmpty :: a }"
, " deriving (ToJSON, FromJSON) via Something Magic (NonEmpty a)"
]
expected = unlines
[ "module Some.Types where"
, ""
, "newtype NonEmpty a"
, " = NonEmpty { unNonEmpty :: a }"
, " deriving (FromJSON, ToJSON)"
, " via Something Magic (NonEmpty a)"
]
case35 :: Assertion
case35 = expected @=? testStep (step indentIndentStyle { cBreakEnums = True, cBreakSingleConstructors = False }) input
where
input = unlines
[ "module Some.Types where"
, ""
, "data Foo = Foo"
, " { _transfer :: MonetaryAmount"
, " -> TransactionId"
, " -> m (Either CreditTransferError TransactionId)"
, " }"
]
expected = unlines
[ "module Some.Types where"
, ""
, "data Foo = Foo"
, " { _transfer :: MonetaryAmount -> TransactionId -> m (Either CreditTransferError TransactionId)"
, " }"
]
case36 :: Assertion
case36 = expected @=? testStep (step indentIndentStyle { cBreakEnums = True, cBreakSingleConstructors = False }) input
where
input = unlines
[ "module Some.Types where"
, ""
, "data Foo = Foo"
, " { _transfer :: (a -> b)"
, " -> TransactionId"
, " -> m (Either CreditTransferError TransactionId)"
, " }"
]
expected = unlines
[ "module Some.Types where"
, ""
, "data Foo = Foo"
, " { _transfer :: (a -> b) -> TransactionId -> m (Either CreditTransferError TransactionId)"
, " }"
]
case37 :: Assertion
case37 = expected @=? testStep (step indentIndentStyle { cVia = Indent 2 }) input
where
input = unlines
[ "module Some.Types where"
, ""
, "newtype UndoFlowData"
, " = UndoFlowData { flowDataDetails :: FlowDataDetails }"
, " deriving stock (Generic, Eq, Show)"
, " deriving (ToJSON, FromJSON)"
, " via AddConstTextFields '[\"type0\" := \"undo\","
, " \"type1\" := \"undo\","
, " \"reversal_indicator\" := \"Undo\"] FlowDataDetails"
]
expected = unlines
[ "module Some.Types where"
, ""
, "newtype UndoFlowData"
, " = UndoFlowData { flowDataDetails :: FlowDataDetails }"
, " deriving stock (Eq, Generic, Show)"
, " deriving (FromJSON, ToJSON)"
, " via AddConstTextFields '[\"type0\" := \"undo\", \"type1\" := \"undo\", \"reversal_indicator\" := \"Undo\"] FlowDataDetails"
]
case38 :: Assertion
case38 = expected @=? testStep (step indentIndentStyle { cVia = Indent 2 }) input
where
input = unlines
[ "data Flat = Flat"
, " { foo :: Int"
, " , bar :: Text"
, " , baz :: Double"
, " , qux :: Bool"
, " }"
, " deriving stock (Generic, Show, Eq)"
, " deriving (FromJSON, ToJSON)"
, " via GenericEncoded"
, " '[ FieldLabelModifier :="
, " '[ \"foo\" ==> \"nestFoo#foo\""
, " , \"bar\" ==> \"nestBar#bar\""
, " , \"baz\" ==> \"nestFoo#baz\""
, " ]"
, " ]"
, " Flat"
]
expected = unlines
[ "data Flat"
, " = Flat"
, " { foo :: Int"
, " , bar :: Text"
, " , baz :: Double"
, " , qux :: Bool"
, " }"
, " deriving stock (Eq, Generic, Show)"
, " deriving (FromJSON, ToJSON)"
, " via GenericEncoded '[FieldLabelModifier := '[\"foo\" ==> \"nestFoo#foo\", \"bar\" ==> \"nestBar#bar\", \"baz\" ==> \"nestFoo#baz\"]] Flat"
]
case39 :: Assertion
case39 = expected @=? testStep (step indentIndentStyle { cVia = Indent 2 }) input
where
input = unlines
[ "data CreditTransfer = CreditTransfer"
, " { nestedCreditorInfo :: CreditorInfo"
, " }"
, " deriving stock (Show, Eq, Generic)"
, " deriving (ToJSON, FromJSON) via"
, " ( UntaggedEncoded NordeaCreditTransfer"
, " & AddConstTextFields"
, " '[ \"request_type\" ':= \"credit_transfer\""
, " , \"provider\" ':= \"nordea\""
, " ]"
, " & FlattenFields '[\"nested_creditor_info\"]"
, " & RenameKeys"
, " '[ \"nested_creditor_info.creditor_agent_bic\" ==> \"creditor_agent_bic\""
, " , \"nested_creditor_info.creditor_iban\" ==> \"creditor_iban\""
, " , \"nested_creditor_info.creditor_name\" ==> \"creditor_name\""
, " , \"nested_creditor_info.creditor_account\" ==> \"creditor_account\""
, " ]"
, " )"
]
expected = unlines
[ "data CreditTransfer"
, " = CreditTransfer"
, " { nestedCreditorInfo :: CreditorInfo"
, " }"
, " deriving stock (Eq, Generic, Show)"
, " deriving (FromJSON, ToJSON)"
, " via (UntaggedEncoded NordeaCreditTransfer & AddConstTextFields '[\"request_type\" ':= \"credit_transfer\", \"provider\" ':= \"nordea\"] & FlattenFields '[\"nested_creditor_info\"] & RenameKeys '[\"nested_creditor_info.creditor_agent_bic\" ==> \"creditor_agent_bic\", \"nested_creditor_info.creditor_iban\" ==> \"creditor_iban\", \"nested_creditor_info.creditor_name\" ==> \"creditor_name\", \"nested_creditor_info.creditor_account\" ==> \"creditor_account\"])"
]
case40 :: Assertion
case40 = expected @=? testStep (step indentIndentStyle { cBreakSingleConstructors = False }) input
where
input = unlines
[ "module X where"
, ""
, "data a :==> b ="
, " Arr a b"
]
expected = unlines
[ "module X where"
, ""
, "data a :==> b = Arr a b"
]
case41 :: Assertion
case41 = expected @=? testStep (step indentIndentStyle) input
where
input = expected
expected = unlines
[ "module X where"
, ""
, "data Callback"
, " -- | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"
, " -- incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
, " -- nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
, " -- Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore"
, " -- eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,"
, " -- sunt in culpa qui officia deserunt mollit anim id est laborum."
, " = KafkaTopic"
, " { callbackTopic :: CallbackTopic"
, " -- ^ Name of topic to send updates to"
, " , callbackFormat :: CallbackFormat"
, " -- ^ The format used to send these updates"
, " }"
, " deriving stock (Eq, Generic, Show)"
, " deriving (FromJSON, ToJSON) via IdiomaticWithDescription CallbackDesc Callback"
, " deriving (HasGen) via Generically Callback"
, " deriving (FromField) via JsonField Callback"
]
case42 :: Assertion
case42 = expected @=? testStep (step indentIndentStyle) input
where
input = expected
expected = unlines
[ "module X where"
, ""
, "data SignupError"
, " = IdempotencyConflict"
, " | ValidationError Text -- TODO: might be a sumtype of possible error codes"
, " deriving stock (Eq, Generic, Show)"
]
case43 :: Assertion
case43 = expected @=? testStep (step indentIndentStyle { cBreakEnums = True, cBreakSingleConstructors = False }) input
where
input = expected
expected = unlines
[ "module X where"
, ""
, "data CallbackResult"
, " -- | Callback successfully sent"
, " = Success"
, " -- | Kafka error received"
, " | KafkaIssue KafkaError"
, " deriving (Eq, Show)"
]
-- This test showcases a difficult to solve issue. If the comment is in a
-- deriving clause, it's very hard to guess the correct position of the entire
-- block. E.g. the deriving clause itself has the wrong position. However, if
-- we look at all deriving clauses we know where they start and end.
--
-- This means that we've needed to make the decision to put all inline comments
-- before the deriving clause itself
case44 :: Assertion
case44 = expected @=? testStep (step indentIndentStyle { cBreakEnums = True, cBreakSingleConstructors = False, cVia = Indent 2 }) input
where
input = unlines
[ "module X where"
, ""
, " data CreditTransfer = CreditTransfer"
, " { amount :: Amount -- ^ 1 <= amount <= 999_999_999_999"
, " , date :: Day"
, " , accountNumber :: Account"