use cpp_formatter::config::Style;
#[track_caller]
fn check(input: &str, expected: &str) {
let style = style();
let path = std::path::Path::new("snippet.cpp");
let actual = cpp_formatter::format_file(path, input, &style);
let actual = actual.trim_end_matches('\n');
let expected = expected.trim_end_matches('\n');
assert_eq!(
actual, expected,
"formatting drifted\ninput:\n{input}\nexpected:\n{expected}\nactual:\n{actual}"
);
let again = cpp_formatter::format_file(path, expected, &style);
assert_eq!(again, expected, "the expected text is not a fixed point");
}
fn style() -> Style {
let mut style = Style::preset("LLVM").expect("LLVM is a preset");
style.set_from_text("IndentWidth", "4");
style.set_from_text("ContinuationIndentWidth", "8");
style.set_from_text("ColumnLimit", "0");
style
}
#[test]
fn functions_02_noexcept() {
check(r#"void f() noexcept;"#, r#"void f() noexcept;"#);
}
#[test]
fn functions_03_default_arg() {
check(
r#"void f(int a = 1, int b = 2);"#,
r#"void f(int a = 1, int b = 2);"#,
);
}
#[test]
fn functions_04_overload_ops() {
check(
r#"bool operator==(const S& a, const S& b);"#,
r#"bool operator==(const S &a, const S &b);"#,
);
}
#[test]
fn functions_06_static() {
check(
r#"static inline int f() { return 1; }"#,
r#"static inline int f() { return 1; }"#,
);
}
#[test]
fn functions_07_lambda_block() {
check(
r#"void f() {
auto g = []() {
return 1;
};
}"#,
r#"void f() {
auto g = []() {
return 1;
};
}"#,
);
}
#[test]
fn functions_08_static_block() {
check(
r#"static inline int f() {
return 1;
}"#,
r#"static inline int f() {
return 1;
}"#,
);
}