Skip to content

Commit

Permalink
Data.Music.Lilypond: Add regression test for tempo
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshoglund committed Oct 11, 2021
1 parent 9938c59 commit 6700437
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
37 changes: 30 additions & 7 deletions test/Regression.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import Data.ByteString.Lazy (ByteString, fromStrict)
import qualified Data.Music.Lilypond as Lilypond
import Data.Text (pack)
import Data.Text.Encoding (encodeUtf8)
import Music.Prelude (Music, c, d, e, pseq, timeSignature, (|>))
Expand All @@ -13,16 +13,39 @@ toLilypondRaw :: Music -> IO ByteString
toLilypondRaw music = do
work <- runIOExportM $ toStandardNotation music
(h, ly) <- runIOExportM $ toLy defaultLilypondOptions work
let ly' = h ++ show (Text.Pretty.pretty ly)
toLilypondRaw' h ly

toLilypondRaw' :: String -> Lilypond.Music -> IO ByteString
toLilypondRaw' header ly = do
let ly' = header ++ show (Text.Pretty.pretty ly)
pure $ fromStrict $ encodeUtf8 $ pack ly'

lilypondRegresionTest name =
goldenVsString
name
("test/regression/lilypond" ++ name ++ ".ly")

tests :: [TestTree]
tests =
[ goldenVsString
"tempo-change-generated"
"test/regression/lilypond/tempo-change-generated.ly"
$ do
toLilypondRaw $ c |> timeSignature (3 / 4) (pseq [d, e])
[ lilypondRegresionTest
"tempo-change-generated" -- TODO this is time, not tempo, fix!!
$ toLilypondRaw $ c |> timeSignature (3 / 4) (pseq [d, e]),
lilypondRegresionTest
"data-lilypond-tempo-change-text-generated"
$ toLilypondRaw'
""
( Lilypond.sequential
(Lilypond.Tempo (Just "Allegro") Nothing)
(Lilypond.Note c Nothing [])
),
lilypondRegresionTest
"data-lilypond-tempo-change-bpm-generated"
$ toLilypondRaw'
""
( Lilypond.sequential
(Lilypond.Tempo Nothing (Just (1 / 4, 120)))
(Lilypond.Note c Nothing [])
)
]

main = defaultMain (testGroup "Regression tests" tests)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ \tempo 4 = 120 c,,,, }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ \tempo "Allegro" c,,,, }

0 comments on commit 6700437

Please sign in to comment.