summaryrefslogtreecommitdiffhomepage
path: root/tests/Language/Haskell/Stylish/Step/Data/Tests.hs
blob: 1d50bf105a2eb0ed44fcfd704ec24c6edca2abbe (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
{-# 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
    ]

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"
      , "   }"
      , "   deriving stock (Eq, Generic, Show)"
      , "   deriving (FromJSON, ToJSON) via"
      , "     AddConstTextFields"
      , "       '[\"notification_type\" ':= \"credit_transaction\""
      , "         -- Note that the bcio name has \"transaction\""
      , "         -- rather than \"transfer\""
      , "        ]"
      , "        (UntaggedEncoded CreditTransfer)"
      ]
    expected = unlines
      [ "module X where"
      , ""
      , "data CreditTransfer = CreditTransfer"
      , "  { amount :: Amount"
      , "    -- ^ 1 <= amount <= 999_999_999_999"
      , "  , date :: Day"
      , "  , accountNumber :: Account"
      , "  }"
      , "  -- Note that the bcio name has \"transaction\""
      , "  -- rather than \"transfer\""
      , "  deriving stock (Eq, Generic, Show)"
      , "  deriving (FromJSON, ToJSON)"
      , "    via AddConstTextFields '[\"notification_type\" ':= \"credit_transaction\"] (UntaggedEncoded CreditTransfer)"
      ]

case45 :: Assertion
case45 = expected @=? testStep (step indentIndentStyle { cBreakEnums = True, cBreakSingleConstructors = False, cVia = Indent 2 }) input
  where
    input = expected
    expected = unlines
      [ "module X where"
      , ""
      , "data CreditTransfer = CreditTransfer"
      , "  { amount :: Amount"
      , "    -- ^ 1 <= amount <= 999_999_999_999"
      , "  , date :: Day"
      , "  , accountNumber :: Account"
      , "  }"
      , "  -- Note that the bcio name has \"transaction\""
      , "  -- rather than \"transfer\""
      , "  deriving stock (Eq, Generic, Show)"
      , "  deriving (FromJSON, ToJSON)"
      , "    via AddConstTextFields '[\"notification_type\" ':= \"credit_transaction\"] (UntaggedEncoded CreditTransfer)"
      ]

case46 :: Assertion
case46 = expected @=? testStep (step indentIndentStyle { cBreakEnums = True, cBreakSingleConstructors = False, cVia = Indent 2 }) input
  where
    input = expected
    expected = unlines
      [ "module X where"
      , ""
      , "-- | A format detailing which encoding to use for the settlement events"
      , "data CallbackFormat"
      , "  -- | The Avro schema is to be used"
      , "  = AvroEngineEvent"
      , "  deriving (Bounded, Enum, Eq, Generic, Show)"
      , "  deriving (FromJSON, ToJSON)"
      , "    via TypeTaggedWithDescription FormatDesc CallbackFormat"
      , "  deriving (HasGen)"
      , "    via EnumBounded CallbackFormat"
      ]

case47 :: Assertion
case47 = expected @=? testStep (step indentIndentStyle) input
  where
    input = expected
    expected = unlines
      [ "module X where"
      , ""
      , "-- | A GADT example"
      , "data T a where"
      , "  D1 :: Int -> T String"
      , "  D2 :: T Bool"
      , "  D3 :: (a, a) -> T [a]"
      ]

case48 :: Assertion
case48 = expected @=? testStep (step indentIndentStyle) input
  where
    input = expected
    expected = unlines
      [ "module X where"
      , ""
      , "-- | A GADT example"
      , "data T a where"
      , "  D1 :: Int -> T String"
      , "  D2 :: T Bool"
      , "  D3 :: forall a. (Eq a, Bounded a) => (a, a) -> T [a]"
      ]

case49 :: Assertion
case49 = expected @=? testStep (step indentIndentStyle) input
  where
    input = expected
    expected = unlines
      [ "module X where"
      , ""
      , "-- | A GADT example"
      , "data T a where"
      , "  D1 :: Int -> T String"
      , "  D2 :: T Bool"
      , "  D3 :: forall a. (Eq a) => (a, a) -> T [a]"
      ]

case50 :: Assertion
case50 = expected @=? testStep (step indentIndentStyle { cCurriedContext = True }) input
  where
    input = expected
    expected = unlines
      [ "module X where"
      , ""
      , "-- | A GADT example"
      , "data T a where"
      , "  D1 :: Int -> T String"
      , "  D2 :: T Bool"
      , "  D3 :: forall a. Eq a => (a, a) -> T [a]"
      ]

case51 :: Assertion
case51 = expected @=? testStep (step indentIndentStyle { cCurriedContext = True }) input
  where
    input = unlines
      [ "module X where"
      , ""
      , "-- | A GADT example"
      , "data T a where"
      , "  D1 :: Int -> T String"
      , "  D2 :: T Bool"
      , "  D3 :: forall a. (Eq a) => (a, a) -> T [a]"
      ]
    expected = unlines
      [ "module X where"
      , ""
      , "-- | A GADT example"
      , "data T a where"
      , "  D1 :: Int -> T String"
      , "  D2 :: T Bool"
      , "  D3 :: forall a. Eq a => (a, a) -> T [a]"
      ]

case52 :: Assertion
case52 = expected @=? testStep (step indentIndentStyle { cBreakSingleConstructors = False, cCurriedContext = True }) input
  where
    input = unlines
      [ "module X where"
      , ""
      , "data Foo = Foo"
      , "  { foo :: forall a b. (Eq a, Bounded b) => a -> b -> [(a, b)]"
      , "  }"
      ]
    expected = unlines
      [ "module X where"
      , ""
      , "data Foo = Foo"
      , "  { foo :: forall a b. Eq a => Bounded b => a -> b -> [(a, b)]"
      , "  }"
      ]

case53 :: Assertion
case53 = expected @=? testStep (step indentIndentStyle { cMaxColumns = MaxColumns 80 }) input
  where
    input = unlines
      [ "newtype Foo m a"
      , "  = Foo (m a)"
      , "  deriving newtype (Functor, Applicative, Monad, MonadError, MonadCatch, Foldable, Monoid)"
      ]
    expected = unlines
      [ "newtype Foo m a"
      , "  = Foo (m a)"
      , "  deriving newtype"
      , "    ( Applicative"
      , "    , Foldable"
      , "    , Functor"
      , "    , Monad"
      , "    , MonadCatch"
      , "    , MonadError"
      , "    , Monoid"
      , "    )"
      ]

case54 :: Assertion
case54 = expected @=? testStep (step indentIndentStyle { cMaxColumns = MaxColumns 80 }) input
  where
    input = unlines
      [ "newtype Foo m a"
      , "  = Foo (m a)"
      , "  deriving newtype (Functor, Applicative, Monad)"
      ]
    expected = unlines
      [ "newtype Foo m a"
      , "  = Foo (m a)"
      , "  deriving newtype (Applicative, Functor, Monad)"
      ]

case55 :: Assertion
case55 = expected @=? testStep (step sameSameNoSortStyle) input
  where
    input = unlines
       [ "data Foo = Foo deriving (Z, Y, X, Bar, Abcd)"
       ]

    expected = input

case56 :: Assertion
case56 = assertSnippet (step defaultConfig)
    [ "data Foo = Foo"
    , "  { -- | Comment"
    , "    bar :: Int"
    , "  , baz :: Int"
    , "  }"
    ]
    [ "data Foo = Foo"
    , "    { -- | Comment"
    , "      bar :: Int"
    , "    , baz :: Int"
    , "    }"
    ]

case57 :: Assertion
case57 = assertSnippet (step defaultConfig)
    [ "data Foo = Foo"
    , "    { {- | A"
    , "      -}"
    , "      fooA :: Int"
    , ""
    , "      {- | B"
    , "      -}"
    , "    , fooB :: Int"
    , ""
    , "      {- | C"
    , "      -}"
    , "    , fooC :: Int"
    , ""
    , "      {- | D"
    , "      -}"
    , "    , fooD :: Int"
    , ""
    , "      {- | E"
    , "      -}"
    , "    , fooE :: Int"
    , ""
    , "      {- | F"
    , "      -}"
    , "    , fooFooFoo :: Int"
    , ""
    , "      {- | G"
    , "      -}"
    , "    , fooBarBar :: Int"
    , "    }"
    ]
    [ "data Foo = Foo"
    , "    { {- | A"
    , "      -}"
    , "      fooA :: Int"
    , "      {- | B"
    , "      -}"
    , "    , fooB :: Int"
    , "      {- | C"
    , "      -}"
    , "    , fooC :: Int"
    , "      {- | D"
    , "      -}"
    , "    , fooD :: Int"
    , "      {- | E"
    , "      -}"
    , "    , fooE :: Int"
    , "      {- | F"
    , "      -}"
    , "    , fooFooFoo :: Int"
    , "      {- | G"
    , "      -}"
    , "    , fooBarBar :: Int"
    , "    }"
    ]

sameSameStyle :: Config
sameSameStyle = Config SameLine SameLine 2 2 False True SameLine False True NoMaxColumns

sameIndentStyle :: Config
sameIndentStyle = Config SameLine (Indent 2) 2 2 False True SameLine False True NoMaxColumns

indentSameStyle :: Config
indentSameStyle = Config (Indent 2) SameLine 2 2 False True SameLine False True NoMaxColumns

indentIndentStyle :: Config
indentIndentStyle = Config (Indent 2) (Indent 2) 2 2 False True SameLine False True NoMaxColumns

indentIndentStyle4 :: Config
indentIndentStyle4 = Config (Indent 4) (Indent 4) 4 4 False True SameLine False True NoMaxColumns

sameSameNoSortStyle :: Config
sameSameNoSortStyle = Config SameLine SameLine 2 2 False True SameLine False False NoMaxColumns