-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ANSIEscapeCode struct with accompanying tests
this struct like a placeholder to hold a ansi code and act like abstraction
- Loading branch information
Showing
1 changed file
with
21 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |