From 0b2a78cbf854bd0ef02be2ee5cd1aa65315eab1a Mon Sep 17 00:00:00 2001 From: Jaro Date: Thu, 25 May 2023 09:29:06 +0200 Subject: [PATCH] Test spanToRuns independently for scripts/directions. --- .../Text/ParagraphLayout/Internal/RunSpec.hs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs b/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs index b260882..84bf2e3 100644 --- a/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs +++ b/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs @@ -162,3 +162,58 @@ spec = do , runScript = Just "Latn" } ] + -- Unrealistic example where text changes direction + -- without changing script. + it "handles script and direction changes" $ do + let levels = levelsRLE [(4, 1), (4, 2), (8, 1), (4, 2), (3, 1)] + let inputSpan = sampleSpan serbianMixedScript levels + let runs = spanToRuns inputSpan + runs `shouldBe` + [ Run + { runOffsetInSpan = 0 + , runText = pack "Viki" + , runLevel = 1 + , runDirection = Just DirRTL + , runScript = Just "Latn" + } + -- direction change + , Run + { runOffsetInSpan = 4 + , runText = pack "pedi" + , runLevel = 2 + , runDirection = Just DirLTR + , runScript = Just "Latn" + } + -- direction change + , Run + { runOffsetInSpan = 8 + , runText = pack "ja (" + , runLevel = 1 + , runDirection = Just DirRTL + , runScript = Just "Latn" + } + -- script change + , Run + { runOffsetInSpan = 12 + , runText = pack "Вики" + , runLevel = 1 + , runDirection = Just DirRTL + , runScript = Just "Cyrl" + } + -- direction change + , Run + { runOffsetInSpan = 20 + , runText = pack "педи" + , runLevel = 2 + , runDirection = Just DirLTR + , runScript = Just "Cyrl" + } + -- direction change + , Run + { runOffsetInSpan = 28 + , runText = pack "ја)" + , runLevel = 1 + , runDirection = Just DirRTL + , runScript = Just "Cyrl" + } + ] -- 2.30.2