Skip to content

Commit

Permalink
Update test suite and benchmark suite
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdone committed Aug 19, 2016
1 parent 60cd0cf commit e7e7168
Show file tree
Hide file tree
Showing 37 changed files with 1,529 additions and 1,419 deletions.
90 changes: 90 additions & 0 deletions BENCHMARKS.md
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)))|]))]
```
3 changes: 3 additions & 0 deletions CHANGELOG → CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
* Drop support for styles

4.6.4

* Copy/delete file instead of renaming

4.4.6

* Fix whole module printer
* Accept a filename to reformat

Expand All @@ -23,5 +25,6 @@
* Fixed: bug in printing operators in statements.

4.5.4

* Improvements to Tibell style.
* 6x speed up on rendering operators.
24 changes: 0 additions & 24 deletions LICENSE

This file was deleted.

28 changes: 28 additions & 0 deletions LICENSE.md
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.
198 changes: 198 additions & 0 deletions TESTS.md
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
```
17 changes: 0 additions & 17 deletions benchmarks/BigDeclarations.hs

This file was deleted.

Loading

0 comments on commit e7e7168

Please sign in to comment.