Skip to content

Commit 12aab48

Browse files
committed
Set // to separate Docs with blank lines
1 parent 87fd397 commit 12aab48

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/Foreign/Lua/Module/DocLayout.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where
5858
import Data.Text (Text)
5959
import Foreign.Lua (Lua, NumResults (..), Optional,
6060
Peekable, Pushable, StackIndex)
61-
import Text.DocLayout (Doc, (<+>), ($$))
61+
import Text.DocLayout (Doc, (<+>), ($$), ($+$))
6262

6363
import qualified Data.Text as T
6464
import qualified Foreign.Lua as Lua
@@ -253,6 +253,7 @@ pushDoc = Lua.pushAnyWithMetatable pushDocMT
253253
Lua.addfunction "__concat" __concat
254254
Lua.addfunction "__div" __div
255255
Lua.addfunction "__eq" __eq
256+
Lua.addfunction "__idiv" __idiv
256257
Lua.addfunction "__tostring" __tostring
257258

258259
instance Pushable (Doc Text) where
@@ -274,6 +275,10 @@ __div a b = return (a $$ b)
274275
__eq :: Doc Text -> Doc Text -> Lua Bool
275276
__eq a b = return (a == b)
276277

278+
-- | @a // b@ puts @a@ above @b@.
279+
__idiv :: Doc Text -> Doc Text -> Lua (Doc Text)
280+
__idiv a b = return (a $+$ b)
281+
277282
-- | Convert to string by rendering without reflowing.
278283
__tostring :: Doc Text -> Lua Text
279284
__tostring d = return $ Doc.render Nothing d

test/test-doclayout.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ return {
6262
end),
6363

6464
test('dividing sets the first above the second', function ()
65+
local first = doclayout.literal 'first'
66+
local second = doclayout.literal 'second'
67+
assert.are_equal(first / second, first .. doclayout.cr .. second)
68+
end),
69+
70+
test('// separates docs with blank line', function ()
6571
local first = doclayout.literal 'first'
6672
local second = doclayout.literal 'second'
67-
assert.are_equal(first / second, first .. doclayout.cr .. second)
73+
assert.are_equal(first // second, first .. doclayout.blankline .. second)
6874
end),
6975
}
7076
}

0 commit comments

Comments
 (0)