// Copyright 2019 Fredrik Portström // This is free software distributed under the terms specified in // the file LICENSE at the top-level directory of this distribution. use crate::test_cases::TEST_CASES; pub fn run_test(configuration: &parse_wiki_text::Configuration) { let mut output = concat!( "Parse Wiki Text test cases", "", "
" ).to_owned(); if let Some(window) = TEST_CASES .windows(2) .find(|window| window[0].0 >= window[1].0) { panic!("Sort: {:#?}", (window[0].0, window[1].0)); } for (title, test_cases) in TEST_CASES { if let Some(window) = test_cases.windows(2).find(|window| window[0] >= window[1]) { panic!("Sort: {:#?}", window); } output += &format!("", title.replace(" ", "_")); output += title; output += &format!(" {}", test_cases.len()); } output += "
"; for (title, test_cases) in TEST_CASES { output += &format!("

", title.replace(" ", "_")); output += title; output += "

"; for wiki_text in *test_cases { output += "
";
            output += &wiki_text
                .replace("&", "&")
                .replace("<", "<")
                .replace("\t", "")
                .replace("\n", "\n")
                .replace(" ", "·")
                .replace("", "");
            match std::panic::catch_unwind(|| configuration.parse(wiki_text)) {
                Err(_) => {
                    eprintln!("Panic with wiki text {:?}", wiki_text);
                    output += "

panic
"; } Ok(result) => { output += "
";
                    output += &format!("{:#?}", result)
                        .replace("&", "&")
                        .replace("<", "<");
                    output += "
"; } } } } output += ""; if let Err(error) = std::fs::write("report.html", output) { eprintln!("Failed to write report: {}", error); std::process::exit(1); } }