1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
5 Copyright : © 2006-2020 John MacFarlane
6 License : GNU GPL, version 2 or above
8 Maintainer : John MacFarlane <jgm@berkeley@edu>
10 Portability : portable
12Tests for functions used in many parts of the library.
14module Tests.Shared (tests) where
17import System.FilePath.Posix (joinPath)
19import Test.Tasty.HUnit (assertBool, testCase, (@?=))
20import Text.Pandoc.Arbitrary ()
21import Text.Pandoc.Builder
22import Text.Pandoc.Shared
23import Text.Pandoc.Writers.Shared (toLegacyTable)
26tests = [ testGroup "compactifyDL"
27 [ testCase "compactifyDL with empty def" $
28 assertBool "compactifyDL"
29 (let x = [(str "word", [para (str "def"), mempty])]
30 in compactifyDL x == x)
32 , testGroup "collapseFilePath" testCollapse
33 , testGroup "toLegacyTable" testLegacyTable
36testCollapse :: [TestTree]
37testCollapse = map (testCase "collapse")
38 [ collapseFilePath (joinPath [ ""]) @?= joinPath [ ""]
39 , collapseFilePath (joinPath [ ".","foo"]) @?= joinPath [ "foo"]
40 , collapseFilePath (joinPath [ ".",".","..","foo"]) @?= joinPath [ joinPath ["..", "foo"]]
41 , collapseFilePath (joinPath [ "..","foo"]) @?= joinPath [ "..","foo"]
42 , collapseFilePath (joinPath [ "","bar","..","baz"]) @?= joinPath [ "","baz"]
43 , collapseFilePath (joinPath [ "","..","baz"]) @?= joinPath [ "","..","baz"]
44 , collapseFilePath (joinPath [ ".","foo","..",".","bar","..",".",".","baz"]) @?= joinPath [ "baz"]
45 , collapseFilePath (joinPath [ ".",""]) @?= joinPath [ ""]
46 , collapseFilePath (joinPath [ ".",".",""]) @?= joinPath [ ""]
47 , collapseFilePath (joinPath [ "..",""]) @?= joinPath [ ".."]
48 , collapseFilePath (joinPath [ "..",".",""]) @?= joinPath [ ".."]
49 , collapseFilePath (joinPath [ ".","..",""]) @?= joinPath [ ".."]
50 , collapseFilePath (joinPath [ "..","..",""]) @?= joinPath [ "..",".."]
51 , collapseFilePath (joinPath [ "parent","foo","baz","..","bar"]) @?= joinPath [ "parent","foo","bar"]
52 , collapseFilePath (joinPath [ "parent","foo","baz","..","..","bar"]) @?= joinPath [ "parent","bar"]
53 , collapseFilePath (joinPath [ "parent","foo",".."]) @?= joinPath [ "parent"]
54 , collapseFilePath (joinPath [ "","parent","foo","..","..","bar"]) @?= joinPath [ "","bar"]
55 , collapseFilePath (joinPath [ "",".","parent","foo"]) @?= joinPath [ "","parent","foo"]]
57testLegacyTable :: [TestTree]
59 [ testCase "decomposes a table with head" $ gen1 @?= expect1
60 , testCase "decomposes a table without head" $ gen2 @?= expect2
63 pln = toList . plain . str
64 cl a h w = Cell ("", [], []) AlignDefault h w $ pln a
65 rws = map $ Row nullAttr
66 th = TableHead nullAttr . rws
67 tb n x y = TableBody nullAttr n (rws x) (rws y)
68 tf = TableFoot nullAttr . rws
71 [[cl "a" 1 1, cl "b" 2 2]
75 [[cl "e" 3 1,cl "f" 3 2]
79 [[emptyCell,emptyCell,emptyCell]
80 ,[cl "g" 1 1,emptyCell,emptyCell]
83 [[cl "h" 1 2,cl "i" 2 1]
85 caption1 = simpleCaption $ plain "caption"
86 spec1 = replicate 2 (AlignDefault, ColWidth 0.5) ++ [(AlignRight, ColWidthDefault)]
87 expect1 = ( [Str "caption"]
88 , replicate 2 AlignDefault ++ [AlignRight]
89 , replicate 2 0.5 ++ [0]
90 , [pln "a", pln "b", mempty]
91 , [[pln "c", mempty, mempty]
92 ,[pln "e", pln "f", mempty]
93 ,[mempty, mempty, mempty]
94 ,[mempty, mempty, mempty]
95 ,[mempty, mempty, mempty]
96 ,[pln "g", mempty, mempty]
97 ,[pln "h", mempty, pln "i"]
98 ,[pln "j", mempty, mempty]]
100 gen1 = toLegacyTable caption1 spec1 (th headRows1) [body1] (tf footRows1)
103 , replicate 2 AlignDefault ++ [AlignRight]
104 , replicate 2 0.5 ++ [0]
106 , [[pln "e", pln "f", mempty]
107 ,[mempty, mempty, mempty]
108 ,[mempty, mempty, mempty]
109 ,[mempty, mempty, mempty]
110 ,[pln "g", mempty, mempty]
111 ,[pln "h", mempty, pln "i"]
112 ,[pln "j", mempty, mempty]]
114 gen2 = toLegacyTable emptyCaption spec1 (th []) [body1] (tf footRows1)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list