Skip to content

Commit ec7b1b2

Browse files
committed
Unmarshal empty strings as empty Docs
1 parent a1bbee5 commit ec7b1b2

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/Foreign/Lua/Module/DocLayout.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ docTypeName = "HsLua DocLayout.Doc"
236236
-- converted to plain @'Doc'@ values.
237237
peekDoc :: StackIndex -> Lua (Doc Text)
238238
peekDoc idx = Lua.ltype idx >>= \case
239-
Lua.TypeString -> Doc.literal <$> Lua.peek idx
239+
Lua.TypeString -> let stringToDoc s = if T.null s
240+
then Doc.empty
241+
else Doc.literal s
242+
in stringToDoc <$> Lua.peek idx
240243
Lua.TypeNumber -> Doc.literal <$> Lua.peek idx
241244
_ -> Lua.reportValueOnFailure docTypeName
242245
(`Lua.toAnyWithName` docTypeName)

test/test-doclayout.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ return {
3434
},
3535

3636
group 'Doc type' {
37+
test('empty strings equal the empty Doc', function ()
38+
assert.are_equal(doclayout.empty .. '', doclayout.empty)
39+
end),
40+
3741
test('strings can be used as Doc values', function ()
3842
assert.are_equal(doclayout.render('hello world'), 'hello world')
3943
end),

0 commit comments

Comments
 (0)