diff --git a/src/SubFix.hs b/src/SubFix.hs
index 7bdf11d..c36c50b 100644
--- a/src/SubFix.hs
+++ b/src/SubFix.hs
@@ -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
diff --git a/subfix.cabal b/subfix.cabal
index 4b27623..d1753d1 100644
--- a/subfix.cabal
+++ b/subfix.cabal
@@ -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
diff --git a/test/Spec.hs b/test/Spec.hs
index 62c53ab..f9aec18 100644
--- a/test/Spec.hs
+++ b/test/Spec.hs
@@ -20,7 +20,9 @@ along with this program. If not, see .
import Test.Hspec (hspec)
+import qualified SubFix.ConvertSpec as Convert
+
main :: IO ()
-main = hspec $ return ()
+main = hspec Convert.spec
--jl
diff --git a/test/SubFix/ConvertSpec.hs b/test/SubFix/ConvertSpec.hs
new file mode 100644
index 0000000..125e2ab
--- /dev/null
+++ b/test/SubFix/ConvertSpec.hs
@@ -0,0 +1,61 @@
+{-
+
+subfix
+Copyright (C) Jonathan Lamothe
+
+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 .
+
+-}
+
+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