Skip to content

Commit af6b58f

Browse files
committed
Merge pull request #181 from Vinatorul/tests_1
New tests and old tests improvements
2 parents 34257da + 9994569 commit af6b58f

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

src/lib.rs

+133
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ mod tests {
10661066
.arg(Arg::from_usage("--color [color] 'some other flag'"))
10671067
.get_matches_from(vec!["", "--flag", "some" ,"--color", "other"]);
10681068
assert!(m.is_present("color"));
1069+
assert_eq!(m.value_of("color").unwrap(), "other");
10691070
assert!(!m.is_present("flag"));
10701071

10711072
let m = App::new("posix")
@@ -1074,6 +1075,7 @@ mod tests {
10741075
.get_matches_from(vec!["", "--color", "some" ,"--flag", "other"]);
10751076
assert!(!m.is_present("color"));
10761077
assert!(m.is_present("flag"));
1078+
assert_eq!(m.value_of("flag").unwrap(), "other");
10771079
}
10781080

10791081
#[test]
@@ -1083,6 +1085,7 @@ mod tests {
10831085
.arg(Arg::from_usage("--color [color] 'some other flag'"))
10841086
.get_matches_from(vec!["", "--flag=some" ,"--color=other"]);
10851087
assert!(m.is_present("color"));
1088+
assert_eq!(m.value_of("color").unwrap(), "other");
10861089
assert!(!m.is_present("flag"));
10871090

10881091
let m = App::new("posix")
@@ -1091,6 +1094,7 @@ mod tests {
10911094
.get_matches_from(vec!["", "--color=some" ,"--flag=other"]);
10921095
assert!(!m.is_present("color"));
10931096
assert!(m.is_present("flag"));
1097+
assert_eq!(m.value_of("flag").unwrap(), "other");
10941098
}
10951099

10961100
#[test]
@@ -1100,6 +1104,7 @@ mod tests {
11001104
.arg(Arg::from_usage("-c [color] 'some other flag'"))
11011105
.get_matches_from(vec!["", "-f", "some", "-c", "other"]);
11021106
assert!(m.is_present("color"));
1107+
assert_eq!(m.value_of("color").unwrap(), "other");
11031108
assert!(!m.is_present("flag"));
11041109

11051110
let m = App::new("posix")
@@ -1108,5 +1113,133 @@ mod tests {
11081113
.get_matches_from(vec!["", "-c", "some", "-f", "other"]);
11091114
assert!(!m.is_present("color"));
11101115
assert!(m.is_present("flag"));
1116+
assert_eq!(m.value_of("flag").unwrap(), "other");
11111117
}
1118+
1119+
#[test]
1120+
fn opts_using_short() {
1121+
let m = App::new("opts")
1122+
.args(vec![
1123+
Arg::from_usage("-f [flag] 'some flag'"),
1124+
Arg::from_usage("-c [color] 'some other flag'")
1125+
])
1126+
.get_matches_from(vec!["", "-f", "some", "-c", "other"]);
1127+
assert!(m.is_present("flag"));
1128+
assert_eq!(m.value_of("flag").unwrap(), "some");
1129+
assert!(m.is_present("color"));
1130+
assert_eq!(m.value_of("color").unwrap(), "other");
1131+
}
1132+
1133+
#[test]
1134+
fn opts_using_long_space() {
1135+
let m = App::new("opts")
1136+
.args(vec![
1137+
Arg::from_usage("--flag [flag] 'some flag'"),
1138+
Arg::from_usage("--color [color] 'some other flag'")
1139+
])
1140+
.get_matches_from(vec!["", "--flag", "some", "--color", "other"]);
1141+
assert!(m.is_present("flag"));
1142+
assert_eq!(m.value_of("flag").unwrap(), "some");
1143+
assert!(m.is_present("color"));
1144+
assert_eq!(m.value_of("color").unwrap(), "other");
1145+
}
1146+
1147+
#[test]
1148+
fn opts_using_long_equals() {
1149+
let m = App::new("opts")
1150+
.args(vec![
1151+
Arg::from_usage("--flag [flag] 'some flag'"),
1152+
Arg::from_usage("--color [color] 'some other flag'")
1153+
])
1154+
.get_matches_from(vec!["", "--flag=some", "--color=other"]);
1155+
assert!(m.is_present("flag"));
1156+
assert_eq!(m.value_of("flag").unwrap(), "some");
1157+
assert!(m.is_present("color"));
1158+
assert_eq!(m.value_of("color").unwrap(), "other");
1159+
}
1160+
1161+
#[test]
1162+
fn opts_using_mixed() {
1163+
let m = App::new("opts")
1164+
.args(vec![
1165+
Arg::from_usage("-f, --flag [flag] 'some flag'"),
1166+
Arg::from_usage("-c, --color [color] 'some other flag'")
1167+
])
1168+
.get_matches_from(vec!["", "-f", "some", "--color", "other"]);
1169+
assert!(m.is_present("flag"));
1170+
assert_eq!(m.value_of("flag").unwrap(), "some");
1171+
assert!(m.is_present("color"));
1172+
assert_eq!(m.value_of("color").unwrap(), "other");
1173+
1174+
let m = App::new("opts")
1175+
.args(vec![
1176+
Arg::from_usage("-f, --flag [flag] 'some flag'"),
1177+
Arg::from_usage("-c, --color [color] 'some other flag'")
1178+
])
1179+
.get_matches_from(vec!["", "--flag=some", "-c", "other"]);
1180+
assert!(m.is_present("flag"));
1181+
assert_eq!(m.value_of("flag").unwrap(), "some");
1182+
assert!(m.is_present("color"));
1183+
assert_eq!(m.value_of("color").unwrap(), "other");
1184+
}
1185+
1186+
#[test]
1187+
fn flag_using_short() {
1188+
let m = App::new("flag")
1189+
.args(vec![
1190+
Arg::from_usage("-f, --flag 'some flag'"),
1191+
Arg::from_usage("-c, --color 'some other flag'")
1192+
])
1193+
.get_matches_from(vec!["", "-f", "-c"]);
1194+
assert!(m.is_present("flag"));
1195+
assert!(m.is_present("color"));
1196+
}
1197+
1198+
#[test]
1199+
fn flag_using_long() {
1200+
let m = App::new("flag")
1201+
.args(vec![
1202+
Arg::from_usage("--flag 'some flag'"),
1203+
Arg::from_usage("--color 'some other flag'")
1204+
])
1205+
.get_matches_from(vec!["", "--flag", "--color"]);
1206+
assert!(m.is_present("flag"));
1207+
assert!(m.is_present("color"));
1208+
}
1209+
1210+
#[test]
1211+
fn flag_using_mixed() {
1212+
let m = App::new("flag")
1213+
.args(vec![
1214+
Arg::from_usage("-f, --flag 'some flag'"),
1215+
Arg::from_usage("-c, --color 'some other flag'")
1216+
])
1217+
.get_matches_from(vec!["", "-f", "--color"]);
1218+
assert!(m.is_present("flag"));
1219+
assert!(m.is_present("color"));
1220+
1221+
let m = App::new("flag")
1222+
.args(vec![
1223+
Arg::from_usage("-f, --flag 'some flag'"),
1224+
Arg::from_usage("-c, --color 'some other flag'")
1225+
])
1226+
.get_matches_from(vec!["", "--flag", "-c"]);
1227+
assert!(m.is_present("flag"));
1228+
assert!(m.is_present("color"));
1229+
}
1230+
1231+
#[test]
1232+
fn multiple_flags_in_single() {
1233+
let m = App::new("multe_flags")
1234+
.args(vec![
1235+
Arg::from_usage("-f, --flag 'some flag'"),
1236+
Arg::from_usage("-c, --color 'some other flag'"),
1237+
Arg::from_usage("-d, --debug 'another other flag'")
1238+
])
1239+
.get_matches_from(vec!["", "-fcd"]);
1240+
assert!(m.is_present("flag"));
1241+
assert!(m.is_present("color"));
1242+
assert!(m.is_present("debug"));
1243+
}
1244+
11121245
}

0 commit comments

Comments
 (0)