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 templates_04_alias() {
check(
r#"using Alias = std::map<int, int>;"#,
r#"using Alias = std::map<int, int>;"#,
);
}
#[test]
fn templates_07_function_block() {
check(
r#"template <typename T>
T id(T v) {
return v;
}"#,
r#"template <typename T>
T id(T v) {
return v;
}"#,
);
}
#[test]
fn templates_08_struct_block() {
check(
r#"template <typename T, int N=3>
struct B {
T a[N];
};"#,
r#"template <typename T, int N = 3>
struct B {
T a[N];
};"#,
);
}
#[test]
fn templates_09_alias_block() {
check(
r#"using Alias = std::map<int,int>;"#,
r#"using Alias = std::map<int, int>;"#,
);
}
#[test]
fn templates_10_variadic_block() {
check(
r#"template <typename... Args>
void v(Args &&...args) {
(void)sizeof...(args);
}"#,
r#"template <typename... Args>
void v(Args &&...args) {
(void)sizeof...(args);
}"#,
);
}
#[test]
fn templates_11_concept_block() {
check(
r#"template <typename T>
concept C = requires(T t) {
t.size();
};"#,
r#"template <typename T>
concept C = requires(T t) {
t.size();
};"#,
);
}
#[test]
fn templates_12_specialization_block() {
check(
r#"template <>
struct B<int,1> {
int a;
};"#,
r#"template <>
struct B<int, 1> {
int a;
};"#,
);
}