Compare commits

...

2 Commits

Author SHA1 Message Date
Kiyomichi Kosaka 38e7df982f Merge pull request #1 from ok2/codex/fix-typo,-bug,-comments,-and-improve-tests
Fix typos and improve radix output
2025-06-08 17:01:17 +02:00
Kiyomichi Kosaka ff4215fbab Fix typos and improve Radix 2025-05-23 13:47:58 +02:00
2 changed files with 15 additions and 3 deletions
+2 -2
View File
@@ -228,7 +228,7 @@ impl<'a> LKEval<'a> {
};
}
}
Err(e) => out.e(format!("error: faild to parse command {}: {}", command, e.to_string())),
Err(e) => out.e(format!("error: failed to parse command {}: {}", command, e.to_string())),
};
}
@@ -330,7 +330,7 @@ impl<'a> LKEval<'a> {
} else {
match save_dump(&self.state.lock().borrow().db, &script) {
Ok(()) => out.o(format!("Passwords saved to file {}", script)),
Err(e) => out.e(format!("error: failed to dump passswords to {}: {}", script, e.to_string())),
Err(e) => out.e(format!("error: failed to dump passwords to {}: {}", script, e.to_string())),
};
}
}
+13 -1
View File
@@ -317,7 +317,7 @@ pub struct Radix {
impl Radix {
pub fn new(x: i32, radix: u32) -> Result<Self, &'static str> {
if radix < 2 || radix > 36 {
Err("Unnsupported radix")
Err("Unsupported radix")
} else {
Ok(Self { x, radix })
}
@@ -333,11 +333,16 @@ impl fmt::Display for Radix {
};
let mut result = Vec::new();
// Convert to requested radix by repeated division
while x != 0 {
let (n, m) = x.div_rem(&self.radix);
result.push(std::char::from_digit(m as u32, self.radix).unwrap());
x = n;
}
// Ensure 0 is represented with a single digit
if result.is_empty() {
result.push('0');
}
if negative {
write!(f, "-")?;
@@ -527,4 +532,11 @@ mod tests {
);
assert_eq!(std::fs::read_to_string("test_pb_out").expect("read"), "san bud most noon jaw cash");
}
#[test]
fn radix_display_zero() {
assert_eq!(format!("{}", Radix::new(0, 10).unwrap()), "0");
assert_eq!(format!("{}", Radix::new(15, 16).unwrap()), "f");
assert_eq!(format!("{}", Radix::new(-15, 16).unwrap()), "-f");
}
}