From e04e4118529461f3d97b0cf3d102925cbab69f74 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Fri, 19 Jul 2024 18:23:16 -0500 Subject: [PATCH] tests: validate style_edition derivation Adds a few tests that validate the various scenarios of precendence, overrides, and defaults to ensure the correct 'style_edition' value is selected even when other options like 'edition' and/or 'version' are included. --- .../indent_style/block_trailing_comma_call/one.rs | 2 +- .../indent_style/block_trailing_comma_call/two.rs | 2 +- tests/target/configs/version/mapped.rs | 9 +++++++++ tests/target/style_edition/default.rs | 10 ++++++++++ tests/target/style_edition/follows_edition.rs | 14 ++++++++++++++ .../style_edition/overrides_edition_when_set.rs | 14 ++++++++++++++ 6 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tests/target/configs/version/mapped.rs create mode 100644 tests/target/style_edition/default.rs create mode 100644 tests/target/style_edition/follows_edition.rs create mode 100644 tests/target/style_edition/overrides_edition_when_set.rs diff --git a/tests/target/configs/indent_style/block_trailing_comma_call/one.rs b/tests/target/configs/indent_style/block_trailing_comma_call/one.rs index 6b9489bef550..204dce6d655a 100644 --- a/tests/target/configs/indent_style/block_trailing_comma_call/one.rs +++ b/tests/target/configs/indent_style/block_trailing_comma_call/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // rustfmt-error_on_line_overflow: false // rustfmt-indent_style: Block diff --git a/tests/target/configs/indent_style/block_trailing_comma_call/two.rs b/tests/target/configs/indent_style/block_trailing_comma_call/two.rs index 4f4292e5f485..887e8328ccc7 100644 --- a/tests/target/configs/indent_style/block_trailing_comma_call/two.rs +++ b/tests/target/configs/indent_style/block_trailing_comma_call/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-error_on_line_overflow: false // rustfmt-indent_style: Block diff --git a/tests/target/configs/version/mapped.rs b/tests/target/configs/version/mapped.rs new file mode 100644 index 000000000000..296dc559a934 --- /dev/null +++ b/tests/target/configs/version/mapped.rs @@ -0,0 +1,9 @@ +// rustfmt-version: Two +fn main() { + let [ + aaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccc, + ddddddddddddddddddddddddd, + ] = panic!(); +} diff --git a/tests/target/style_edition/default.rs b/tests/target/style_edition/default.rs new file mode 100644 index 000000000000..17442df6c49a --- /dev/null +++ b/tests/target/style_edition/default.rs @@ -0,0 +1,10 @@ +fn build_sorted_static_get_entry_names( + mut entries: Vec<(u8, &'static str)>, +) -> (impl Fn( + AlphabeticalTraversal, + Box>, +) -> BoxFuture<'static, Result, Status>> + + Send + + Sync + + 'static) { +} diff --git a/tests/target/style_edition/follows_edition.rs b/tests/target/style_edition/follows_edition.rs new file mode 100644 index 000000000000..c36a993d842a --- /dev/null +++ b/tests/target/style_edition/follows_edition.rs @@ -0,0 +1,14 @@ +// rustfmt-edition: 2024 + +fn build_sorted_static_get_entry_names( + mut entries: Vec<(u8, &'static str)>, +) -> ( + impl Fn( + AlphabeticalTraversal, + Box>, + ) -> BoxFuture<'static, Result, Status>> + + Send + + Sync + + 'static +) { +} diff --git a/tests/target/style_edition/overrides_edition_when_set.rs b/tests/target/style_edition/overrides_edition_when_set.rs new file mode 100644 index 000000000000..6d0eaac8970f --- /dev/null +++ b/tests/target/style_edition/overrides_edition_when_set.rs @@ -0,0 +1,14 @@ +// rustfmt-edition: 2018 +// rustfmt-style_edition: 2024 +fn build_sorted_static_get_entry_names( + mut entries: Vec<(u8, &'static str)>, +) -> ( + impl Fn( + AlphabeticalTraversal, + Box>, + ) -> BoxFuture<'static, Result, Status>> + + Send + + Sync + + 'static +) { +}