1 #[test]
iter()2 fn iter() {
3 let raw = clap_lex::RawArgs::new(["bin", "-short"]);
4 let mut cursor = raw.cursor();
5 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
6 let next = raw.next(&mut cursor).unwrap();
7 let shorts = next.to_short().unwrap();
8
9 let actual: String = shorts.map(|s| s.unwrap()).collect();
10 assert_eq!(actual, "short");
11 }
12
13 #[test]
next_flag()14 fn next_flag() {
15 let raw = clap_lex::RawArgs::new(["bin", "-short"]);
16 let mut cursor = raw.cursor();
17 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
18 let next = raw.next(&mut cursor).unwrap();
19 let mut shorts = next.to_short().unwrap();
20
21 let mut actual = String::new();
22 actual.push(shorts.next_flag().unwrap().unwrap());
23 actual.push(shorts.next_flag().unwrap().unwrap());
24 actual.push(shorts.next_flag().unwrap().unwrap());
25 actual.push(shorts.next_flag().unwrap().unwrap());
26 actual.push(shorts.next_flag().unwrap().unwrap());
27 assert_eq!(shorts.next_flag(), None);
28
29 assert_eq!(actual, "short");
30 }
31
32 #[test]
next_value_os()33 fn next_value_os() {
34 let raw = clap_lex::RawArgs::new(["bin", "-short"]);
35 let mut cursor = raw.cursor();
36 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
37 let next = raw.next(&mut cursor).unwrap();
38 let mut shorts = next.to_short().unwrap();
39
40 let actual = shorts.next_value_os().unwrap().to_str_lossy();
41
42 assert_eq!(actual, "short");
43 }
44
45 #[test]
next_flag_with_value()46 fn next_flag_with_value() {
47 let raw = clap_lex::RawArgs::new(["bin", "-short"]);
48 let mut cursor = raw.cursor();
49 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
50 let next = raw.next(&mut cursor).unwrap();
51 let mut shorts = next.to_short().unwrap();
52
53 assert_eq!(shorts.next_flag().unwrap().unwrap(), 's');
54 let actual = shorts.next_value_os().unwrap().to_str_lossy();
55
56 assert_eq!(actual, "hort");
57 }
58
59 #[test]
next_flag_with_no_value()60 fn next_flag_with_no_value() {
61 let raw = clap_lex::RawArgs::new(["bin", "-short"]);
62 let mut cursor = raw.cursor();
63 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
64 let next = raw.next(&mut cursor).unwrap();
65 let mut shorts = next.to_short().unwrap();
66
67 assert_eq!(shorts.next_flag().unwrap().unwrap(), 's');
68 assert_eq!(shorts.next_flag().unwrap().unwrap(), 'h');
69 assert_eq!(shorts.next_flag().unwrap().unwrap(), 'o');
70 assert_eq!(shorts.next_flag().unwrap().unwrap(), 'r');
71 assert_eq!(shorts.next_flag().unwrap().unwrap(), 't');
72
73 assert_eq!(shorts.next_value_os(), None);
74 }
75
76 #[test]
advance_by_nothing()77 fn advance_by_nothing() {
78 let raw = clap_lex::RawArgs::new(["bin", "-short"]);
79 let mut cursor = raw.cursor();
80 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
81 let next = raw.next(&mut cursor).unwrap();
82 let mut shorts = next.to_short().unwrap();
83
84 assert_eq!(shorts.advance_by(0), Ok(()));
85
86 let actual: String = shorts.map(|s| s.unwrap()).collect();
87 assert_eq!(actual, "short");
88 }
89
90 #[test]
advance_by_something()91 fn advance_by_something() {
92 let raw = clap_lex::RawArgs::new(["bin", "-short"]);
93 let mut cursor = raw.cursor();
94 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
95 let next = raw.next(&mut cursor).unwrap();
96 let mut shorts = next.to_short().unwrap();
97
98 assert_eq!(shorts.advance_by(2), Ok(()));
99
100 let actual: String = shorts.map(|s| s.unwrap()).collect();
101 assert_eq!(actual, "ort");
102 }
103
104 #[test]
advance_by_out_of_bounds()105 fn advance_by_out_of_bounds() {
106 let raw = clap_lex::RawArgs::new(["bin", "-short"]);
107 let mut cursor = raw.cursor();
108 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
109 let next = raw.next(&mut cursor).unwrap();
110 let mut shorts = next.to_short().unwrap();
111
112 assert_eq!(shorts.advance_by(2000), Err(5));
113
114 let actual: String = shorts.map(|s| s.unwrap()).collect();
115 assert_eq!(actual, "");
116 }
117
118 #[test]
is_not_empty()119 fn is_not_empty() {
120 let raw = clap_lex::RawArgs::new(["bin", "-hello"]);
121 let mut cursor = raw.cursor();
122 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
123 let next = raw.next(&mut cursor).unwrap();
124 let shorts = next.to_short().unwrap();
125
126 assert!(!shorts.is_empty());
127 }
128
129 #[test]
is_partial_not_empty()130 fn is_partial_not_empty() {
131 let raw = clap_lex::RawArgs::new(["bin", "-hello"]);
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 let mut shorts = next.to_short().unwrap();
136 shorts.advance_by(1).unwrap();
137
138 assert!(!shorts.is_empty());
139 }
140
141 #[test]
is_exhausted_empty()142 fn is_exhausted_empty() {
143 let raw = clap_lex::RawArgs::new(["bin", "-hello"]);
144 let mut cursor = raw.cursor();
145 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
146 let next = raw.next(&mut cursor).unwrap();
147 let mut shorts = next.to_short().unwrap();
148 shorts.advance_by(20000).unwrap_err();
149
150 assert!(shorts.is_empty());
151 }
152
153 #[test]
is_number()154 fn is_number() {
155 let raw = clap_lex::RawArgs::new(["bin", "-1.0"]);
156 let mut cursor = raw.cursor();
157 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
158 let next = raw.next(&mut cursor).unwrap();
159 let shorts = next.to_short().unwrap();
160
161 assert!(shorts.is_number());
162 }
163
164 #[test]
is_not_number()165 fn is_not_number() {
166 let raw = clap_lex::RawArgs::new(["bin", "-hello"]);
167 let mut cursor = raw.cursor();
168 assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
169 let next = raw.next(&mut cursor).unwrap();
170 let shorts = next.to_short().unwrap();
171
172 assert!(!shorts.is_number());
173 }
174