Skip to content

Commit 0e59ed5

Browse files
committed
Extract output test helpers
1 parent 48f9087 commit 0e59ed5

File tree

3 files changed

+47
-57
lines changed

3 files changed

+47
-57
lines changed

test/mudbrick/text_block_test.exs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
defmodule Mudbrick.TextBlockTest do
22
use ExUnit.Case, async: true
33

4-
import Mudbrick.TestHelper,
5-
only: [
6-
bodoni_regular: 0,
7-
bodoni_bold: 0,
8-
franklin_regular: 0
9-
]
4+
import Mudbrick.TestHelper, only: [output: 1]
105

11-
alias Mudbrick.Page
126
alias Mudbrick.TextBlock
137
alias Mudbrick.TextBlock.Line
148
alias Mudbrick.TextBlock.Line.Part
15-
alias Mudbrick.TextBlock.Output
169

1710
test "single write is divided into lines" do
1811
block =
@@ -293,47 +286,4 @@ defmodule Mudbrick.TextBlockTest do
293286
defp operations(ops) do
294287
Enum.map(ops, &Mudbrick.TestHelper.show/1)
295288
end
296-
297-
defp output(f) when is_function(f) do
298-
import Mudbrick
299-
300-
{doc, _contents_obj} =
301-
context =
302-
Mudbrick.new(
303-
title: "My thing",
304-
compress: false,
305-
fonts: %{
306-
a: [file: bodoni_regular()],
307-
b: [file: bodoni_bold()],
308-
c: [file: franklin_regular()]
309-
}
310-
)
311-
|> page(size: Page.size(:letter))
312-
313-
fonts = Mudbrick.Document.root_page_tree(doc).value.fonts
314-
315-
block =
316-
f.(%{
317-
fonts: %{
318-
regular: Map.fetch!(fonts, :a).value,
319-
bold: Map.fetch!(fonts, :b).value,
320-
franklin_regular: Map.fetch!(fonts, :c).value
321-
}
322-
})
323-
324-
ops = Output.from(block).operations
325-
326-
context
327-
|> Mudbrick.ContentStream.put(operations: ops)
328-
|> render()
329-
|> output()
330-
331-
ops
332-
end
333-
334-
defp output(chain) do
335-
tap(chain, fn rendered ->
336-
File.write("test.pdf", rendered)
337-
end)
338-
end
339289
end

test/mudbrick_test.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,4 @@ defmodule MudbrickTest do
399399
"<xmpMM:\\1ID>0000000000000000000000000000000000000000000</xmpMM:\\2ID>"
400400
)
401401
end
402-
403-
def output(chain) do
404-
tap(chain, fn rendered ->
405-
File.write("test.pdf", rendered)
406-
end)
407-
end
408402
end

test/test_helper.exs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ defmodule Mudbrick.TestHelper do
55
@flower Path.join(__DIR__, "fixtures/JPEG_example_flower.jpg") |> File.read!()
66
@example_png Path.join(__DIR__, "fixtures/Example.png") |> File.read!()
77

8+
alias Mudbrick.Page
9+
alias Mudbrick.TextBlock.Output
10+
811
def show(o) do
912
Mudbrick.Object.from(o) |> to_string()
1013
end
@@ -34,6 +37,49 @@ defmodule Mudbrick.TestHelper do
3437
def example_png do
3538
@example_png
3639
end
40+
41+
def output(f) when is_function(f) do
42+
import Mudbrick
43+
44+
{doc, _contents_obj} =
45+
context =
46+
Mudbrick.new(
47+
title: "My thing",
48+
compress: false,
49+
fonts: %{
50+
a: [file: bodoni_regular()],
51+
b: [file: bodoni_bold()],
52+
c: [file: franklin_regular()]
53+
}
54+
)
55+
|> page(size: Page.size(:letter))
56+
57+
fonts = Mudbrick.Document.root_page_tree(doc).value.fonts
58+
59+
block =
60+
f.(%{
61+
fonts: %{
62+
regular: Map.fetch!(fonts, :a).value,
63+
bold: Map.fetch!(fonts, :b).value,
64+
franklin_regular: Map.fetch!(fonts, :c).value
65+
}
66+
})
67+
68+
ops = Output.from(block).operations
69+
70+
context
71+
|> Mudbrick.ContentStream.put(operations: ops)
72+
|> render()
73+
|> output()
74+
75+
ops
76+
end
77+
78+
def output(chain) do
79+
tap(chain, fn rendered ->
80+
File.write("test.pdf", rendered)
81+
end)
82+
end
3783
end
3884

3985
ExUnit.start()

0 commit comments

Comments
 (0)