-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update test suite and benchmark suite
- Loading branch information
Showing
37 changed files
with
1,529 additions
and
1,419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Large inputs | ||
|
||
Bunch of declarations | ||
|
||
``` haskell | ||
listPrinters = | ||
[(''[] | ||
,\(typeVariable:_) _automaticPrinter -> | ||
(let presentVar = varE (presentVarName typeVariable) | ||
in lamE [varP (presentVarName typeVariable)] | ||
[|(let typeString = "[" ++ fst $(presentVar) ++ "]" | ||
in (typeString | ||
,\xs -> | ||
case fst $(presentVar) of | ||
"GHC.Types.Char" -> | ||
ChoicePresentation | ||
"String" | ||
[("String",undefined) | ||
,("List of characters",undefined)] | ||
_ -> | ||
ListPresentation typeString | ||
(map (snd $(presentVar)) xs)))|]))] | ||
printComments loc' ast = do | ||
let correctLocation comment = comInfoLocation comment == Just loc' | ||
commentsWithLocation = filter correctLocation (nodeInfoComments info) | ||
comments <- return $ map comInfoComment commentsWithLocation | ||
|
||
forM_ comments $ \comment -> do | ||
-- Preceeding comments must have a newline before them. | ||
hasNewline <- gets psNewline | ||
when (not hasNewline && loc' == Before) newline | ||
|
||
printComment (Just $ srcInfoSpan $ nodeInfoSpan info) comment | ||
where info = ann ast | ||
exp' (App _ op a) = | ||
do (fits,st) <- | ||
fitsOnOneLine (spaced (map pretty (f : args))) | ||
if fits | ||
then put st | ||
else do pretty f | ||
newline | ||
spaces <- getIndentSpaces | ||
indented spaces (lined (map pretty args)) | ||
where (f,args) = flatten op [a] | ||
flatten :: Exp NodeInfo | ||
-> [Exp NodeInfo] | ||
-> (Exp NodeInfo,[Exp NodeInfo]) | ||
flatten (App _ f' a') b = | ||
flatten f' (a' : b) | ||
flatten f' as = (f',as) | ||
infixApp :: Exp NodeInfo | ||
-> Exp NodeInfo | ||
-> QOp NodeInfo | ||
-> Exp NodeInfo | ||
-> Maybe Int64 | ||
-> Printer () | ||
``` | ||
|
||
# Complex inputs | ||
|
||
Quasi-quotes with nested lets and operators | ||
|
||
``` haskell | ||
quasiQuotes = | ||
[(''[] | ||
,\(typeVariable:_) _automaticPrinter -> | ||
(let presentVar = varE (presentVarName typeVariable) | ||
in lamE [varP (presentVarName typeVariable)] | ||
[|(let typeString = "[" ++ fst $(presentVar) ++ "]" | ||
in (typeString | ||
,\xs -> | ||
case fst $(presentVar) of | ||
"GHC.Types.Char" -> | ||
ChoicePresentation | ||
"String" | ||
[("String" | ||
,StringPresentation "String" | ||
(concatMap getCh (map (snd $(presentVar)) xs))) | ||
,("List of characters" | ||
,ListPresentation typeString | ||
(map (snd $(presentVar)) xs))] | ||
where getCh (CharPresentation "GHC.Types.Char" ch) = | ||
ch | ||
getCh (ChoicePresentation _ ((_,CharPresentation _ ch):_)) = | ||
ch | ||
getCh _ = "" | ||
_ -> | ||
ListPresentation typeString | ||
(map (snd $(presentVar)) xs)))|]))] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Copyright (c) 2014, Chris Done | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of hindent nor the names of its contributors may be | ||
used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CHRIS DONE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
# Introduction | ||
|
||
This file is a test suite. Each section maps to an HSpec test, and | ||
each line that is followed by a Haskell code fence is tested to make | ||
sure re-formatting that code snippet produces the same result. | ||
|
||
You can browse through this document to see what HIndent's style is | ||
like, or contribute additional sections to it, or regression tests. | ||
|
||
# Modules | ||
|
||
Module header | ||
|
||
``` haskell | ||
module X where | ||
``` | ||
|
||
Exports | ||
|
||
``` haskell | ||
module X | ||
(x | ||
,y | ||
,Z | ||
,P(x, z)) | ||
where | ||
``` | ||
|
||
## Imports | ||
|
||
Import lists | ||
|
||
``` haskell | ||
import Data.Text | ||
import Data.Text | ||
import qualified Data.Text as T | ||
import qualified Data.Text (a, b, c) | ||
import Data.Text (a, b, c) | ||
import Data.Text hiding (a, b, c) | ||
``` | ||
|
||
# Declarations | ||
|
||
Type declaration | ||
|
||
``` haskell | ||
type EventSource a = (AddHandler a, a -> IO ()) | ||
``` | ||
|
||
# Expressions | ||
|
||
Lazy patterns in a lambda | ||
|
||
``` haskell | ||
f = \ ~a -> undefined -- \~a yields parse error on input ‘\~’ | ||
``` | ||
|
||
Bang patterns in a lambda | ||
|
||
``` haskell | ||
f = \ !a -> undefined -- \!a yields parse error on input ‘\!’ | ||
``` | ||
|
||
List comprehensions | ||
|
||
``` haskell | ||
defaultExtensions = | ||
[ e | ||
| e@EnableExtension {} <- knownExtensions ] \\ | ||
map EnableExtension badExtensions | ||
``` | ||
|
||
Record indentation | ||
|
||
``` haskell | ||
getGitProvider :: EventProvider GitRecord () | ||
getGitProvider = | ||
EventProvider | ||
{ getModuleName = "Git" | ||
, getEvents = getRepoCommits | ||
} | ||
``` | ||
|
||
Records again | ||
|
||
``` haskell | ||
commitToEvent :: FolderPath -> TimeZone -> Commit -> Event.Event | ||
commitToEvent gitFolderPath timezone commit = | ||
Event.Event | ||
{ pluginName = getModuleName getGitProvider | ||
, eventIcon = "glyphicon-cog" | ||
, eventDate = localTimeToUTC timezone (commitDate commit) | ||
} | ||
``` | ||
|
||
Cases | ||
|
||
``` haskell | ||
strToMonth :: String -> Int | ||
strToMonth month = | ||
case month of | ||
"Jan" -> 1 | ||
"Feb" -> 2 | ||
_ -> error $ "Unknown month " ++ month | ||
``` | ||
|
||
Operators | ||
|
||
``` haskell | ||
x = | ||
Value <$> thing <*> secondThing <*> thirdThing <*> fourthThing <*> | ||
Just thisissolong <*> | ||
Just stilllonger | ||
``` | ||
|
||
# Type signatures | ||
|
||
Class constraints | ||
|
||
``` haskell | ||
fun | ||
:: (Class a, Class b) | ||
=> a -> b -> c | ||
``` | ||
|
||
Tuples | ||
|
||
``` haskell | ||
fun :: (a, b, c) -> (a, b) | ||
``` | ||
|
||
# Function declarations | ||
|
||
Where clause | ||
|
||
``` haskell | ||
sayHello :: IO () | ||
sayHello = do | ||
name <- getLine | ||
putStrLn $ greeting name | ||
where | ||
greeting name = "Hello, " ++ name ++ "!" | ||
``` | ||
|
||
Guards and pattern guards | ||
|
||
``` haskell | ||
f :: Int | ||
f x | ||
| x <- Just x | ||
, x <- Just x = | ||
case x of | ||
Just x -> e | ||
| otherwise = do e | ||
where | ||
x = y | ||
``` | ||
|
||
Case inside a `where` and `do` | ||
|
||
``` haskell | ||
g x = | ||
case x of | ||
a -> x | ||
where | ||
foo = | ||
case x of | ||
_ -> do | ||
launchMissiles | ||
where | ||
y = 2 | ||
``` | ||
|
||
Let inside a `where` | ||
|
||
``` haskell | ||
g x = | ||
let x = 1 | ||
in x | ||
where | ||
foo = | ||
let y = 2 | ||
z = 3 | ||
in y | ||
``` | ||
|
||
# Behaviour checks | ||
|
||
Unicode | ||
|
||
``` haskell | ||
α = γ * "ω" -- υ | ||
``` | ||
|
||
Empty module | ||
|
||
``` haskell | ||
``` |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.