packages feed

phino-0.0.166 / test / AbridgeSpec.hs

{-# LANGUAGE OverloadedStrings #-}-- SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com-- SPDX-License-Identifier: MITmodule AbridgeSpec whereimport ASTimport Abridge (abridged)import Data.Text qualified as Timport Encoding (Encoding (..))import Lining (LineFormat (..))import Margin (defaultMargin)import Printer (printExpressionWith)import Sugar (SugarType (..))import Test.Hspec (Spec, describe, it, shouldBe)import Text.Printf (printf)spec :: Specspec =  describe "abridged" $ do    it "leaves a formation no longer than the width as it is" $      printExpressionWith        (const (abridged True 64))        (ExFormation [BiTau (AtLabel "kübel") (ExDispatch ExXi (AtLabel "wand")), BiVoid (AtLabel "zaun")])        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "⟦ kübel ↦ wand, zaun ↦ ∅ ⟧"    it "keeps a formation exactly as wide as the width" $      printExpressionWith        (const (abridged True 68))        (ExFormation (map (\idx -> BiTau (AtLabel (T.pack ("ort-" <> show idx))) ExRoot) [1 .. 6 :: Int]))        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "⟦ ort-1 ↦ Φ, ort-2 ↦ Φ, ort-3 ↦ Φ, ort-4 ↦ Φ, ort-5 ↦ Φ, ort-6 ↦ Φ ⟧"    it "folds a formation one character wider than the width" $      printExpressionWith        (const (abridged True 67))        (ExFormation (map (\idx -> BiTau (AtLabel (T.pack ("ort-" <> show idx))) ExRoot) [1 .. 6 :: Int]))        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "⟦ +6 ⟧"    it "keeps the data and the λ of a long formation and folds the rest into a count" $      printExpressionWith        (const (abridged True 64))        ( ExFormation            ( BiDelta (BtMany ["00", "77", "66"])                : BiLambda (Function "L_xxx")                : map (\idx -> BiVoid (AtLabel (T.pack ("atributo-" <> show idx)))) [1 .. 34 :: Int]            )        )        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "⟦ Δ ⤍ 00-77-66, λ ⤍ L_xxx, +34 ⟧"    it "keeps the φ of a long formation and folds the formation it holds" $      printExpressionWith        (const (abridged True 64))        ( ExFormation            [ BiTau (AtLabel "hund") ExRoot            , BiTau AtPhi (ExFormation (map (\idx -> BiTau (AtLabel (T.pack ("pfote-" <> show idx))) ExRoot) [1 .. 9 :: Int]))            , BiTau (AtLabel "katze") ExXi            ]        )        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "⟦ φ ↦ ⟦ +9 ⟧, +2 ⟧"    it "keeps a void φ of a long formation and folds the rest into a count" $      printExpressionWith        (const (abridged True 64))        ( ExFormation            ( BiLambda (Function "L_weit")                : BiVoid AtPhi                : map (\idx -> BiTau (AtLabel (T.pack ("anfang-" <> show idx))) ExRoot) [1 .. 5 :: Int]            )        )        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "⟦ λ ⤍ L_weit, φ ↦ ∅, +5 ⟧"    it "leaves an application no longer than the width as it is" $      printExpressionWith        (const (abridged True 64))        (ExApplication (ExApplication (ExDispatch ExRoot (AtLabel "brücke")) (ArTau (AtLabel "links") ExXi)) (ArTau (AtLabel "rechts") ExRoot))        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "Φ.brücke( links ↦ ξ, rechts ↦ Φ )"    it "folds the arguments of an application wider than the width into a count" $      printExpressionWith        (const (abridged True 64))        (foldl (\expr idx -> ExApplication expr (ArTau (AtLabel (T.pack ("strasse-" <> show idx))) ExRoot)) (ExDispatch ExRoot (AtLabel "stadt")) [1 .. 7 :: Int])        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "Φ.stadt( +7 )"    it "folds a long application in the φ of a long formation" $      printExpressionWith        (const (abridged True 64))        ( ExFormation            [ BiTau (AtLabel "wolke") ExRoot            , BiTau AtPhi (foldl (\expr idx -> ExApplication expr (ArTau (AtLabel (T.pack ("regen-" <> show idx))) ExXi)) (ExDispatch ExXi (AtLabel "himmel")) [1 .. 8 :: Int])            ]        )        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "⟦ φ ↦ himmel( +8 ), +1 ⟧"    it "folds a long application its dispatch is made of" $      printExpressionWith        (const (abridged True 64))        (ExDispatch (foldl (\expr idx -> ExApplication expr (ArAlpha (Alpha idx) (ExDispatch ExRoot (AtLabel "langer-name")))) (ExDispatch ExRoot (AtLabel "fluss")) [0 .. 5 :: Int]) (AtLabel "ufer"))        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "Φ.fluss( +6 ).ufer"    it "cuts a long byte string to its first bytes, its last bytes and the count of the bytes between them" $      printExpressionWith        (const (abridged True 64))        (ExFormation [BiDelta (BtMany (map (printf "%02X") [7 .. 51 :: Int]))])        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "07-08-..(41b)..-32-33:Δ"    it "cuts a long byte string inside a formation too short to fold" $      printExpressionWith        (const (abridged True 64))        (ExFormation [BiTau (AtLabel "k") (ExFormation [BiDelta (BtMany ["01", "02", "03", "04", "05", "06", "07", "08", "09", "0A"])])])        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "01-02-..(6b)..-09-0A:Δ:k"    it "keeps a long byte string whole unless told to cut the data" $      printExpressionWith        (const (abridged False 64))        (ExFormation [BiDelta (BtMany (map (printf "%02X") [3 .. 19 :: Int]))])        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F-10-11-12-13:Δ"    it "folds a long formation and keeps its long byte string whole unless told to cut the data" $      printExpressionWith        (const (abridged False 64))        (ExFormation (BiDelta (BtMany ["30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "41", "42"]) : map (\idx -> BiVoid (AtLabel (T.pack ("fenster-" <> show idx)))) [1 .. 7 :: Int]))        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "⟦ Δ ⤍ 30-31-32-33-34-35-36-37-38-39-41-42, +7 ⟧"    it "keeps a byte string of eight bytes whole" $      printExpressionWith        (const (abridged True 64))        (ExFormation (BiDelta (BtMany ["40", "60", "E0", "00", "00", "00", "00", "01"]) : map (\idx -> BiVoid (AtLabel (T.pack ("ränder-" <> show idx)))) [1 .. 5 :: Int]))        (SWEET, UNICODE, SINGLELINE, defaultMargin)        `shouldBe` "⟦ Δ ⤍ 40-60-E0-00-00-00-00-01, +5 ⟧"    it "spells a folded formation the same way in ASCII" $      printExpressionWith        (const (abridged True 64))        (ExFormation (BiLambda (Function "F") : map (\idx -> BiVoid (AtLabel (T.pack ("sehr-langes-" <> show idx)))) [1 .. 5 :: Int]))        (SWEET, ASCII, SINGLELINE, defaultMargin)        `shouldBe` "[[ L> F, +5 ]]"