File: CommonTests.hs

package info (click to toggle)
haskell-yi-core 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 756 kB
  • sloc: haskell: 10,038; makefile: 5
file content (27 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download | duplicates (4)
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
{-# LANGUAGE OverloadedStrings #-}
module Yi.Mode.CommonTests (testSuite) where

import Test.Tasty
import Test.Tasty.HUnit

import Yi.Mode.Common
import Data.Attoparsec.Text (parseOnly)
import Control.Applicative ((<|>))
import Data.Either (isRight)

testSuite :: TestTree
testSuite = testGroup "Mode.Common" [unitTests]

unitTests :: TestTree
unitTests = testGroup "unit tests"
  [ testGroup "shebangParser" $
      [ testCase "matches a simple shebang" $
          parseOnly (shebangParser "runhaskell") "#!/usr/bin/env runhaskell\n" @?= Right ()
      , testCase "matches a complex shebang" $
          map (parseOnly (shebangParser ("python" *> ("3" <|> "2" <|> "")))) ["#!/usr/bin/env python\n", "#!/usr/bin/env python2\n", "#!/usr/bin/env python3\n"] @?= [Right (), Right (), Right ()]
      , testCase "ignores noise and spaces" $
          parseOnly (shebangParser "runhaskell") "\n#!abcdefg\r\nABCdefG\n#!   /usr/bin/env  runhaskell    \r\n\n/AbcDe#!/fg\n" @?= Right ()
      , testCase "parser fails correctly" $
          isRight (parseOnly (shebangParser "runhaskell") "#!/usr/bin/env abc\n") @?= False
      ]
  ]