Skip to content

Commit ba6297d

Browse files
alexandruagandreeaflorescu
authored andcommitted
cmdline: implement Debug and PartialEq
Signed-off-by: Alexandru Agache <aagch@amazon.com>
1 parent a41ea97 commit ba6297d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

coverage_config_x86_64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 81.1,
2+
"coverage_score": 80.8,
33
"exclude_path": "",
44
"crate_features": "bzimage,elf",
55
"exclude_path": "benches/,loader_gen/"

src/cmdline/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn valid_element(s: &str) -> Result<()> {
9696
/// let cl_cstring = CString::new(cl).unwrap();
9797
/// assert_eq!(cl_cstring.to_str().unwrap(), "");
9898
/// ```
99+
#[derive(Debug)]
99100
pub struct Cmdline {
100101
line: String,
101102
capacity: usize,
@@ -337,6 +338,12 @@ impl From<Cmdline> for Vec<u8> {
337338
}
338339
}
339340

341+
impl PartialEq for Cmdline {
342+
fn eq(&self, other: &Self) -> bool {
343+
self.line == other.line
344+
}
345+
}
346+
340347
#[cfg(test)]
341348
mod tests {
342349
use super::*;
@@ -479,4 +486,18 @@ mod tests {
479486
assert!(cl.insert_multiple("foo", &["bar", "baz"]).is_ok());
480487
assert_eq!(cl.as_str(), "foo=bar,baz");
481488
}
489+
490+
#[test]
491+
fn test_partial_eq() {
492+
let mut c1 = Cmdline::new(20);
493+
let mut c2 = Cmdline::new(30);
494+
495+
c1.insert_str("hello world!").unwrap();
496+
c2.insert_str("hello").unwrap();
497+
assert_ne!(c1, c2);
498+
499+
// `insert_str` also adds a whitespace before the string being inserted.
500+
c2.insert_str("world!").unwrap();
501+
assert_eq!(c1, c2);
502+
}
482503
}

0 commit comments

Comments
 (0)