Skip to content

Commit

Permalink
Use /usr/bin/env shebang in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Mar 14, 2024
1 parent 7d99e0b commit 4eb99c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import qualified Data.Text as Text (null, takeWhile)

import Nixfmt.Predoc
(Doc, GroupAnn(..), Pretty, emptyline, group, group', hardline, hardspace, hcat, line, line',
nest, offset, newline, pretty, sepBy, surroundWith, softline, text, comment, trailingComment, trailing, textWidth,
nest, offset, newline, pretty, sepBy, surroundWith, softline, softline', text, comment, trailingComment, trailing, textWidth,
unexpandSpacing')
import Nixfmt.Types
(Ann(..), Binder(..), Expression(..), Item(..), Items(..), Leaf,
Expand Down Expand Up @@ -139,9 +139,18 @@ prettyTerm (Token t) = pretty t
prettyTerm (SimpleString (Ann leading s trailing')) = pretty leading <> prettySimpleString s <> pretty trailing'
prettyTerm (IndentedString (Ann leading s trailing')) = pretty leading <> prettyIndentedString s <> pretty trailing'
prettyTerm (Path p) = pretty p
prettyTerm (Selection term selectors Nothing) = pretty term <> hcat selectors
prettyTerm (Selection term selectors (Just (kw, def))) =
pretty term <> hcat selectors <> hardspace <> pretty kw <> hardspace <> pretty def
prettyTerm (Selection term selectors rest) =
pretty term <> sep <> hcat selectors
<> pretty ((\(kw, def) -> softline <> nest (pretty kw <> hardspace <> pretty def)) <$> rest)
where
-- Selection (`foo.bar.baz`) case distinction on the first element (`foo`):
sep = case term of
-- If it is an ident, keep it all together
(Token _) -> mempty
-- If it is a parenthesized expression, maybe add a line break
(Parenthesized _ _ _) -> softline'
-- Otherwise, very likely add a line break
_ -> line'

-- Empty list
prettyTerm (List (Ann leading paropen Nothing) (Items []) (Ann [] parclose trailing'))
Expand Down
2 changes: 1 addition & 1 deletion test/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/env bash
#!/usr/bin/env bash
set -euo pipefail

# Simple test runner for nixfmt.
Expand Down

0 comments on commit 4eb99c1

Please sign in to comment.