summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMohamed Abdelnour <mohamed.k.abdelnour@gmail.com>2021-05-29 05:44:22 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2021-06-01 22:36:56 +0200
commite91778493204c29d875975b81a52074419bbbfa9 (patch)
treeda2ff101e901530e6fcc16a7b25a8d39b4ca9ab9 /tests
parentf46b90d28df54d67635c009fc4d7ebe4a08b4bec (diff)
Add Literate Haskell syntax test file
Diffstat (limited to 'tests')
-rw-r--r--tests/syntax-tests/highlighted/Literate Haskell/Main.lhs47
-rw-r--r--tests/syntax-tests/source/Literate Haskell/Main.lhs47
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/syntax-tests/highlighted/Literate Haskell/Main.lhs b/tests/syntax-tests/highlighted/Literate Haskell/Main.lhs
new file mode 100644
index 00000000..a32aab33
--- /dev/null
+++ b/tests/syntax-tests/highlighted/Literate Haskell/Main.lhs
@@ -0,0 +1,47 @@
+\documentclass{article}
+
+\begin{document}
+
+\section*{Introduction}
+
+Text outside code environments should follow TeX/LaTeX highlighting.
+
+The code environment delimiters themselves should be highlighted.
+
+Text inside code environments should follow regular Haskell highlighting.
+
+\begin{code}
+import Data.List
+import System.Environment
+import Text.Printf
+
+twoSumN :: Int -> [Int] -> [Int]
+twoSumN _ [] = []
+twoSumN n (x : xs) | (n - x) `elem` xs = [x, n - x]
+ | otherwise = twoSumN n xs
+
+threeSumN :: Int -> [Int] -> [Int]
+threeSumN _ [] = []
+threeSumN n (x : xs) | null partial = threeSumN n xs
+ | otherwise = x : partial
+ where partial = twoSumN (n - x) xs
+\end{code}
+
+Text in-between code environments.
+% LaTeX comment.
+
+\begin{code}
+output :: String -> IO ()
+output path = do
+ input <- sort . map read . filter (not . null) . lines <$> readFile path
+ printf "File: %s\n" path
+ printf " Part 1: %d\n" . product . twoSumN 2020 $ input
+ printf " Part 2: %d\n" . product . threeSumN 2020 $ input
+
+-- Haskell comment inside code environment.
+
+main :: IO ()
+main = getArgs >>= mapM_ output
+\end{code}
+
+\end{document}
diff --git a/tests/syntax-tests/source/Literate Haskell/Main.lhs b/tests/syntax-tests/source/Literate Haskell/Main.lhs
new file mode 100644
index 00000000..e71756a5
--- /dev/null
+++ b/tests/syntax-tests/source/Literate Haskell/Main.lhs
@@ -0,0 +1,47 @@
+\documentclass{article}
+
+\begin{document}
+
+\section*{Introduction}
+
+Text outside code environments should follow TeX/LaTeX highlighting.
+
+The code environment delimiters themselves should be highlighted.
+
+Text inside code environments should follow regular Haskell highlighting.
+
+\begin{code}
+import Data.List
+import System.Environment
+import Text.Printf
+
+twoSumN :: Int -> [Int] -> [Int]
+twoSumN _ [] = []
+twoSumN n (x : xs) | (n - x) `elem` xs = [x, n - x]
+ | otherwise = twoSumN n xs
+
+threeSumN :: Int -> [Int] -> [Int]
+threeSumN _ [] = []
+threeSumN n (x : xs) | null partial = threeSumN n xs
+ | otherwise = x : partial
+ where partial = twoSumN (n - x) xs
+\end{code}
+
+Text in-between code environments.
+% LaTeX comment.
+
+\begin{code}
+output :: String -> IO ()
+output path = do
+ input <- sort . map read . filter (not . null) . lines <$> readFile path
+ printf "File: %s\n" path
+ printf " Part 1: %d\n" . product . twoSumN 2020 $ input
+ printf " Part 2: %d\n" . product . threeSumN 2020 $ input
+
+-- Haskell comment inside code environment.
+
+main :: IO ()
+main = getArgs >>= mapM_ output
+\end{code}
+
+\end{document}