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]
to_long_stdio()4 fn 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]
to_long_no_escape()16 fn 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]
to_long_no_value()28 fn 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]
to_long_with_empty_value()42 fn 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]
to_long_with_value()56 fn 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]
to_short_stdio()70 fn 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]
to_short_escape()82 fn 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]
to_short_long()94 fn 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]
to_short()106 fn 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]
is_negative_number()120 fn 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]
is_positive_number()130 fn 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]
is_not_number()140 fn 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]
is_stdio()150 fn 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]
is_not_stdio()160 fn 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]
is_escape()170 fn 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]
is_not_escape()180 fn 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