From 0cb234de5df6f4d8798de85f4f6773daa9a20820 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Thu, 31 Dec 2015 12:00:09 +0100 Subject: [PATCH] Add tests for find_playpens --- .../html_handlebars/helpers/playpen.rs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/renderer/html_handlebars/helpers/playpen.rs b/src/renderer/html_handlebars/helpers/playpen.rs index adc63978..115c3884 100644 --- a/src/renderer/html_handlebars/helpers/playpen.rs +++ b/src/renderer/html_handlebars/helpers/playpen.rs @@ -8,6 +8,7 @@ pub fn render_playpen(s: &mut str) { } +#[derive(PartialOrd, PartialEq, Debug)] struct Playpen{ start_index: u32, end_index: u32, @@ -51,3 +52,53 @@ fn find_playpens(s: &str) -> Vec { playpens } + + + + +// +//--------------------------------------------------------------------------------- +// Tests +// + +#[test] +fn test_find_playpens_no_playpen() { + let s = "Some random text without playpen..."; + assert!(find_playpens(s) == vec![]); +} + +#[test] +fn test_find_playpens_partial_playpen() { + let s = "Some random text with {{#playpen..."; + assert!(find_playpens(s) == vec![]); +} + +#[test] +fn test_find_playpens_empty_playpen() { + let s = "Some random text with {{#playpen}} and {{#playpen }}..."; + assert!(find_playpens(s) == vec![]); +} + +#[test] +fn test_find_playpens_simple_playpen() { + let s = "Some random text with {{#playpen file.rs}} and {{#playpen test.rs }}..."; + + println!("\nOUTPUT: {:?}\n", find_playpens(s)); + + assert!(find_playpens(s) == vec![ + Playpen{start_index: 22, end_index: 42, rust_file: PathBuf::from("file.rs"), editable: false}, + Playpen{start_index: 47, end_index: 68, rust_file: PathBuf::from("test.rs"), editable: false} + ]); +} + +#[test] +fn test_find_playpens_complex_playpen() { + let s = "Some random text with {{#playpen file.rs editable}} and {{#playpen test.rs editable }}..."; + + println!("\nOUTPUT: {:?}\n", find_playpens(s)); + + assert!(find_playpens(s) == vec![ + Playpen{start_index: 22, end_index: 51, rust_file: PathBuf::from("file.rs"), editable: true}, + Playpen{start_index: 56, end_index: 86, rust_file: PathBuf::from("test.rs"), editable: true} + ]); +}