1{-# LANGUAGE OverloadedStrings #-}
2module Main (main) where
4import Control.Monad (forM_)
5import Data.Maybe (isJust)
6import Data.Word (Word8)
7import Prelude hiding (takeWhile)
9import Test.Framework (defaultMain, testGroup)
10import Test.Framework.Providers.QuickCheck2 (testProperty)
11import Test.QuickCheck hiding (NonEmpty)
12import qualified Data.Attoparsec as P
13import qualified Data.ByteString as B
14import qualified Data.ByteString.Char8 as C
16-- Make sure that structures whose types claim they are non-empty
19nonEmptyList l = length (nonEmpty l) > 0
20 where types = l :: NonEmpty [Int]
21nonEmptyBS l = B.length (nonEmpty l) > 0
26label (NonEmpty s) = case parse (anyWord8 <?> s) B.empty of
27 (_, Left err) -> s `isInfixOf` err
31-- Basic byte-level combinators.
33maybeP p s = case P.parse p s `P.feed` B.empty of
37defP p s = P.parse p s `P.feed` B.empty
39satisfy w s = maybeP (P.satisfy (<=w)) (B.cons w s) == Just w
41word8 w s = maybeP (P.word8 w) (B.cons w s) == Just w
43anyWord8 s = maybeP P.anyWord8 s == if B.null s
47notWord8 w (NonEmpty s) = maybeP (P.notWord8 w) s == if v == w
52string s = maybeP (P.string s) s == Just s
55 let t = B.dropWhile (<=w) s
56 in case defP (P.skipWhile (<=w)) s of
57 P.Done t' () -> t == t'
60takeCount (Positive k) s =
61 case maybeP (P.take k) s of
62 Nothing -> k > B.length s
63 Just s' -> k <= B.length s
66 let (h,t) = B.span (==w) s
67 in case defP (P.takeWhile (==w)) s of
68 P.Done t' h' -> t == t' && h == h'
73 (h,t) = B.span (<=w) s'
74 in case defP (P.takeWhile1 (<=w)) s' of
75 P.Done t' h' -> t == t' && h == h'
79 let (h,t) = B.break (==w) s
80 in case defP (P.takeTill (==w)) s of
81 P.Done t' h' -> t == t' && h == h'
84ensure n s = case defP (P.ensure m) s of
85 P.Done _ () -> B.length s >= m
87 where m = (n `mod` 220) - 20
89takeWhile1_empty = maybeP (P.takeWhile1 undefined) B.empty == Nothing
91endOfInput s = maybeP P.endOfInput s == if B.null s
95main = defaultMain tests
99 testProperty "nonEmptyList" nonEmptyList,
100 testProperty "nonEmptyBS" nonEmptyBS,
101 testProperty "satisfy" satisfy,
102 testProperty "word8" word8,
103 testProperty "notWord8" notWord8,
104 testProperty "anyWord8" anyWord8,
105 testProperty "string" string,
106 testProperty "skipWhile" skipWhile,
107 testProperty "takeCount" takeCount,
108 testProperty "takeWhile" takeWhile,
109 testProperty "takeWhile1" takeWhile1,
110 testProperty "takeWhile1_empty" takeWhile1_empty,
111 testProperty "takeTill" takeTill,
112 testProperty "endOfInput" endOfInput,
113 testProperty "ensure" ensure
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list