1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-17 02:25:17 +00:00
starship/src/modules/line_break.rs
2020-08-16 23:33:40 -04:00

41 lines
1019 B
Rust

use super::{Context, Module};
use crate::segment::Segment;
/// Creates a module for the line break
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
const LINE_ENDING: &str = "\n";
let show_newline = context.config.get_root_config().add_newline;
if !show_newline {
return None;
}
let mut module = context.new_module("line_break");
module.set_segments(vec![Segment::new(None, LINE_ENDING)]);
Some(module)
}
#[cfg(test)]
mod tests {
use crate::test::ModuleRenderer;
#[test]
fn add_newline_by_default() {
let expected = Some(String::from("\n"));
let actual = ModuleRenderer::new("line_break").collect();
assert_eq!(expected, actual);
}
#[test]
fn dont_add_newline_when_disabled() {
let expected = None;
let config = toml::toml! {
add_newline = false
};
let actual = ModuleRenderer::new("line_break").config(config).collect();
assert_eq!(expected, actual);
}
}