File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -248,7 +248,9 @@ instance Peekable (Doc Text) where
248248pushDoc :: Doc Text -> Lua ()
249249pushDoc = Lua. pushAnyWithMetatable pushDocMT
250250 where
251- pushDocMT = Lua. ensureUserdataMetatable docTypeName $
251+ pushDocMT = Lua. ensureUserdataMetatable docTypeName $ do
252+ Lua. addfunction " __concat" __concat
253+ Lua. addfunction " __eq" __eq
252254 Lua. addfunction " __tostring" __tostring
253255
254256instance Pushable (Doc Text ) where
@@ -257,3 +259,11 @@ instance Pushable (Doc Text) where
257259-- | Convert to string by rendering without reflowing.
258260__tostring :: Doc Text -> Lua Text
259261__tostring d = return $ Doc. render Nothing d
262+
263+ -- | Concatenate two @'Doc'@.
264+ __concat :: Doc Text -> Doc Text -> Lua (Doc Text )
265+ __concat a b = return (a <> b)
266+
267+ -- | Test @'Doc'@ equality.
268+ __eq :: Doc Text -> Doc Text -> Lua Bool
269+ __eq a b = return (a == b)
Original file line number Diff line number Diff line change @@ -38,6 +38,17 @@ return {
3838 assert .are_equal (doclayout .render (' hello world' ), ' hello world' )
3939 end ),
4040
41+ test (' equality' , function ()
42+ assert .is_truthy (doclayout .literal " true" , doclayout .literal " true" )
43+ end ),
44+
45+ test (' concatenate docs' , function ()
46+ assert .are_equal (
47+ tostring (doclayout .literal ' Rock-' .. doclayout .literal ' Ola' ),
48+ ' Rock-Ola'
49+ )
50+ end ),
51+
4152 test (' has tostring method' , function ()
4253 local str = ' just a literal string for now'
4354 assert .are_equal (tostring (str ), str )
You can’t perform that action at this time.
0 commit comments