Skip to content

Commit 28dfeea

Browse files
make test-styler consistent with rest of tests.
1 parent aa6a21e commit 28dfeea

10 files changed

+1574
-41
lines changed
File renamed without changes.

tests/testthat/strict/non_strict-in_tree

Lines changed: 699 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/strict/strict-in.R

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
test <- function() {
2+
"Double quotes remain as they are"
3+
'Single quotes are converted to double quotes'
4+
'even if the string contains an escaped \' single quote'
5+
'but not if it contains a "double quote'
6+
7+
# Comments are always preserved
8+
9+
function_calls(get_spaces=around_equal)
10+
11+
no_space( after_opening( ), paren( (1 + 2)))
12+
no_space (before_opening (), paren ( (1 + 2)))
13+
no_space(before(closing ), paren((1 + 2) ) )
14+
multi(
15+
line,
16+
call
17+
)
18+
multi_line_empty_call(
19+
)
20+
21+
one_space(after,comma("in","function", args))
22+
23+
{
24+
braced
25+
expression
26+
}
27+
28+
braced("unnamed", {
29+
"function"
30+
call
31+
})
32+
33+
braced(named = {
34+
"function"
35+
call
36+
})
37+
38+
braced("unnamed reduces space", {
39+
})
40+
41+
braced("unnamed adds space space",{
42+
})
43+
44+
braced(named_reduces_space = {
45+
})
46+
47+
braced(named_adds_space = {
48+
})
49+
50+
braced( {
51+
empty_removes_space
52+
})
53+
54+
a%/%b
55+
a%%b
56+
a&&b
57+
a||b
58+
a==b
59+
a!=b
60+
a<=b
61+
a>=b
62+
a<-b
63+
a->b
64+
a=b
65+
a<b
66+
a>b
67+
a*b
68+
a/b
69+
a^b
70+
a&b
71+
a|b
72+
a:=b
73+
74+
a+b
75+
a-b
76+
a++b
77+
a+-b
78+
a++b
79+
a-+b
80+
a--b
81+
a+--b
82+
a--+b
83+
call( + a)
84+
call( - a)
85+
call(5, + a)
86+
call(5, - a)
87+
88+
# Only with conservative settings:
89+
call(
90+
preserves, distance,
91+
after, commas,
92+
given_has,one
93+
)
94+
95+
if(TRUE){
96+
FALSE
97+
}
98+
99+
if(TRUE){
100+
FALSE
101+
}else{
102+
TRUE
103+
}
104+
105+
while(TRUE){
106+
FALSE
107+
}
108+
109+
single_line ( "function" ,call )
110+
111+
multiline (
112+
"function", call )
113+
114+
nested ( function_call ( "in" ,one ,line ) )
115+
116+
nested ( function_call (
117+
"in",
118+
multiple,lines ) )
119+
120+
nested(
121+
function_call ( with ),
122+
many
123+
, first_level_args )
124+
125+
nested(
126+
function_call ( with ), # a comment and
127+
many #more
128+
, first_level_args )
129+
130+
difficult(nested(
131+
"function", call
132+
),
133+
with, more, args
134+
)
135+
}
136+
137+
138+
# formula
139+
lm(a~b+c,data=NA)
140+
lm(a~.-1,data=NA)
141+
a~b:c
142+
a~b :c

tests/testthat/strict/strict-in_tree

Lines changed: 699 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

tests/testthat/test-strict.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
context("styler")
2+
3+
test_that("can style example source file with strict = TRUE", {
4+
expect_warning(test_collection(
5+
"strict", "strict",
6+
transformer = style_text,
7+
strict = TRUE), NA)
8+
})
9+
10+
test_that("can style example source file with strict = FALSE", {
11+
expect_warning(test_collection(
12+
"strict", "non_strict",
13+
transformer = style_text,
14+
strict = FALSE), NA)
15+
})
16+
17+
test_that("removes space at EOL", {
18+
expect_equal(style_text("a() "), "a()")
19+
expect_equal(style_text("a() # comment "), "a() # comment")
20+
})
21+
22+
test_that("removes blank lines at EOF", {
23+
expect_equal(style_text(c("a() ", "", "")), "a()")
24+
})
25+
26+
27+
test_that("Space placed after 'if' and before '('", {
28+
expect_equal(style_text(c("if(TRUE) x else y")), "if (TRUE) x else y")
29+
})
30+
31+
test_that("space before comma is removed", {
32+
expect_equal(style_text("c( 1, 16 , 333 , 33 , 1)"),
33+
"c(1, 16, 333, 33, 1)")
34+
})

tests/testthat/test-styler.R

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)