1// Despite our design philosophy being to support completion generation, we aren't considering `-` 2// the start of a long because there is no valid value to return. 3#[test] 4fn to_long_stdio() { 5 let raw = clap_lex::RawArgs::new(["bin", "-"]); 6 let mut cursor = raw.cursor(); 7 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 8 let next = raw.next(&mut cursor).unwrap(); 9 10 assert!(!next.is_long()); 11 12 assert_eq!(next.to_long(), None); 13} 14 15#[test] 16fn to_long_no_escape() { 17 let raw = clap_lex::RawArgs::new(["bin", "--"]); 18 let mut cursor = raw.cursor(); 19 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 20 let next = raw.next(&mut cursor).unwrap(); 21 22 assert!(!next.is_long()); 23 24 assert_eq!(next.to_long(), None); 25} 26 27#[test] 28fn to_long_no_value() { 29 let raw = clap_lex::RawArgs::new(["bin", "--long"]); 30 let mut cursor = raw.cursor(); 31 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 32 let next = raw.next(&mut cursor).unwrap(); 33 34 assert!(next.is_long()); 35 36 let (key, value) = next.to_long().unwrap(); 37 assert_eq!(key, Ok("long")); 38 assert_eq!(value, None); 39} 40 41#[test] 42fn to_long_with_empty_value() { 43 let raw = clap_lex::RawArgs::new(["bin", "--long="]); 44 let mut cursor = raw.cursor(); 45 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 46 let next = raw.next(&mut cursor).unwrap(); 47 48 assert!(next.is_long()); 49 50 let (key, value) = next.to_long().unwrap(); 51 assert_eq!(key, Ok("long")); 52 assert_eq!(value, Some(clap_lex::RawOsStr::from_str(""))); 53} 54 55#[test] 56fn to_long_with_value() { 57 let raw = clap_lex::RawArgs::new(["bin", "--long=hello"]); 58 let mut cursor = raw.cursor(); 59 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 60 let next = raw.next(&mut cursor).unwrap(); 61 62 assert!(next.is_long()); 63 64 let (key, value) = next.to_long().unwrap(); 65 assert_eq!(key, Ok("long")); 66 assert_eq!(value, Some(clap_lex::RawOsStr::from_str("hello"))); 67} 68 69#[test] 70fn to_short_stdio() { 71 let raw = clap_lex::RawArgs::new(["bin", "-"]); 72 let mut cursor = raw.cursor(); 73 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 74 let next = raw.next(&mut cursor).unwrap(); 75 76 assert!(!next.is_short()); 77 78 assert!(next.to_short().is_none()); 79} 80 81#[test] 82fn to_short_escape() { 83 let raw = clap_lex::RawArgs::new(["bin", "--"]); 84 let mut cursor = raw.cursor(); 85 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 86 let next = raw.next(&mut cursor).unwrap(); 87 88 assert!(!next.is_short()); 89 90 assert!(next.to_short().is_none()); 91} 92 93#[test] 94fn to_short_long() { 95 let raw = clap_lex::RawArgs::new(["bin", "--long"]); 96 let mut cursor = raw.cursor(); 97 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 98 let next = raw.next(&mut cursor).unwrap(); 99 100 assert!(!next.is_short()); 101 102 assert!(next.to_short().is_none()); 103} 104 105#[test] 106fn to_short() { 107 let raw = clap_lex::RawArgs::new(["bin", "-short"]); 108 let mut cursor = raw.cursor(); 109 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 110 let next = raw.next(&mut cursor).unwrap(); 111 112 assert!(next.is_short()); 113 114 let shorts = next.to_short().unwrap(); 115 let actual: String = shorts.map(|s| s.unwrap()).collect(); 116 assert_eq!(actual, "short"); 117} 118 119#[test] 120fn is_negative_number() { 121 let raw = clap_lex::RawArgs::new(["bin", "-10.0"]); 122 let mut cursor = raw.cursor(); 123 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 124 let next = raw.next(&mut cursor).unwrap(); 125 126 assert!(next.is_number()); 127} 128 129#[test] 130fn is_positive_number() { 131 let raw = clap_lex::RawArgs::new(["bin", "10.0"]); 132 let mut cursor = raw.cursor(); 133 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 134 let next = raw.next(&mut cursor).unwrap(); 135 136 assert!(next.is_number()); 137} 138 139#[test] 140fn is_not_number() { 141 let raw = clap_lex::RawArgs::new(["bin", "--10.0"]); 142 let mut cursor = raw.cursor(); 143 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 144 let next = raw.next(&mut cursor).unwrap(); 145 146 assert!(!next.is_number()); 147} 148 149#[test] 150fn is_stdio() { 151 let raw = clap_lex::RawArgs::new(["bin", "-"]); 152 let mut cursor = raw.cursor(); 153 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 154 let next = raw.next(&mut cursor).unwrap(); 155 156 assert!(next.is_stdio()); 157} 158 159#[test] 160fn is_not_stdio() { 161 let raw = clap_lex::RawArgs::new(["bin", "--"]); 162 let mut cursor = raw.cursor(); 163 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 164 let next = raw.next(&mut cursor).unwrap(); 165 166 assert!(!next.is_stdio()); 167} 168 169#[test] 170fn is_escape() { 171 let raw = clap_lex::RawArgs::new(["bin", "--"]); 172 let mut cursor = raw.cursor(); 173 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 174 let next = raw.next(&mut cursor).unwrap(); 175 176 assert!(next.is_escape()); 177} 178 179#[test] 180fn is_not_escape() { 181 let raw = clap_lex::RawArgs::new(["bin", "-"]); 182 let mut cursor = raw.cursor(); 183 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); 184 let next = raw.next(&mut cursor).unwrap(); 185 186 assert!(!next.is_escape()); 187} 188