Skip to content

Commit c850ac7

Browse files
tests: add more tests for long chain elements
1 parent 065dbaf commit c850ac7

File tree

3 files changed

+187
-2
lines changed

3 files changed

+187
-2
lines changed

Configurations.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ fn example() {
390390
```
391391

392392
## `chains_block_parent_indent_children`
393-
Determines whether to indent the child chain items of a chain that beings with a block-like parent element.
393+
Determines whether to indent the child chain items of a chain that beings with a block-like parent element when `indent_style` is `Block`.
394394

395395
- **Default value**: `false`
396396
- **Possible values**: `true`, `false`
@@ -424,8 +424,10 @@ fn example() {
424424
}
425425
```
426426

427+
See also: [`indent_style`](#indent_style).
428+
427429
## `chains_block_parent_indent_parent_item`
428-
Determines whether block-like chain parents are indented
430+
Determines whether block-like chain parents are indented when `indent_style` is `Block`.
429431

430432
- **Default value**: `"Never"`
431433
- **Possible values**: `"Always"`, `"Never"`, `"OnlySimpleCalls"`, `"OnlyTupleLitsAndSimpleCalls"`
@@ -589,6 +591,8 @@ fn example() {
589591
}
590592
```
591593

594+
See also: [`indent_style`](#indent_style).
595+
592596
## `comment_width`
593597

594598
Maximum length of comments. No effect unless`wrap_comments = true`.

tests/source/chains_long_items_block.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,91 @@ fn raw_str_lit() {
7676
}
7777
"#.trim().foo().bar.baz.qux().unwrap());
7878
}
79+
80+
// https://github.com/rust-lang/rustup.rs/pull/2097
81+
fn deeply_nested() {
82+
let mut app = App::new("rustup")
83+
.version(common::version())
84+
.about("The Rust toolchain installer")
85+
.after_help(RUSTUP_HELP)
86+
.setting(AppSettings::VersionlessSubcommands)
87+
.setting(AppSettings::DeriveDisplayOrder)
88+
.setting(AppSettings::SubcommandRequiredElseHelp)
89+
.subcommand(
90+
SubCommand::with_name("run")
91+
.about("Run a command with an environment configured for a given toolchain")
92+
.after_help(RUN_HELP)
93+
.setting(AppSettings::TrailingVarArg)
94+
.arg(
95+
Arg::with_name("install")
96+
.help("Install the requested toolchain if needed")
97+
.long("install"),
98+
)
99+
.arg(
100+
Arg::with_name("toolchain")
101+
.help(TOOLCHAIN_ARG_HELP)
102+
.required(true),
103+
)
104+
.arg(
105+
Arg::with_name("command")
106+
.required(true)
107+
.multiple(true)
108+
.use_delimiter(false),
109+
),
110+
)
111+
.subcommand(
112+
SubCommand::with_name("which")
113+
.about("Display which binary will be run for a given command")
114+
.arg(Arg::with_name("command").required(true))
115+
.arg(
116+
Arg::with_name("toolchain")
117+
.help(TOOLCHAIN_ARG_HELP)
118+
.long("toolchain")
119+
.takes_value(true),
120+
),
121+
)
122+
.subcommand(
123+
SubCommand::with_name("doc")
124+
.alias("docs")
125+
.about("Open the documentation for the current toolchain")
126+
.after_help(DOC_HELP)
127+
.arg(
128+
Arg::with_name("path")
129+
.long("path")
130+
.help("Only print the path to the documentation"),
131+
)
132+
.args(
133+
&DOCS_DATA
134+
.iter()
135+
.map(|(name, help_msg, _)| Arg::with_name(name).long(name).help(help_msg))
136+
.collect::<Vec<_>>(),
137+
)
138+
.arg(Arg::with_name("toolchain")
139+
.help(TOOLCHAIN_ARG_HELP)
140+
.long("toolchain")
141+
.takes_value(true),
142+
).group(ArgGroup::with_name("page").args(
143+
&DOCS_DATA
144+
.iter()
145+
.map(|(name, _, _)| *name)
146+
.collect::<Vec<_>>(),
147+
),
148+
)
149+
.arg(Arg::with_name("topic").help("Topic such as 'core', 'fn', 'usize', 'eprintln!', 'core::arch', 'alloc::format!', 'std::fs', 'std::fs::read_dir', 'std::io::Bytes', 'std::iter::Sum', 'std::io::error::Result' etc..."),
150+
),
151+
);
152+
}
153+
154+
fn comments() {
155+
foo // foo
156+
// comment after parent
157+
.x
158+
.y
159+
// comment 1
160+
.bar("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk") // comment after bar()
161+
// comment 2
162+
.foobar
163+
// comment after
164+
// comment 3
165+
.baz(x, y, z);
166+
}

tests/target/chains_long_items_block.rs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,96 @@ fn raw_str_lit() {
182182
.unwrap(),
183183
);
184184
}
185+
186+
// https://github.com/rust-lang/rustup.rs/pull/2097
187+
fn deeply_nested() {
188+
let mut app = App::new("rustup")
189+
.version(common::version())
190+
.about("The Rust toolchain installer")
191+
.after_help(RUSTUP_HELP)
192+
.setting(AppSettings::VersionlessSubcommands)
193+
.setting(AppSettings::DeriveDisplayOrder)
194+
.setting(AppSettings::SubcommandRequiredElseHelp)
195+
.subcommand(
196+
SubCommand::with_name("run")
197+
.about("Run a command with an environment configured for a given toolchain")
198+
.after_help(RUN_HELP)
199+
.setting(AppSettings::TrailingVarArg)
200+
.arg(
201+
Arg::with_name("install")
202+
.help("Install the requested toolchain if needed")
203+
.long("install"),
204+
)
205+
.arg(
206+
Arg::with_name("toolchain")
207+
.help(TOOLCHAIN_ARG_HELP)
208+
.required(true),
209+
)
210+
.arg(
211+
Arg::with_name("command")
212+
.required(true)
213+
.multiple(true)
214+
.use_delimiter(false),
215+
),
216+
)
217+
.subcommand(
218+
SubCommand::with_name("which")
219+
.about("Display which binary will be run for a given command")
220+
.arg(Arg::with_name("command").required(true))
221+
.arg(
222+
Arg::with_name("toolchain")
223+
.help(TOOLCHAIN_ARG_HELP)
224+
.long("toolchain")
225+
.takes_value(true),
226+
),
227+
)
228+
.subcommand(
229+
SubCommand::with_name("doc")
230+
.alias("docs")
231+
.about("Open the documentation for the current toolchain")
232+
.after_help(DOC_HELP)
233+
.arg(
234+
Arg::with_name("path")
235+
.long("path")
236+
.help("Only print the path to the documentation"),
237+
)
238+
.args(
239+
&DOCS_DATA
240+
.iter()
241+
.map(|(name, help_msg, _)| Arg::with_name(name).long(name).help(help_msg))
242+
.collect::<Vec<_>>(),
243+
)
244+
.arg(
245+
Arg::with_name("toolchain")
246+
.help(TOOLCHAIN_ARG_HELP)
247+
.long("toolchain")
248+
.takes_value(true),
249+
)
250+
.group(
251+
ArgGroup::with_name("page").args(
252+
&DOCS_DATA
253+
.iter()
254+
.map(|(name, _, _)| *name)
255+
.collect::<Vec<_>>(),
256+
),
257+
)
258+
.arg(
259+
Arg::with_name("topic")
260+
.help("Topic such as 'core', 'fn', 'usize', 'eprintln!', 'core::arch', 'alloc::format!', 'std::fs', 'std::fs::read_dir', 'std::io::Bytes', 'std::iter::Sum', 'std::io::error::Result' etc..."),
261+
),
262+
);
263+
}
264+
265+
fn comments() {
266+
foo // foo
267+
// comment after parent
268+
.x
269+
.y
270+
// comment 1
271+
.bar("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk") // comment after bar()
272+
// comment 2
273+
.foobar
274+
// comment after
275+
// comment 3
276+
.baz(x, y, z);
277+
}

0 commit comments

Comments
 (0)