Skip to content

Commit

Permalink
fix: Replace tabs with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Nov 8, 2023
1 parent 3ab6fb6 commit bf281a5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ dev = '''set -e
cargo watch -i .cargo -s 'cargo run --features dev'
'''

dev-install = '''set -e
cargo build
sudo rm /usr/local/bin/oatmeal
sudo mv ./target/debug/oatmeal /usr/local/bin/
'''

goreleaser = '''set -e
export OM_VERSION=$(cat Cargo.toml | grep version | head -n1 | awk -F '"' '{print $2}')
Expand Down
6 changes: 3 additions & 3 deletions src/domain/models/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Message {
return Message {
author: author.clone(),
author_formatted: formatted_author(author),
text: text.to_string(),
text: text.to_string().replace('\t', " "),
mtype: MessageType::Normal,
};
}
Expand All @@ -48,7 +48,7 @@ impl Message {
return Message {
author: author.clone(),
author_formatted: formatted_author(author),
text: text.to_string(),
text: text.to_string().replace('\t', " "),
mtype,
};
}
Expand All @@ -58,7 +58,7 @@ impl Message {
}

pub fn append(&mut self, text: &str) {
self.text += text;
self.text += &text.replace('\t', " ");
}

pub fn as_string_lines(&self, line_max_width: u16) -> Vec<String> {
Expand Down
25 changes: 25 additions & 0 deletions src/domain/models/message_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ fn it_executes_new() {
assert_eq!(msg.mtype, MessageType::Normal);
}

#[test]
fn it_executes_new_replacing_tabs() {
let msg = Message::new(Author::Oatmeal, "\t\tHi there!");
assert_eq!(msg.author, Author::Oatmeal);
assert_eq!(msg.author_formatted, "Oatmeal");
assert_eq!(msg.text, " Hi there!".to_string());
assert_eq!(msg.mtype, MessageType::Normal);
}

#[test]
fn it_executes_new_with_type() {
let msg = Message::new_with_type(Author::Oatmeal, MessageType::Error, "It broke!");
Expand All @@ -22,6 +31,15 @@ fn it_executes_new_with_type() {
assert_eq!(msg.mtype, MessageType::Error);
}

#[test]
fn it_executes_new_with_type_replacing_tabs() {
let msg = Message::new_with_type(Author::Oatmeal, MessageType::Error, "\t\tIt broke!");
assert_eq!(msg.author, Author::Oatmeal);
assert_eq!(msg.author_formatted, "Oatmeal");
assert_eq!(msg.text, " It broke!".to_string());
assert_eq!(msg.mtype, MessageType::Error);
}

#[test]
fn it_executes_message_type() {
let msg = Message::new_with_type(Author::Oatmeal, MessageType::Error, "It broke!");
Expand All @@ -35,6 +53,13 @@ fn it_executes_append() {
assert_eq!(msg.text, "Hi there! It's me!");
}

#[test]
fn it_executes_append_with_tabs() {
let mut msg = Message::new(Author::Oatmeal, "Hi there!");
msg.append("\tIt's me!");
assert_eq!(msg.text, "Hi there! It's me!");
}

#[test]
fn it_executes_as_string_lines() {
let msg = Message::new(Author::Oatmeal, "Hi there! This is a really long line that pushes the boundaries of 50 characters across the screen, resulting in the line being wrapped. Cool right?");
Expand Down

0 comments on commit bf281a5

Please sign in to comment.