Skip to content

Commit

Permalink
Add tests for new space after function name option
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed May 29, 2024
1 parent 3ec7936 commit 0e8abbe
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/editorconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,41 @@ mod tests {
assert_eq!(config.call_parentheses, CallParenType::None);
}

#[test]
fn test_space_after_functions_always() {
let mut properties = Properties::new();
properties.insert_raw_for_key("space_after_functions", "Always");
let config = Config::from(&properties);
assert_eq!(config.space_after_functions, SpaceAfterFunctions::Always);
}

#[test]
fn test_space_after_functions_definitions() {
let mut properties = Properties::new();
properties.insert_raw_for_key("space_after_functions", "Definitions");
let config = Config::from(&properties);
assert_eq!(
config.space_after_functions,
SpaceAfterFunctions::Definitions
);
}

#[test]
fn test_space_after_functions_calls() {
let mut properties = Properties::new();
properties.insert_raw_for_key("space_after_functions", "Calls");
let config = Config::from(&properties);
assert_eq!(config.space_after_functions, SpaceAfterFunctions::Calls);
}

#[test]
fn test_space_after_functions_never() {
let mut properties = Properties::new();
properties.insert_raw_for_key("space_after_functions", "Never");
let config = Config::from(&properties);
assert_eq!(config.space_after_functions, SpaceAfterFunctions::Never);
}

#[test]
fn test_collapse_simple_statement_never() {
let mut properties = Properties::new();
Expand Down
134 changes: 134 additions & 0 deletions tests/test_spaces_after_functions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
use stylua_lib::{format_code, Config, OutputVerification, SpaceAfterFunctions};

fn format(input: &str, space_after_functions: SpaceAfterFunctions) -> String {
format_code(
input,
Config {
space_after_functions,
..Config::default()
},
None,
OutputVerification::None,
)
.unwrap()
}

const STARTINGCODE: &str = r###"
local foo = function() end
local function bar () end
function baz() end
a = {}
function a:b () end
function a.c () end
function qiz () return function () end end
foo()
bar ()
baz()
a:b ()
a.c ()
qiz()()
"###;

#[test]
fn test_never_space_after_functions() {
insta::assert_snapshot!(
format(STARTINGCODE,
SpaceAfterFunctions::Never
),
@r###"
local foo = function() end
local function bar() end
function baz() end
a = {}
function a:b() end
function a.c() end
function qiz()
return function() end
end
foo()
bar()
baz()
a:b()
a.c()
qiz()()
"###
);
}

#[test]
fn test_space_after_function_definitions() {
insta::assert_snapshot!(
format(STARTINGCODE,
SpaceAfterFunctions::Definitions
),
@r###"
local foo = function () end
local function bar () end
function baz () end
a = {}
function a:b () end
function a.c () end
function qiz ()
return function () end
end
foo()
bar()
baz()
a:b()
a.c()
qiz()()
"###
);
}

#[test]
fn test_space_after_function_calls() {
insta::assert_snapshot!(
format(STARTINGCODE,
SpaceAfterFunctions::Calls
),
@r###"
local foo = function() end
local function bar() end
function baz() end
a = {}
function a:b() end
function a.c() end
function qiz()
return function() end
end
foo ()
bar ()
baz ()
a:b ()
a.c ()
qiz () ()
"###
);
}

#[test]
fn test_always_space_after_functions() {
insta::assert_snapshot!(
format(STARTINGCODE,
SpaceAfterFunctions::Always
),
@r###"
local foo = function () end
local function bar () end
function baz () end
a = {}
function a:b () end
function a.c () end
function qiz ()
return function () end
end
foo ()
bar ()
baz ()
a:b ()
a.c ()
qiz () ()
"###
);
}

0 comments on commit 0e8abbe

Please sign in to comment.