summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-03-09 02:28:46 +0100
committertv <tv@krebsco.de>2026-03-09 02:28:46 +0100
commitbff24914f21800719c99c80165a8c3a3759311e7 (patch)
tree80f1378990574deec4a10d7171668bc621336a55
parent230e538e41360f2018db9a8b5274402d0b3200b6 (diff)
test: Text -> String & no OverloadedStrings
This avoids needing type annotations for string literals.
-rw-r--r--test/Spec.hs34
-rw-r--r--text-viewport.cabal2
2 files changed, 21 insertions, 15 deletions
diff --git a/test/Spec.hs b/test/Spec.hs
index 70b1815..a886816 100644
--- a/test/Spec.hs
+++ b/test/Spec.hs
@@ -3,7 +3,6 @@ module Main (main) where
import Control.Exception (evaluate)
import Data.HashMap.Strict qualified as HM
import Data.Sequence qualified as Seq
-import Data.Text (Text)
import Data.Text qualified as T
import Data.Vector qualified as V
import System.Clock (Clock(Monotonic), getTime, toNanoSecs)
@@ -40,15 +39,24 @@ shouldRunUnder action maxNs = do
let dt = toNanoSecs (t2 - t1)
dt `shouldSatisfy` (< maxNs)
-mkItem :: T.Text -> Item
+mkItem :: String -> Item String
mkItem t = Item t NoSegments
-mkBuf :: [T.Text] -> Buffer
+mkBuf :: [String] -> Buffer String
mkBuf xs = Buffer.fromList (map mkItem xs)
-mkRS :: Int -> [T.Text] -> RenderState
+mkRS :: Int -> [String] -> RenderState String
mkRS w xs = mkRenderState w (mkBuf xs)
+emptyCache :: HM.HashMap String [(String, String)]
+emptyCache = HM.empty
+
+emptyBuffer :: Buffer String
+emptyBuffer = Buffer.empty
+
+emptyStrings :: [String]
+emptyStrings = []
+
main :: IO ()
main = hspec do
@@ -88,7 +96,7 @@ main = hspec do
Seq.fromList [mkItem "a", mkItem "b", mkItem "c"]
it "modifyItem should fail on out-of-bounds index" do
- evaluate (Buffer.modifyItem 99 id (Buffer.fromList [])) `shouldThrow` anyException
+ evaluate (Buffer.modifyItem 99 id emptyBuffer) `shouldThrow` anyException
it "insertItem should reject out-of-bounds index" do
let b = Buffer.fromList []
@@ -280,11 +288,11 @@ main = hspec do
RS.rsLineCount rs1 `shouldSatisfy` (> RS.rsLineCount rs0)
it "modifyItemRS should fail on out-of-bounds index" do
- evaluate (RS.modifyItemRS 99 id (mkRenderState 10 (Buffer.fromList [])))
+ evaluate (RS.modifyItemRS 99 id (mkRenderState 10 emptyBuffer))
`shouldThrow` anyException
it "insertItem should reject out-of-bounds index" do
- let rs = mkRenderState 10 (Buffer.fromList [])
+ let rs = mkRenderState 10 emptyBuffer
rs' = RS.insertItem 5 (Item "x" NoSegments) rs
RS.rsBuffer rs' `shouldBe` RS.rsBuffer rs
@@ -293,7 +301,7 @@ main = hspec do
evaluate (RS.deleteItem 5 rs) `shouldThrow` anyException
it "replaceItem should handle out-of-bounds index consistently" do
- let rs = mkRenderState 10 (Buffer.fromList [])
+ let rs = mkRenderState 10 emptyBuffer
evaluate (RS.replaceItem 0 (Item "x" NoSegments) rs)
`shouldThrow` anyException
@@ -359,7 +367,7 @@ main = hspec do
it "hyphenateWord splits German words" do
let lang = H.German_1996
- hyphenateWord lang "Schifffahrt" `shouldSatisfy` (not . null)
+ hyphenateWord lang (T.pack "Schifffahrt") `shouldSatisfy` (not . null)
it "scoreCandidate is deterministic for identical candidates" do
let c = ("abcdefghijk", ["abcdefgh","ijk"], False)
@@ -381,9 +389,9 @@ main = hspec do
it "HyphenateSegments should return updated cache" do
let lang = H.German_1996
- cache0 = HM.empty
+ cache0 = emptyCache
_v = applyStrategy (HyphenateSegments lang cache0) 5 0 "Schifffahrt"
- cache0 `shouldNotBe` (HM.empty :: HM.HashMap Text [(Text, Text)])
+ cache0 `shouldNotBe` emptyCache
it "lineCandidates should preserve candidate order" do
let lang = H.German_1996
@@ -395,7 +403,7 @@ main = hspec do
breakWordSafe 1 [family] `shouldBe` [family]
it "scoreCandidate should not always penalize short lines" do
- scoreCandidate 10 ("a",[],False) < scoreCandidate 10 ("a-",[],True)
+ scoreCandidate 10 ("a",emptyStrings,False) < scoreCandidate 10 ("a-",emptyStrings,True)
`shouldBe` True
@@ -463,7 +471,7 @@ main = hspec do
describe "Viewport" do
it "mkViewport should reject non-positive width/height" do
- let rs = mkRenderState 10 (Buffer.fromList [])
+ let rs = mkRenderState 10 emptyBuffer
evaluate (mkViewport 0 0 rs) `shouldThrow` anyException
it "alignBottom should place viewport at last line even when height > total lines" do
diff --git a/text-viewport.cabal b/text-viewport.cabal
index f0099e6..f7a2503 100644
--- a/text-viewport.cabal
+++ b/text-viewport.cabal
@@ -8,8 +8,6 @@ build-type: Simple
common shared-settings
default-language: GHC2024
- default-extensions:
- OverloadedStrings
ghc-options: -Wall -Wextra
library