Skip to content

Commit

Permalink
Merge pull request #144 from guibou/fix_wrapping_141
Browse files Browse the repository at this point in the history
fix: correctly remove indentation one line even if escaped line brake
  • Loading branch information
guibou authored Jan 3, 2025
2 parents e6e287d + d065b3d commit d0fed60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 3 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Revision history for PyF

- Support for GHC 9.12
- Fix indentation in `fmtTrim` when line break was escaped (bug https://github.com/guibou/PyF/issues/141).
- Support for GHC 9.12.
- Fix for tests in GHC 9.10.
- No more "python" reference check in the test phase. I'm removing complexity,
and if it does not match the python implementation, we can just introduce a
new test case. Note that python checking can be reimplemented easilly by
Expand Down
7 changes: 5 additions & 2 deletions src/PyF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ fmt = mkFormatter "fmt" fmtConfig

-- | Format with whitespace trimming.
fmtTrim :: QuasiQuoter
fmtTrim = mkFormatter "fmtTrim" (addTrim fmtConfig)
fmtTrim = let
qq = mkFormatter "fmtTrim" fmtConfig
in qq { quoteExp = \s -> quoteExp qq (trimIndent s) }

-- | Multiline string, no interpolation.
str :: QuasiQuoter
str = mkFormatter "str" strConfig

-- | Multiline string, no interpolation, but does indentation trimming.
strTrim :: QuasiQuoter
strTrim = mkFormatter "strTrim" (addTrim strConfig)
strTrim = let qq = mkFormatter "strTrim" strConfig
in qq { quoteExp = \s -> quoteExp qq (trimIndent s) }

-- | Raw string, neither interpolation nor escaping is performed.
raw :: QuasiQuoter
Expand Down
14 changes: 7 additions & 7 deletions test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,18 @@ yeah\
hello
- a
- {
2 + 2
2 + 2
:d}|]
`shouldBe` "hello\n- a\n - 4"

it "behaves well with escaped first line" $ do
[fmtTrim|\
- a
- b
|]
`shouldBe` "- a\n- b\n"
it "Do not touch single lines" $ do
[fmtTrim| hello|] `shouldBe` " hello"
it "trim when there is a linebreak" $ do
-- https://github.com/guibou/PyF/issues/141
[fmtTrim|
Cannot convert formula 2.0 * exponent(unit=s, value=1.0) which has unit dimensionless to\
unit dimensionless for they have different dimensions|]
`shouldBe` "Cannot convert formula 2.0 * exponent(unit=s, value=1.0) which has unit dimensionless to unit dimensionless for they have different dimensions"
describe "raw" $ do
it "does not escape anything" $
[raw|hello
Expand Down

0 comments on commit d0fed60

Please sign in to comment.