119625d8cSopenharmony_ci// Despite our design philosophy being to support completion generation, we aren't considering `-`
219625d8cSopenharmony_ci// the start of a long because there is no valid value to return.
319625d8cSopenharmony_ci#[test]
419625d8cSopenharmony_cifn to_long_stdio() {
519625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "-"]);
619625d8cSopenharmony_ci    let mut cursor = raw.cursor();
719625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
819625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
919625d8cSopenharmony_ci
1019625d8cSopenharmony_ci    assert!(!next.is_long());
1119625d8cSopenharmony_ci
1219625d8cSopenharmony_ci    assert_eq!(next.to_long(), None);
1319625d8cSopenharmony_ci}
1419625d8cSopenharmony_ci
1519625d8cSopenharmony_ci#[test]
1619625d8cSopenharmony_cifn to_long_no_escape() {
1719625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "--"]);
1819625d8cSopenharmony_ci    let mut cursor = raw.cursor();
1919625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
2019625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
2119625d8cSopenharmony_ci
2219625d8cSopenharmony_ci    assert!(!next.is_long());
2319625d8cSopenharmony_ci
2419625d8cSopenharmony_ci    assert_eq!(next.to_long(), None);
2519625d8cSopenharmony_ci}
2619625d8cSopenharmony_ci
2719625d8cSopenharmony_ci#[test]
2819625d8cSopenharmony_cifn to_long_no_value() {
2919625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "--long"]);
3019625d8cSopenharmony_ci    let mut cursor = raw.cursor();
3119625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
3219625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
3319625d8cSopenharmony_ci
3419625d8cSopenharmony_ci    assert!(next.is_long());
3519625d8cSopenharmony_ci
3619625d8cSopenharmony_ci    let (key, value) = next.to_long().unwrap();
3719625d8cSopenharmony_ci    assert_eq!(key, Ok("long"));
3819625d8cSopenharmony_ci    assert_eq!(value, None);
3919625d8cSopenharmony_ci}
4019625d8cSopenharmony_ci
4119625d8cSopenharmony_ci#[test]
4219625d8cSopenharmony_cifn to_long_with_empty_value() {
4319625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "--long="]);
4419625d8cSopenharmony_ci    let mut cursor = raw.cursor();
4519625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
4619625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
4719625d8cSopenharmony_ci
4819625d8cSopenharmony_ci    assert!(next.is_long());
4919625d8cSopenharmony_ci
5019625d8cSopenharmony_ci    let (key, value) = next.to_long().unwrap();
5119625d8cSopenharmony_ci    assert_eq!(key, Ok("long"));
5219625d8cSopenharmony_ci    assert_eq!(value, Some(clap_lex::RawOsStr::from_str("")));
5319625d8cSopenharmony_ci}
5419625d8cSopenharmony_ci
5519625d8cSopenharmony_ci#[test]
5619625d8cSopenharmony_cifn to_long_with_value() {
5719625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "--long=hello"]);
5819625d8cSopenharmony_ci    let mut cursor = raw.cursor();
5919625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
6019625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
6119625d8cSopenharmony_ci
6219625d8cSopenharmony_ci    assert!(next.is_long());
6319625d8cSopenharmony_ci
6419625d8cSopenharmony_ci    let (key, value) = next.to_long().unwrap();
6519625d8cSopenharmony_ci    assert_eq!(key, Ok("long"));
6619625d8cSopenharmony_ci    assert_eq!(value, Some(clap_lex::RawOsStr::from_str("hello")));
6719625d8cSopenharmony_ci}
6819625d8cSopenharmony_ci
6919625d8cSopenharmony_ci#[test]
7019625d8cSopenharmony_cifn to_short_stdio() {
7119625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "-"]);
7219625d8cSopenharmony_ci    let mut cursor = raw.cursor();
7319625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
7419625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
7519625d8cSopenharmony_ci
7619625d8cSopenharmony_ci    assert!(!next.is_short());
7719625d8cSopenharmony_ci
7819625d8cSopenharmony_ci    assert!(next.to_short().is_none());
7919625d8cSopenharmony_ci}
8019625d8cSopenharmony_ci
8119625d8cSopenharmony_ci#[test]
8219625d8cSopenharmony_cifn to_short_escape() {
8319625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "--"]);
8419625d8cSopenharmony_ci    let mut cursor = raw.cursor();
8519625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
8619625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
8719625d8cSopenharmony_ci
8819625d8cSopenharmony_ci    assert!(!next.is_short());
8919625d8cSopenharmony_ci
9019625d8cSopenharmony_ci    assert!(next.to_short().is_none());
9119625d8cSopenharmony_ci}
9219625d8cSopenharmony_ci
9319625d8cSopenharmony_ci#[test]
9419625d8cSopenharmony_cifn to_short_long() {
9519625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "--long"]);
9619625d8cSopenharmony_ci    let mut cursor = raw.cursor();
9719625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
9819625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
9919625d8cSopenharmony_ci
10019625d8cSopenharmony_ci    assert!(!next.is_short());
10119625d8cSopenharmony_ci
10219625d8cSopenharmony_ci    assert!(next.to_short().is_none());
10319625d8cSopenharmony_ci}
10419625d8cSopenharmony_ci
10519625d8cSopenharmony_ci#[test]
10619625d8cSopenharmony_cifn to_short() {
10719625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "-short"]);
10819625d8cSopenharmony_ci    let mut cursor = raw.cursor();
10919625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
11019625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
11119625d8cSopenharmony_ci
11219625d8cSopenharmony_ci    assert!(next.is_short());
11319625d8cSopenharmony_ci
11419625d8cSopenharmony_ci    let shorts = next.to_short().unwrap();
11519625d8cSopenharmony_ci    let actual: String = shorts.map(|s| s.unwrap()).collect();
11619625d8cSopenharmony_ci    assert_eq!(actual, "short");
11719625d8cSopenharmony_ci}
11819625d8cSopenharmony_ci
11919625d8cSopenharmony_ci#[test]
12019625d8cSopenharmony_cifn is_negative_number() {
12119625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "-10.0"]);
12219625d8cSopenharmony_ci    let mut cursor = raw.cursor();
12319625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
12419625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
12519625d8cSopenharmony_ci
12619625d8cSopenharmony_ci    assert!(next.is_number());
12719625d8cSopenharmony_ci}
12819625d8cSopenharmony_ci
12919625d8cSopenharmony_ci#[test]
13019625d8cSopenharmony_cifn is_positive_number() {
13119625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "10.0"]);
13219625d8cSopenharmony_ci    let mut cursor = raw.cursor();
13319625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
13419625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
13519625d8cSopenharmony_ci
13619625d8cSopenharmony_ci    assert!(next.is_number());
13719625d8cSopenharmony_ci}
13819625d8cSopenharmony_ci
13919625d8cSopenharmony_ci#[test]
14019625d8cSopenharmony_cifn is_not_number() {
14119625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "--10.0"]);
14219625d8cSopenharmony_ci    let mut cursor = raw.cursor();
14319625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
14419625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
14519625d8cSopenharmony_ci
14619625d8cSopenharmony_ci    assert!(!next.is_number());
14719625d8cSopenharmony_ci}
14819625d8cSopenharmony_ci
14919625d8cSopenharmony_ci#[test]
15019625d8cSopenharmony_cifn is_stdio() {
15119625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "-"]);
15219625d8cSopenharmony_ci    let mut cursor = raw.cursor();
15319625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
15419625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
15519625d8cSopenharmony_ci
15619625d8cSopenharmony_ci    assert!(next.is_stdio());
15719625d8cSopenharmony_ci}
15819625d8cSopenharmony_ci
15919625d8cSopenharmony_ci#[test]
16019625d8cSopenharmony_cifn is_not_stdio() {
16119625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "--"]);
16219625d8cSopenharmony_ci    let mut cursor = raw.cursor();
16319625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
16419625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
16519625d8cSopenharmony_ci
16619625d8cSopenharmony_ci    assert!(!next.is_stdio());
16719625d8cSopenharmony_ci}
16819625d8cSopenharmony_ci
16919625d8cSopenharmony_ci#[test]
17019625d8cSopenharmony_cifn is_escape() {
17119625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "--"]);
17219625d8cSopenharmony_ci    let mut cursor = raw.cursor();
17319625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
17419625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
17519625d8cSopenharmony_ci
17619625d8cSopenharmony_ci    assert!(next.is_escape());
17719625d8cSopenharmony_ci}
17819625d8cSopenharmony_ci
17919625d8cSopenharmony_ci#[test]
18019625d8cSopenharmony_cifn is_not_escape() {
18119625d8cSopenharmony_ci    let raw = clap_lex::RawArgs::new(["bin", "-"]);
18219625d8cSopenharmony_ci    let mut cursor = raw.cursor();
18319625d8cSopenharmony_ci    assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
18419625d8cSopenharmony_ci    let next = raw.next(&mut cursor).unwrap();
18519625d8cSopenharmony_ci
18619625d8cSopenharmony_ci    assert!(!next.is_escape());
18719625d8cSopenharmony_ci}
188