@@ -11,6 +11,7 @@ import Data.Text.Encoding qualified as TE
11
11
import Data.Text.Lazy qualified as LazyText
12
12
import Data.Text.Lazy.Encoding qualified as LTE
13
13
import Format qualified
14
+ import Gren.Package qualified
14
15
import Parse.Module qualified as Parse
15
16
import Test.Hspec
16
17
@@ -318,6 +319,19 @@ spec = do
318
319
" f =" ,
319
320
" 0"
320
321
]
322
+ describe " operator declarations" $ do
323
+ it " formats" $
324
+ [ " infix left 0 (|>) = apR" ,
325
+ " infix right 0 (<|) = apL" ,
326
+ " f = {}"
327
+ ]
328
+ `shouldFormatKernelModuleBodyAs` [ " infix left 0 (|>) = apR" ,
329
+ " infix right 0 (<|) = apL" ,
330
+ " " ,
331
+ " " ,
332
+ " f =" ,
333
+ " {}"
334
+ ]
321
335
322
336
describe " expressions" $ do
323
337
describe " array literals" $ do
@@ -686,10 +700,18 @@ assertFormattedModuleBody lines_ =
686
700
lines_ `shouldFormatModuleBodyAs` lines_
687
701
688
702
shouldFormatModuleBodyAs :: [Text ] -> [Text ] -> IO ()
689
- shouldFormatModuleBodyAs inputLines expectedOutputLines =
703
+ shouldFormatModuleBodyAs =
704
+ shouldFormatModuleBodyAs_ Parse. Application
705
+
706
+ shouldFormatKernelModuleBodyAs :: [Text ] -> [Text ] -> IO ()
707
+ shouldFormatKernelModuleBodyAs =
708
+ shouldFormatModuleBodyAs_ (Parse. Package Gren.Package. kernel)
709
+
710
+ shouldFormatModuleBodyAs_ :: Parse. ProjectType -> [Text ] -> [Text ] -> IO ()
711
+ shouldFormatModuleBodyAs_ projectType inputLines expectedOutputLines =
690
712
let input = TE. encodeUtf8 $ Text. unlines inputLines
691
713
expectedOutput = LazyText. unlines $ fmap LazyText. fromStrict expectedOutputLines
692
- actualOutput = LTE. decodeUtf8 . Builder. toLazyByteString <$> Format. formatByteString Parse. Application input
714
+ actualOutput = LTE. decodeUtf8 . Builder. toLazyByteString <$> Format. formatByteString projectType input
693
715
in case LazyText. stripPrefix " module Main exposing (..)\n\n\n\n " <$> actualOutput of
694
716
Left err ->
695
717
expectationFailure (" shouldFormatModuleBodyAs: failed to format" <> show err)
0 commit comments