From 8067edb9bfff08bbf03aa67c6cc57efbc20f4531 Mon Sep 17 00:00:00 2001 From: Jaro Date: Sat, 20 May 2023 14:20:06 +0200 Subject: [PATCH] Deduplicate code in SpanData. --- test/Data/Text/ParagraphLayout/SpanData.hs | 82 ++++++---------------- 1 file changed, 20 insertions(+), 62 deletions(-) diff --git a/test/Data/Text/ParagraphLayout/SpanData.hs b/test/Data/Text/ParagraphLayout/SpanData.hs index 810f1f5..e5ca23b 100644 --- a/test/Data/Text/ParagraphLayout/SpanData.hs +++ b/test/Data/Text/ParagraphLayout/SpanData.hs @@ -19,84 +19,42 @@ import Data.Text.ParagraphLayout.Internal.TextOptions defaultBox :: Direction -> ResolvedBox () defaultBox dir = ResolvedBox () 0 defaultBoxOptions dir -emptySpan :: Font -> ResolvedSpan () -emptySpan font = ResolvedSpan +sampleSpan :: Direction -> String -> String -> Font -> ResolvedSpan () +sampleSpan dir lang str font = ResolvedSpan { spanUserData = () , spanIndex = 0 , spanOffsetInParagraph = 0 - , spanText = pack "" - , spanTextOptions = (defaultTextOptions DirLTR) + , spanText = text + , spanTextOptions = (defaultTextOptions dir) { textFont = font , textLineHeight = Normal - , textLanguage = "en" + , textLanguage = lang } - , spanBoxes = [defaultBox DirLTR] + , spanBoxes = [defaultBox dir] , spanLineBreaks = [] , spanCharacterBreaks = [] } + where + text = pack str + +emptySpan :: Font -> ResolvedSpan () +emptySpan = sampleSpan DirLTR "en" + "" czechHello :: Font -> ResolvedSpan () -czechHello font = ResolvedSpan - { spanUserData = () - , spanIndex = 0 - , spanOffsetInParagraph = 0 - , spanText = pack "Ahoj, světe!" - , spanTextOptions = (defaultTextOptions DirLTR) - { textFont = font - , textLineHeight = Normal - , textLanguage = "cs" - } - , spanBoxes = [defaultBox DirLTR] - , spanLineBreaks = [] - , spanCharacterBreaks = [] - } +czechHello = sampleSpan DirLTR "cs" + "Ahoj, světe!" arabicHello :: Font -> ResolvedSpan () -arabicHello font = ResolvedSpan - { spanUserData = () - , spanIndex = 0 - , spanOffsetInParagraph = 0 - , spanText = pack "سلام" - , spanTextOptions = (defaultTextOptions DirRTL) - { textFont = font - , textLineHeight = Normal - , textLanguage = "ar" - } - , spanBoxes = [defaultBox DirRTL] - , spanLineBreaks = [] - , spanCharacterBreaks = [] - } +arabicHello = sampleSpan DirRTL "ar" + "سلام" serbianMixedScript :: Font -> ResolvedSpan () -serbianMixedScript font = ResolvedSpan - { spanUserData = () - , spanIndex = 0 - , spanOffsetInParagraph = 0 - , spanText = pack "Vikipedija (Википедија)" - , spanTextOptions = (defaultTextOptions DirLTR) - { textFont = font - , textLineHeight = Normal - , textLanguage = "sr" - } - , spanBoxes = [defaultBox DirLTR] - , spanLineBreaks = [] - , spanCharacterBreaks = [] - } +serbianMixedScript = sampleSpan DirLTR "sr" + "Vikipedija (Википедија)" -- | Source: -- englishAroundArabic :: Font -> ResolvedSpan () -englishAroundArabic font = ResolvedSpan - { spanUserData = () - , spanIndex = 0 - , spanOffsetInParagraph = 0 - , spanText = pack "The title is مفتاح معايير الويب in Arabic." - , spanTextOptions = (defaultTextOptions DirLTR) - { textFont = font - , textLineHeight = Normal - , textLanguage = "en" - } - , spanBoxes = [defaultBox DirLTR] - , spanLineBreaks = [] - , spanCharacterBreaks = [] - } +englishAroundArabic = sampleSpan DirLTR "en" + "The title is مفتاح معايير الويب in Arabic." -- 2.30.2