Skip to content

Commit

Permalink
feat: Add ANSIEscapeCode struct with accompanying tests
Browse files Browse the repository at this point in the history
this struct like a placeholder to hold a ansi code and act like abstraction
  • Loading branch information
Syaw0 committed Oct 31, 2024
1 parent d67a238 commit 6367638
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
struct ANSIEscapeCode {
parameter: String,
}
impl ANSIEscapeCode {
fn new(parameter: String) -> Self {
ANSIEscapeCode { parameter }
}

fn code(&self) -> String {
format!("\\x1b[{}m", self.parameter)
}
}

#[cfg(test)]
mod tests {
mod test {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
fn create_simple_ansi_code() {
let p = ANSIEscapeCode::new(String::from("33"));
assert_eq!(p.code(), "\\x1b[33m")
}

#[test]
fn create_reset_ansi_code() {
let reset_ansi = ANSIEscapeCode::new(String::from("0"));
assert_eq!("\\x1b[0m", reset_ansi.code());
}
}

0 comments on commit 6367638

Please sign in to comment.