implemented convert function

This commit is contained in:
Jonathan Lamothe 2020-11-09 13:50:19 -05:00
parent 0a041c4f1f
commit 3674dc72c8
4 changed files with 81 additions and 3 deletions

View File

@ -29,6 +29,8 @@ module SubFix (
encode,
) where
import Data.Char (chr)
-- | Defines a caption group
data Caption = Caption
{ capID :: Int
@ -43,7 +45,7 @@ data Caption = Caption
-- | Applies the transformations to a caption group
convert :: Caption -> Caption
convert = undefined
convert c = c { capText = editText $ capText c }
-- | Decodes the text of a subtitle file
decode
@ -58,4 +60,16 @@ decode = undefined
encode :: [Caption] -> String
encode = undefined
editText :: String -> String
editText = checkCaret . checkNotes
checkCaret :: String -> String
checkCaret ('^' : str) = "{\\an8}" ++ str
checkCaret str = str
checkNotes :: String -> String
checkNotes "" = ""
checkNotes ('#' : '#' : str) = chr 0x2669 : checkNotes str
checkNotes (ch : str) = ch : checkNotes str
--jl

View File

@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: d007e87bb36671373e831d22ee6d19cedeec2d81a3e1543f413d672dc39ce9e5
-- hash: 0bbe0a65faa072211284afd0838b32a74ded6fa51252fc0c023e92ba5da20c8f
name: subfix
version: 0.0.0
@ -55,6 +55,7 @@ test-suite subfix-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
SubFix.ConvertSpec
Paths_subfix
hs-source-dirs:
test

View File

@ -20,7 +20,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import Test.Hspec (hspec)
import qualified SubFix.ConvertSpec as Convert
main :: IO ()
main = hspec $ return ()
main = hspec Convert.spec
--jl

View File

@ -0,0 +1,61 @@
{-
subfix
Copyright (C) Jonathan Lamothe <jonathan@jlamothe.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-}
module SubFix.ConvertSpec (spec) where
import Data.Char (chr)
import Test.Hspec (Spec, context, describe, it, shouldBe)
import SubFix (Caption (..), convert)
spec :: Spec
spec = describe "convert" $ mapM_
( \(input, expected) -> context (show input) $
it ("should be " ++ show expected) $
convert input `shouldBe` expected
)
-- input, expected
[ ( regular, regular )
, ( raised, raised' )
, ( midCaret, midCaret )
, ( note, note' )
, ( both, both' )
]
where
regular = base "foo"
raised = base "^foo"
raised' = base "{\\an8}foo"
midCaret = base "foo^bar"
note = base "foo##bar"
note' = base $ "foo" ++ [chr 0x2669] ++ "bar"
both = base "^foo##bar"
both' = base $ "{\\an8}foo" ++ [chr 0x2669] ++ "bar"
base str = Caption
{ capID = 1
, capStart = 2
, capEnd = 3
, capText = str
}
--jl