Skip to content

Commit 3359ced

Browse files
committed
Add tests for new space after function name option
1 parent 682b785 commit 3359ced

File tree

2 files changed

+169
-0
lines changed

2 files changed

+169
-0
lines changed

src/editorconfig.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,41 @@ mod tests {
333333
assert_eq!(config.call_parentheses, CallParenType::None);
334334
}
335335

336+
#[test]
337+
fn test_space_after_functions_always() {
338+
let mut properties = Properties::new();
339+
properties.insert_raw_for_key("space_after_functions", "Always");
340+
let config = Config::from(&properties);
341+
assert_eq!(config.space_after_functions, SpaceAfterFunctions::Always);
342+
}
343+
344+
#[test]
345+
fn test_space_after_functions_definitions() {
346+
let mut properties = Properties::new();
347+
properties.insert_raw_for_key("space_after_functions", "Definitions");
348+
let config = Config::from(&properties);
349+
assert_eq!(
350+
config.space_after_functions,
351+
SpaceAfterFunctions::Definitions
352+
);
353+
}
354+
355+
#[test]
356+
fn test_space_after_functions_calls() {
357+
let mut properties = Properties::new();
358+
properties.insert_raw_for_key("space_after_functions", "Calls");
359+
let config = Config::from(&properties);
360+
assert_eq!(config.space_after_functions, SpaceAfterFunctions::Calls);
361+
}
362+
363+
#[test]
364+
fn test_space_after_functions_never() {
365+
let mut properties = Properties::new();
366+
properties.insert_raw_for_key("space_after_functions", "Never");
367+
let config = Config::from(&properties);
368+
assert_eq!(config.space_after_functions, SpaceAfterFunctions::Never);
369+
}
370+
336371
#[test]
337372
fn test_collapse_simple_statement_never() {
338373
let mut properties = Properties::new();
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
use stylua_lib::{format_code, Config, OutputVerification, SpaceAfterFunctions};
2+
3+
fn format(input: &str, space_after_functions: SpaceAfterFunctions) -> String {
4+
format_code(
5+
input,
6+
Config {
7+
space_after_functions,
8+
..Config::default()
9+
},
10+
None,
11+
OutputVerification::None,
12+
)
13+
.unwrap()
14+
}
15+
16+
const STARTINGCODE: &str = r###"
17+
local foo = function() end
18+
local function bar () end
19+
function baz() end
20+
a = {}
21+
function a:b () end
22+
function a.c () end
23+
function qiz () return function () end end
24+
foo()
25+
bar ()
26+
baz()
27+
a:b ()
28+
a.c ()
29+
qiz()()
30+
"###;
31+
32+
#[test]
33+
fn test_never_space_after_functions() {
34+
insta::assert_snapshot!(
35+
format(STARTINGCODE,
36+
SpaceAfterFunctions::Never
37+
),
38+
@r###"
39+
local foo = function() end
40+
local function bar() end
41+
function baz() end
42+
a = {}
43+
function a:b() end
44+
function a.c() end
45+
function qiz()
46+
return function() end
47+
end
48+
foo()
49+
bar()
50+
baz()
51+
a:b()
52+
a.c()
53+
qiz()()
54+
"###
55+
);
56+
}
57+
58+
#[test]
59+
fn test_space_after_function_definitions() {
60+
insta::assert_snapshot!(
61+
format(STARTINGCODE,
62+
SpaceAfterFunctions::Definitions
63+
),
64+
@r###"
65+
local foo = function () end
66+
local function bar () end
67+
function baz () end
68+
a = {}
69+
function a:b () end
70+
function a.c () end
71+
function qiz ()
72+
return function () end
73+
end
74+
foo()
75+
bar()
76+
baz()
77+
a:b()
78+
a.c()
79+
qiz()()
80+
"###
81+
);
82+
}
83+
84+
#[test]
85+
fn test_space_after_function_calls() {
86+
insta::assert_snapshot!(
87+
format(STARTINGCODE,
88+
SpaceAfterFunctions::Calls
89+
),
90+
@r###"
91+
local foo = function() end
92+
local function bar() end
93+
function baz() end
94+
a = {}
95+
function a:b() end
96+
function a.c() end
97+
function qiz()
98+
return function() end
99+
end
100+
foo ()
101+
bar ()
102+
baz ()
103+
a:b ()
104+
a.c ()
105+
qiz () ()
106+
"###
107+
);
108+
}
109+
110+
#[test]
111+
fn test_always_space_after_functions() {
112+
insta::assert_snapshot!(
113+
format(STARTINGCODE,
114+
SpaceAfterFunctions::Always
115+
),
116+
@r###"
117+
local foo = function () end
118+
local function bar () end
119+
function baz () end
120+
a = {}
121+
function a:b () end
122+
function a.c () end
123+
function qiz ()
124+
return function () end
125+
end
126+
foo ()
127+
bar ()
128+
baz ()
129+
a:b ()
130+
a.c ()
131+
qiz () ()
132+
"###
133+
);
134+
}

0 commit comments

Comments
 (0)