Skip to content

Commit 4ee26cb

Browse files
committed
Cut fun tests like with Jest
1 parent bd613c5 commit 4ee26cb

File tree

1 file changed

+188
-172
lines changed

1 file changed

+188
-172
lines changed

tests/testthat/test-funs.R

Lines changed: 188 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,202 @@
1-
test_that("create_overlay works", {
2-
# Step 1, testing with label and style
3-
res <- create_overlay("xyz", "this", "my style")
4-
5-
expect_true(length(res) == 3)
6-
expect_named(res, c("elementId", "label", "style"))
7-
expect_equal(res$elementId, "xyz")
8-
expect_equal(res$label, "this")
9-
expect_equal(res$style, "my style")
10-
11-
# Step 2, testing with no label, and style
12-
res <- create_overlay("this", NULL, "my style")
13-
14-
expect_true(length(res) == 2)
15-
expect_named(res, c("elementId", "style"))
16-
expect_equal(res$elementId, "this")
17-
expect_equal(res$style, "my style")
18-
19-
# Step 3, testing with label and no style
20-
res <- create_overlay("this", "my label", NULL)
21-
22-
expect_true(length(res) == 2)
23-
expect_named(res, c("elementId", "label"))
24-
expect_equal(res$elementId, "this")
25-
expect_equal(res$label, "my label")
1+
describe("create_overlay works", {
2+
test_that("with label and style", {
3+
res <- create_overlay("xyz", "this", "my style")
4+
5+
expect_true(length(res) == 3)
6+
expect_named(res, c("elementId", "label", "style"))
7+
expect_equal(res$elementId, "xyz")
8+
expect_equal(res$label, "this")
9+
expect_equal(res$style, "my style")
10+
})
11+
12+
test_that("with no label, and style", {
13+
res <- create_overlay("this", NULL, "my style")
14+
15+
expect_true(length(res) == 2)
16+
expect_named(res, c("elementId", "style"))
17+
expect_equal(res$elementId, "this")
18+
expect_equal(res$style, "my style")
19+
})
20+
21+
test_that("with label and no style", {
22+
res <- create_overlay("this", "my label", NULL)
23+
24+
expect_true(length(res) == 2)
25+
expect_named(res, c("elementId", "label"))
26+
expect_equal(res$elementId, "this")
27+
expect_equal(res$label, "my label")
28+
})
2629
})
2730

28-
test_that("create_style works", {
29-
# Step 1, testing with font, fill and stroke
30-
res <- create_style("my font", "my fill", "my stroke")
31-
32-
expect_true(length(res) == 3)
33-
expect_named(res, c("font", "fill", "stroke"))
34-
expect_equal(res$font, "my font")
35-
expect_equal(res$fill, "my fill")
36-
expect_equal(res$stroke, "my stroke")
37-
38-
# Step 2, testing with no font, fill and stroke
39-
res <- create_style(NULL, "my fill", "my stroke")
40-
41-
expect_true(length(res) == 2)
42-
expect_named(res, c("fill", "stroke"))
43-
expect_equal(res$fill, "my fill")
44-
expect_equal(res$stroke, "my stroke")
45-
46-
# Step 3, testing with font, no fill, and stroke
47-
res <- create_style("my font", NULL, "my stroke")
48-
49-
expect_true(length(res) == 2)
50-
expect_named(res, c("font", "stroke"))
51-
expect_equal(res$font, "my font")
52-
expect_equal(res$stroke, "my stroke")
53-
54-
# Step 4, testing with font, fill and no stroke
55-
res <- create_style("my font", "my fill", NULL)
56-
57-
expect_true(length(res) == 2)
58-
expect_named(res, c("font", "fill"))
59-
expect_equal(res$font, "my font")
60-
expect_equal(res$fill, "my fill")
31+
describe("create_style works", {
32+
test_that("with font, fill and stroke", {
33+
res <- create_style("my font", "my fill", "my stroke")
34+
35+
expect_true(length(res) == 3)
36+
expect_named(res, c("font", "fill", "stroke"))
37+
expect_equal(res$font, "my font")
38+
expect_equal(res$fill, "my fill")
39+
expect_equal(res$stroke, "my stroke")
40+
})
41+
42+
test_that("with no font, fill and stroke", {
43+
res <- create_style(NULL, "my fill", "my stroke")
44+
45+
expect_true(length(res) == 2)
46+
expect_named(res, c("fill", "stroke"))
47+
expect_equal(res$fill, "my fill")
48+
expect_equal(res$stroke, "my stroke")
49+
})
50+
51+
test_that("with font, no fill, and stroke", {
52+
res <- create_style("my font", NULL, "my stroke")
53+
54+
expect_true(length(res) == 2)
55+
expect_named(res, c("font", "stroke"))
56+
expect_equal(res$font, "my font")
57+
expect_equal(res$stroke, "my stroke")
58+
})
59+
60+
test_that("with font, fill and no stroke", {
61+
res <- create_style("my font", "my fill", NULL)
62+
63+
expect_true(length(res) == 2)
64+
expect_named(res, c("font", "fill"))
65+
expect_equal(res$font, "my font")
66+
expect_equal(res$fill, "my fill")
67+
})
6168
})
6269

63-
test_that("create_font works", {
64-
# Step 1, testing with color and size
65-
res <- create_font("my color", "my size")
66-
67-
expect_true(length(res) == 2)
68-
expect_named(res, c("color", "size"))
69-
expect_equal(res$color, "my color")
70-
expect_equal(res$size, "my size")
71-
72-
# Step 2, testing with no color, and size
73-
res <- create_font(NULL, "my size")
74-
75-
expect_true(length(res) == 1)
76-
expect_named(res, c("size"))
77-
expect_equal(res$size, "my size")
78-
79-
# Step 3, testing with color and no stroke
80-
res <- create_font("my color", NULL)
81-
82-
expect_true(length(res) == 1)
83-
expect_named(res, c("color"))
70+
describe("create_font works", {
71+
test_that("with color and size", {
72+
res <- create_font("my color", "my size")
73+
74+
expect_true(length(res) == 2)
75+
expect_named(res, c("color", "size"))
76+
expect_equal(res$color, "my color")
77+
expect_equal(res$size, "my size")
78+
})
79+
80+
test_that("with no color, and size", {
81+
res <- create_font(NULL, "my size")
82+
83+
expect_true(length(res) == 1)
84+
expect_named(res, c("size"))
85+
expect_equal(res$size, "my size")
86+
})
87+
88+
test_that("with color and no stroke", {
89+
res <- create_font("my color", NULL)
90+
91+
expect_true(length(res) == 1)
92+
expect_named(res, c("color"))
93+
})
8494
})
8595

86-
test_that("create_fill works", {
87-
# Step 1, testing with color
88-
res <- create_fill("my color")
89-
90-
expect_true(length(res) == 1)
91-
expect_named(res, c("color"))
92-
expect_equal(res$color, "my color")
93-
94-
# Step 2, testing with no color
95-
res <- create_fill(NULL)
96-
97-
expect_true(length(res) == 0)
96+
describe("create_fill works", {
97+
test_that("with color", {
98+
res <- create_fill("my color")
99+
100+
expect_true(length(res) == 1)
101+
expect_named(res, c("color"))
102+
expect_equal(res$color, "my color")
103+
})
104+
105+
test_that("with no color", {
106+
res <- create_fill(NULL)
107+
108+
expect_true(length(res) == 0)
109+
})
98110
})
99111

100-
test_that("create_stroke works", {
101-
# Step 1, testing with color
102-
res <- create_stroke("my color")
103-
104-
expect_true(length(res) == 1)
105-
expect_named(res, c("color"))
106-
expect_equal(res$color, "my color")
107-
108-
# Step 2, testing with no color
109-
res <- create_stroke(NULL)
110-
111-
expect_true(length(res) == 0)
112+
describe("create_stroke works", {
113+
test_that("with color", {
114+
res <- create_stroke("my color")
115+
116+
expect_true(length(res) == 1)
117+
expect_named(res, c("color"))
118+
expect_equal(res$color, "my color")
119+
})
120+
121+
test_that("with no color", {
122+
res <- create_stroke(NULL)
123+
124+
expect_true(length(res) == 0)
125+
})
112126
})
113127

114-
test_that("build_bpmnContent works", {
115-
# Step 1, testing xml_doc, no overlays
116-
res <- build_bpmnContent(
117-
xml2::read_xml(
118-
system.file("examples/Email_Voting.bpmn",
119-
package = "bpmnVisualizationR")
120-
),
121-
enableDefaultOverlayStyle = TRUE
122-
)
123-
124-
expect_true(length(res) == 2)
125-
expect_named(res, c("bpmnContent", "enableDefaultOverlayStyle"))
126-
127-
# Step 2, testing xml_doc, overlays
128-
res <- build_bpmnContent(
129-
xml2::read_xml(
130-
system.file("examples/Email_Voting.bpmn",
131-
package = "bpmnVisualizationR")
132-
),
133-
enableDefaultOverlayStyle = FALSE,
134-
overlays = "this"
135-
)
136-
137-
expect_true(length(res) == 3)
138-
expect_named(res, c("bpmnContent", "enableDefaultOverlayStyle", "overlays"))
139-
140-
expect_equal(res$overlays, list("this"))
141-
142-
# Step 3, testing xml_doc, overlays is list
143-
res <- build_bpmnContent(
144-
xml2::read_xml(
145-
system.file("examples/Email_Voting.bpmn",
146-
package = "bpmnVisualizationR")
147-
),
148-
enableDefaultOverlayStyle = FALSE,
149-
overlays = list(
150-
create_overlay("bpmn_element_id_1", "42"),
151-
create_overlay("bpmn_element_id_2", "9")
128+
describe("build_bpmnContent works", {
129+
test_that("with xml_doc and no overlays", {
130+
res <- build_bpmnContent(
131+
xml2::read_xml(
132+
system.file("examples/Email_Voting.bpmn", package = "bpmnVisualizationR")
133+
),
134+
enableDefaultOverlayStyle = TRUE
152135
)
153-
)
154-
155-
expect_true(length(res) == 3)
156-
expect_named(res,
157-
c("bpmnContent", "enableDefaultOverlayStyle", "overlays"))
158-
159-
# Step 4, testing character, no overlays
160-
res <- build_bpmnContent(
161-
paste(readLines(
162-
system.file("examples/Email_Voting.bpmn",
163-
package = "bpmnVisualizationR")
164-
),
165-
collapse = " "),
166-
enableDefaultOverlayStyle = TRUE
167-
)
168-
169-
expect_true(length(res) == 2)
170-
expect_named(res, c("bpmnContent", "enableDefaultOverlayStyle"))
171-
172-
# Step 5, testing character, no overlays
173-
res <- build_bpmnContent(
174-
system.file("examples/Email_Voting.bpmn",
175-
package = "bpmnVisualizationR"),
176-
enableDefaultOverlayStyle = TRUE
177-
)
178-
179-
expect_true(length(res) == 2)
180-
expect_named(res, c("bpmnContent", "enableDefaultOverlayStyle"))
181-
182-
# Step 6, error
183-
expect_error(build_bpmnContent(iris))
136+
137+
expect_true(length(res) == 2)
138+
expect_named(res, c("bpmnContent", "enableDefaultOverlayStyle"))
139+
})
140+
141+
test_that("with xml_doc and overlays", {
142+
res <- build_bpmnContent(
143+
xml2::read_xml(
144+
system.file("examples/Email_Voting.bpmn", package = "bpmnVisualizationR")
145+
),
146+
enableDefaultOverlayStyle = FALSE,
147+
overlays = "this"
148+
)
149+
150+
expect_true(length(res) == 3)
151+
expect_named(res, c("bpmnContent", "enableDefaultOverlayStyle", "overlays"))
152+
153+
expect_equal(res$overlays, list("this"))
154+
})
155+
156+
test_that("with xml_doc and overlays is list", {
157+
res <- build_bpmnContent(
158+
xml2::read_xml(
159+
system.file("examples/Email_Voting.bpmn", package = "bpmnVisualizationR")
160+
),
161+
enableDefaultOverlayStyle = FALSE,
162+
overlays = list(
163+
create_overlay("bpmn_element_id_1", "42"),
164+
create_overlay("bpmn_element_id_2", "9")
165+
)
166+
)
167+
168+
expect_true(length(res) == 3)
169+
expect_named(res, c("bpmnContent", "enableDefaultOverlayStyle", "overlays"))
170+
})
171+
172+
test_that("with character and no overlays", {
173+
res <- build_bpmnContent(
174+
paste(
175+
readLines(
176+
system.file("examples/Email_Voting.bpmn", package = "bpmnVisualizationR")
177+
),
178+
collapse = " "
179+
),
180+
enableDefaultOverlayStyle = TRUE
181+
)
182+
183+
expect_true(length(res) == 2)
184+
expect_named(res, c("bpmnContent", "enableDefaultOverlayStyle"))
185+
})
186+
187+
test_that("with character and no overlays", {
188+
res <- build_bpmnContent(
189+
system.file("examples/Email_Voting.bpmn", package = "bpmnVisualizationR"),
190+
enableDefaultOverlayStyle = TRUE
191+
)
192+
193+
expect_true(length(res) == 2)
194+
expect_named(res, c("bpmnContent", "enableDefaultOverlayStyle"))
195+
})
196+
197+
test_that("error", {
198+
expect_error(build_bpmnContent(iris))
199+
})
184200
})
185201

186202
test_that("not_null_list works", {

0 commit comments

Comments
 (0)