align-equal 1.0.0.0 → 1.0.1.0
raw patch · 4 files changed
+80/−5 lines, 4 filesdep +hspecdep ~basedep ~safedep ~textPVP ok
version bump matches the API change (PVP)
Dependencies added: hspec
Dependency ranges changed: base, safe, text
API changes (from Hackage documentation)
Files
- CHANGELOG.md +13/−0
- align-equal.cabal +14/−1
- src/Data/Text/AlignEqual.hs +8/−4
- test/Spec.hs +45/−0
CHANGELOG.md view
@@ -1,6 +1,19 @@ # Changelog All notable changes to the `align-equal` project will be documented in this file. +## [1.0.1.0] - 2025-04-03++### Added+- Added a test suite using HSpec (`test/Spec.hs`) to validate core functions (`prefixLength`, `adjustLine`, `adjustText`).++### Changed+- Improved `adjustText` function:+ - Now returns the original text unchanged if it's empty or contains no lines with `'='`.+ - Updated function documentation and doctests to reflect this behavior.++### Removed+- Removed an unnecessary `newText` binding in `adjustText` for cleaner logic.+ ## [1.0.0] - 2025-03-31 ### Changed:
align-equal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: align-equal-version: 1.0.0.0+version: 1.0.1.0 license: MIT license-file: LICENSE author: Joonkyu Park (based on original work by Gabriella Gonzalez)@@ -41,4 +41,17 @@ text >=2.0.2 && <2.1, hs-source-dirs: src+ default-language: Haskell2010++test-suite your-project-test+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Spec.hs+ build-depends:+ align-equal,+ base,+ hspec,+ safe,+ text,+ default-language: Haskell2010
src/Data/Text/AlignEqual.hs view
@@ -57,17 +57,23 @@ -- | Processes multi-line text to align all '=' signs across lines. -- It adjusts the prefix length of each line to match the maximum prefix length. -- If a line does not contain '=', it will be left as-is.+-- If the input is empty or contains no lines with '=', it is returned unchanged. -- -- >>> adjustText "key=value\na=b" -- "key=value\na =b" -- >>> adjustText "x=y\nlong=var" -- "x =y\nlong=var"+-- >>> adjustText ""+-- "" adjustText :: Text -- ^ The input text (possibly multi-line) -> Text- -- ^ The aligned text-adjustText oldText = newText+ -- ^ The aligned text, or the original text if no '=' is found+adjustText oldText+ | T.null oldText = oldText+ | null newLines = oldText+ | otherwise = T.intercalate "\n" newLines where oldLines = T.lines oldText @@ -81,5 +87,3 @@ [] Just desiredPrefixLength -> map (adjustLine desiredPrefixLength) oldLines-- newText = T.unlines newLines
+ test/Spec.hs view
@@ -0,0 +1,45 @@+{-# LANGUAGE OverloadedStrings #-}++module Main where++import Data.Text (Text)+import qualified Data.Text as T+import Data.Text.AlignEqual+import Test.Hspec++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "prefixLength" $ do+ it "returns Just length for lines containing '='" $ do+ prefixLength "key=value" `shouldBe` Just 3+ prefixLength "a=b" `shouldBe` Just 1+ prefixLength "foo=bar=baz" `shouldBe` Just 3++ it "returns Nothing for lines without '='" $ do+ prefixLength "noequals" `shouldBe` Nothing+ prefixLength "" `shouldBe` Nothing++ describe "adjustLine" $ do+ it "pads the prefix to match the desired length" $ do+ adjustLine 5 "key=value" `shouldBe` "key =value"+ adjustLine 3 "a=b" `shouldBe` "a =b"++ it "does not add spaces if the prefix is already at the desired length" $ do+ adjustLine 3 "foo=bar" `shouldBe` "foo=bar"++ it "handles lines without '=' correctly" $ do+ adjustLine 5 "noequals" `shouldBe` "noequals"++ describe "adjustText" $ do+ it "aligns '=' across multiple lines" $ do+ adjustText "key=value\na=b" `shouldBe` "key=value\na =b"+ adjustText "x=y\nlong=var" `shouldBe` "x =y\nlong=var"++ it "leaves lines without '=' unchanged" $ do+ adjustText "hello\nworld" `shouldBe` "hello\nworld"++ it "handles empty input correctly" $ do+ adjustText "" `shouldBe` ""