Skip to content

Commit 731452c

Browse files
committed
Add more methods to type Doc
1 parent 9429a8c commit 731452c

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/HsLua/Module/DocLayout.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,25 @@ typeDoc = deftype "Doc"
208208
[ method before_non_blank
209209
, method braces
210210
, method brackets
211+
, method cblock
211212
, method chomp
212213
, method double_quotes
213214
, method is_empty
214215
, method flush
216+
, method hang
215217
, method height
218+
, method inside
219+
, method lblock
216220
, method min_offset
221+
, method nest
217222
, method nestle
218223
, method nowrap
219224
, method offset
220225
, method parens
226+
, method prefixed
221227
, method quotes
228+
, method rblock
229+
, method render
222230
, method update_column
223231
, method vfill
224232
]

test/test-doclayout.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ return {
8787
.. doclayout.literal 'How' .. doclayout.space
8888
.. doclayout.literal 'are' .. doclayout.space
8989
.. doclayout.literal 'you?'
90-
assert.are_equal(doclayout.render(greeting, 7), 'Hi! How\nare\nyou?')
90+
assert.are_equal(greeting:render(7), 'Hi! How\nare\nyou?')
9191
end),
9292
test('after_break', function ()
9393
local doc = doclayout.literal 'hi'
9494
+ doclayout.after_break '!'
9595
.. doclayout.after_break '?'
9696
.. doclayout.literal 'x'
9797
.. doclayout.after_break '?'
98-
assert.are_equal(doclayout.render(doc, 2), 'hi\n!x')
98+
assert.are_equal(doc:render(2), 'hi\n!x')
9999
end),
100100
test('before_non_blank', function ()
101101
local doc = doclayout.before_non_blank '!!' .. ' ab'
@@ -148,15 +148,22 @@ return {
148148
end),
149149
test('nowrap', function()
150150
local doc = doclayout.nowrap(doclayout.literal 'first' + 'second')
151-
assert.are_equal(doclayout.render(doc, 8), 'first second')
151+
assert.are_equal(doc:render(8), 'first second')
152152
end),
153153
test('parens', function ()
154154
local doc = doclayout.parens 'lisp'
155155
assert.are_equal(doclayout.render(doc), '(lisp)')
156+
-- as method
157+
assert.are_equal(doc:parens():render(), '((lisp))')
156158
end),
157159
test('prefixed', function ()
158160
local doc = doclayout.prefixed(doclayout.literal 'aa' // 'bb', '# ' )
159161
assert.are_equal(doclayout.render(doc), '# aa\n#\n# bb')
162+
-- as method
163+
assert.are_equal(
164+
(doclayout.literal'aa' // 'bb'):prefixed('# '):render(),
165+
'# aa\n#\n# bb'
166+
)
160167
end),
161168
group 'table helpers' {
162169
test('cblock', function ()

0 commit comments

Comments
 (0)