Lines Matching +full:test +full:- +full:cl
2 // Use of this source code is governed by a BSD-style license that can be
22 /// Operation would have resulted in a non-printable ASCII character.
23 #[error("string contains non-printable ASCII character")]
33 fn valid_char(c: char) -> bool { in valid_char()
37 fn valid_str(s: &str) -> Result<()> { in valid_str()
45 fn valid_element(s: &str) -> Result<()> { in valid_element()
67 pub fn new(capacity: usize) -> Cmdline { in new()
75 fn has_capacity(&self, more: usize) -> Result<()> { in has_capacity()
97 pub fn insert<T: AsRef<str>>(&mut self, key: T, val: T) -> Result<()> { in insert()
115 pub fn insert_str<T: AsRef<str>>(&mut self, slug: T) -> Result<()> { in insert_str()
129 pub fn as_str(&self) -> &str { in as_str()
135 fn from(c: Cmdline) -> Vec<u8> { in from()
140 #[cfg(test)]
146 #[test]
148 let mut cl = Cmdline::new(100); in insert_hello_world() localVariable
149 assert_eq!(cl.as_str(), ""); in insert_hello_world()
150 assert!(cl.insert("hello", "world").is_ok()); in insert_hello_world()
151 assert_eq!(cl.as_str(), "hello=world"); in insert_hello_world()
153 let s = CString::new(cl).expect("failed to create CString from Cmdline"); in insert_hello_world()
157 #[test]
159 let mut cl = Cmdline::new(100); in insert_multi() localVariable
160 assert!(cl.insert("hello", "world").is_ok()); in insert_multi()
161 assert!(cl.insert("foo", "bar").is_ok()); in insert_multi()
162 assert_eq!(cl.as_str(), "hello=world foo=bar"); in insert_multi()
165 #[test]
167 let mut cl = Cmdline::new(100); in insert_space() localVariable
168 assert_eq!(cl.insert("a ", "b"), Err(Error::HasSpace)); in insert_space()
169 assert_eq!(cl.insert("a", "b "), Err(Error::HasSpace)); in insert_space()
170 assert_eq!(cl.insert("a ", "b "), Err(Error::HasSpace)); in insert_space()
171 assert_eq!(cl.insert(" a", "b"), Err(Error::HasSpace)); in insert_space()
172 assert_eq!(cl.as_str(), ""); in insert_space()
175 #[test]
177 let mut cl = Cmdline::new(100); in insert_equals() localVariable
178 assert_eq!(cl.insert("a=", "b"), Err(Error::HasEquals)); in insert_equals()
179 assert_eq!(cl.insert("a", "b="), Err(Error::HasEquals)); in insert_equals()
180 assert_eq!(cl.insert("a=", "b "), Err(Error::HasEquals)); in insert_equals()
181 assert_eq!(cl.insert("=a", "b"), Err(Error::HasEquals)); in insert_equals()
182 assert_eq!(cl.insert("a", "=b"), Err(Error::HasEquals)); in insert_equals()
183 assert_eq!(cl.as_str(), ""); in insert_equals()
186 #[test]
188 let mut cl = Cmdline::new(100); in insert_emoji() localVariable
189 assert_eq!(cl.insert("heart", ""), Err(Error::InvalidAscii)); in insert_emoji()
190 assert_eq!(cl.insert("", "love"), Err(Error::InvalidAscii)); in insert_emoji()
191 assert_eq!(cl.as_str(), ""); in insert_emoji()
194 #[test]
196 let mut cl = Cmdline::new(13); in insert_string() localVariable
197 assert_eq!(cl.as_str(), ""); in insert_string()
198 assert!(cl.insert_str("noapic").is_ok()); in insert_string()
199 assert_eq!(cl.as_str(), "noapic"); in insert_string()
200 assert!(cl.insert_str("nopci").is_ok()); in insert_string()
201 assert_eq!(cl.as_str(), "noapic nopci"); in insert_string()
204 #[test]
206 let mut cl = Cmdline::new(4); in insert_too_large() localVariable
207 assert_eq!(cl.insert("hello", "world"), Err(Error::TooLarge)); in insert_too_large()
208 assert_eq!(cl.insert("a", "world"), Err(Error::TooLarge)); in insert_too_large()
209 assert_eq!(cl.insert("hello", "b"), Err(Error::TooLarge)); in insert_too_large()
210 assert!(cl.insert("a", "b").is_ok()); in insert_too_large()
211 assert_eq!(cl.insert("a", "b"), Err(Error::TooLarge)); in insert_too_large()
212 assert_eq!(cl.insert_str("a"), Err(Error::TooLarge)); in insert_too_large()
213 assert_eq!(cl.as_str(), "a=b"); in insert_too_large()
215 let mut cl = Cmdline::new(10); in insert_too_large() localVariable
216 assert!(cl.insert("ab", "ba").is_ok()); // adds 5 length in insert_too_large()
217 assert_eq!(cl.insert("c", "da"), Err(Error::TooLarge)); // adds 5 (including space) length in insert_too_large()
218 assert!(cl.insert("c", "d").is_ok()); // adds 4 (including space) length in insert_too_large()