File: PrettyTests.hs

package info (click to toggle)
haskell-futhark 0.25.32-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,236 kB
  • sloc: haskell: 100,484; ansic: 12,100; python: 3,440; yacc: 785; sh: 561; javascript: 558; lisp: 399; makefile: 277
file content (35 lines) | stat: -rw-r--r-- 967 bytes parent folder | download
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
module Language.Futhark.PrettyTests (tests) where

import Data.Text qualified as T
import Language.Futhark
import Language.Futhark.SyntaxTests ()
import Test.Tasty
import Test.Tasty.HUnit
import Prelude

var :: QualName Name -> UncheckedExp
var x = Var x NoInfo mempty

binOp :: QualName Name -> UncheckedExp -> UncheckedExp -> UncheckedExp
binOp op x y = AppExp (BinOp (op, mempty) NoInfo (x, NoInfo) (y, NoInfo) mempty) NoInfo

tests :: TestTree
tests =
  testGroup
    "Language.Futhark.Pretty"
    [ testCase "No outer parens" $
        p (binOp "+" (var "x") (var "y"))
          @?= "x + y",
      testCase "No redundant parens" $
        p (binOp "+" "x+y" (var "z"))
          @?= "x + y + z",
      testCase "Necessary parens" $
        p (binOp "+" (var "x") "y+z")
          @?= "x + (y + z)",
      testCase "Explicit but redundant parens" $
        p "(x+y)+z"
          @?= "(x + y) + z"
    ]
  where
    p :: UncheckedExp -> T.Text
    p = prettyText