1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! What:
//! Token insertion positions for fixed transforms.
//! Why:
//! An off-by-one would put `-o` before `commit` or after a pathspec.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! // expect(insertTokens(['a', 'b'], 1, ['x'])).toEqual(['a', 'x', 'b']);
//! ```
/// The builder under test and the shared argument builder.
use super::insert_tokens;
use crate::command_test_support::os_arguments;
use std::ffi::OsString;
/// Tokens land before the indexed argument,
/// or at the end when the index is the length.
#[test]
fn inserts_before_the_indexed_argument() {
let arguments: Vec<OsString> = os_arguments(&["a", "b"]);
for (at, expected) in [
(0, vec!["x", "y", "a", "b"]),
(1, vec!["a", "x", "y", "b"]),
(2, vec!["a", "b", "x", "y"]),
(9, vec!["a", "b", "x", "y"]),
] {
assert_eq!(
insert_tokens(arguments.as_slice(), at, &["x", "y"]),
os_arguments(expected.as_slice()),
"{at}"
);
}
assert_eq!(insert_tokens(&[], 0, &["x"]), os_arguments(&["x"]));
assert_eq!(
insert_tokens(arguments.as_slice(), 1, &[]),
os_arguments(&["a", "b"])
);
}