use codeframe::{Codeframe, Color}; use k9::*; #[test] fn simple_capture() { super::setup_test_env(); let raw_lines = "let a: i64 = 12;".to_owned(); let codeframe = Codeframe::new(raw_lines, 1).set_color(Color::Red).capture(); assert_matches_inline_snapshot!( format!("\n{}", codeframe.expect("must be present")), " 1 | let a: i64 = 12; " ); let raw_lines = "macro_rules! test_simple_style { ($string:expr, $style:ident) => { #[test] fn $style() { assert_eq!( s.$style().to_string(), ansi_term::Style::new().$style().paint(s).to_string() ) } }; }" .to_owned(); let codeframe = Codeframe::new(raw_lines, 5).set_color(Color::Red).capture(); assert_matches_inline_snapshot!( format!("\n{}", codeframe.expect("must be present")), " 3 | #[test] 4 | fn $style() { 5 | assert_eq!( 6 | s.$style().to_string(), 7 | ansi_term::Style::new().$style().paint(s).to_string() 8 | ) " ); let raw_lines = "macro_rules! test_simple_style { ($string:expr, $style:ident) => { #[test] fn $style() { assert_eq!( s.$style().to_string(), ansi_term::Style::new().$style().paint(s).to_string() ) } }; }" .to_owned(); let codeframe = Codeframe::new(raw_lines, 5).capture(); assert_matches_inline_snapshot!( format!("\n{}", codeframe.expect("must be present")), " 3 | #[test] 4 | fn $style() { 5 | assert_eq!( 6 | s.$style().to_string(), 7 | ansi_term::Style::new().$style().paint(s).to_string() 8 | ) " ); } #[test] fn out_of_bound_line_number() { super::setup_test_env(); let raw_lines = "let a: i64 = 12;".to_owned(); let codeframe = Codeframe::new(raw_lines, 2) .set_color(Color::Black) .capture(); assert_matches_inline_snapshot!( format!("\n{}", codeframe.expect("must be present")), " 1 | let a: i64 = 12; " ); }