-
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.
refactor: move ANSIEscapeCode and tests to own module
- Loading branch information
Showing
3 changed files
with
37 additions
and
28 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pub struct ANSIEscapeCode { | ||
parameter: String, | ||
} | ||
impl ANSIEscapeCode { | ||
pub fn new(parameter: String) -> Self { | ||
ANSIEscapeCode { parameter } | ||
} | ||
|
||
pub fn code(&self) -> String { | ||
format!("\\x1b[{}m", self.parameter) | ||
} | ||
} |
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,29 +1,3 @@ | ||
struct ANSIEscapeCode { | ||
parameter: String, | ||
} | ||
impl ANSIEscapeCode { | ||
fn new(parameter: String) -> Self { | ||
ANSIEscapeCode { parameter } | ||
} | ||
mod ansi_escape_code; | ||
|
||
fn code(&self) -> String { | ||
format!("\\x1b[{}m", self.parameter) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
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()); | ||
} | ||
} | ||
// ======================================================================= |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[cfg(test)] | ||
mod ansi_escape_code_test { | ||
use crate::ansi_escape_code::ANSIEscapeCode; | ||
use super::*; | ||
|
||
#[test] | ||
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()); | ||
} | ||
|
||
#[test] | ||
fn create_bright_cyan_ansi_code() { | ||
let reset_ansi = ANSIEscapeCode::new(String::from("96")); | ||
assert_eq!("\\x1b[96m", reset_ansi.code()); | ||
} | ||
} |