From a2e04ff18ad27be4dc1c66079941baaec79e003f Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 4 Jan 2023 15:57:41 -0800 Subject: Copy the last version of the parse_wiki_text crate in for development --- parse_wiki_text/examples/test/main.rs | 51 ++ parse_wiki_text/examples/test/test.rs | 70 +++ parse_wiki_text/examples/test/test_cases.rs | 726 ++++++++++++++++++++++++++++ 3 files changed, 847 insertions(+) create mode 100644 parse_wiki_text/examples/test/main.rs create mode 100644 parse_wiki_text/examples/test/test.rs create mode 100644 parse_wiki_text/examples/test/test_cases.rs (limited to 'parse_wiki_text/examples/test') diff --git a/parse_wiki_text/examples/test/main.rs b/parse_wiki_text/examples/test/main.rs new file mode 100644 index 0000000..72872fc --- /dev/null +++ b/parse_wiki_text/examples/test/main.rs @@ -0,0 +1,51 @@ +// 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. + +extern crate parse_wiki_text; + +mod test; +mod test_cases; + +fn main() { + let mut args = std::env::args(); + match args.nth(1) { + None => return test::run_test(&Default::default()), + Some(command) => match &command as _ { + "file" => { + if let Some(path) = args.next() { + if args.next().is_none() { + match std::fs::read_to_string(path) { + Err(error) => { + eprintln!("Failed to read file: {}", error); + std::process::exit(1); + } + Ok(file_contents) => { + println!( + "{:#?}", + parse_wiki_text::Configuration::default().parse(&file_contents) + ); + return; + } + } + } + } + } + "text" => { + if let Some(wiki_text) = args.next() { + if args.next().is_none() { + println!( + "{:#?}", + parse_wiki_text::Configuration::default() + .parse(&wiki_text.replace("\\t", "\t").replace("\\n", "\n")) + ); + return; + } + } + } + _ => {} + }, + } + eprintln!("invalid use"); + std::process::exit(1); +} diff --git a/parse_wiki_text/examples/test/test.rs b/parse_wiki_text/examples/test/test.rs new file mode 100644 index 0000000..9f04942 --- /dev/null +++ b/parse_wiki_text/examples/test/test.rs @@ -0,0 +1,70 @@ +// 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); + } +} diff --git a/parse_wiki_text/examples/test/test_cases.rs b/parse_wiki_text/examples/test/test_cases.rs new file mode 100644 index 0000000..da7b374 --- /dev/null +++ b/parse_wiki_text/examples/test/test_cases.rs @@ -0,0 +1,726 @@ +// 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. + +pub const TEST_CASES: &[(&str, &[&str])] = &[ + ( + "basic", + &[ + "", + "\t", + "\t\n", + "\t alpha", + "\talpha", + "\n", + "\n\t", + "\n\n\nalpha", + "\n\nalpha", + "\n\nalpha\n\n", + "\n \nalpha", + "\nalpha", + "\nalpha\n", + " ", + " \n\nalpha", + " \nalpha", + " ", + "!!", + "alpha", + "alpha\t", + "alpha\n", + "alpha\n\t", + "alpha\n\n", + "alpha\n\n\n", + "alpha\n\n ", + "alpha\n ", + "alpha\n \n", + "alpha\nbeta", + "alpha ", + "alpha \n", + ], + ), + ( + "bold italic", + &[ + "'", + "''", + "'''", + "''''", + "'''''", + "''''''", + "'''''''", + "''''''''", + "'''alpha", + "'''alpha''", + "'''alpha'''", + "''alpha", + "''alpha''", + "''alpha'''", + "alpha''", + "alpha'''", + "alpha'''beta", + "alpha'''beta'''gamma", + "alpha'''beta''gamma", + "alpha''beta", + "alpha''beta'''gamma", + "alpha''beta''gamma", + ], + ), + ( + "character entity", + &[ + "≪", + "Ö", + "<", + "<ö", + "<", + "< alpha", + "<ö", + "<alpha", + "ö", + "alpha <", + "alpha < beta", + "alpha<", + "alpha<beta", + ], + ), + ( + "comment", + &[ + "", + "beta", + "beta", + "-->beta", + "", + " beta", + "", + "beta", + "beta", + "alpha ", + "{{", + "{{alpha}}", + "}}", + ], + ), + ( + "paragraph break", + &[ + "alpha\t\n\nbeta", + "alpha\n\t\nbeta", + "alpha\n\n\t beta", + "alpha\n\n\tbeta", + "alpha\n\n\n\nbeta", + "alpha\n\n\nbeta", + "alpha\n\nbeta", + "alpha\n \nbeta", + "alpha \n\nbeta", + ], + ), + ( + "parameter", + &[ + "*alpha}}}", + "[[alpha|beta}}}]]", + "{{{", + "{{{\talpha}}}", + "{{{\nalpha}}}", + "{{{''}}}", + "{{{[[alpha|beta}}}", + "{{{alpha\t|beta}}}", + "{{{alpha\t}}}", + "{{{alpha\n|beta}}}", + "{{{alpha\n}}}", + "{{{alpha |beta}}}", + "{{{alpha }}}", + "{{{alpha|", + "{{{alpha|\tbeta}}}", + "{{{alpha|\t|}}}", + "{{{alpha|\t}}}", + "{{{alpha|\nbeta}}}", + "{{{alpha|\n|}}}", + "{{{alpha|\n}}}", + "{{{alpha| beta|}}}", + "{{{alpha| |}}}", + "{{{alpha| }}}", + "{{{alpha|beta\t|}}}", + "{{{alpha|beta\n|}}}", + "{{{alpha|beta |}}}", + "{{{alpha|beta|", + "{{{alpha|beta|\n}}}", + "{{{alpha|beta|gamma}}}", + "{{{alpha|beta|}}}", + "{{{alpha|beta}}}", + "{{{alpha|}}}", + "{{{alpha}}}", + "{{{|''}}}", + "{{{||}}}", + "{{{|}}}", + "{{{}}}", + "}}}", + ], + ), + ( + "preformatted block", + &[ + " alpha", + " alpha", + " alpha\n\n\nbeta", + " alpha\n\nbeta", + " alpha\n beta", + " alpha\n beta\n gamma", + " alpha\n beta\ngamma", + " alpha\nbeta", + " alpha\nbeta\n gamma", + "alpha\t\n beta", + "alpha\n\n beta", + "alpha\n \n beta", + "alpha\n =beta=\ngamma", + "alpha\n beta", + "alpha\n beta\n gamma", + "alpha\n beta\ngamma", + "alpha \n beta", + ], + ), + ( + "redirect", + &[ + "\t#REDIRECT[[alpha]]", + "\n\n#REDIRECT[[alpha]]", + "\n #REDIRECT[[alpha]]", + "\n#REDIRECT [[alpha]]", + " \n#REDIRECT[[alpha]]", + " #REDIRECT[[alpha]]", + " #REDIRECT[[alpha]]", + "#REDIRECT\t:[[alpha]]", + "#REDIRECT\t[[alpha]]", + "#REDIRECT\n\n[[alpha]]", + "#REDIRECT\n [[alpha]]", + "#REDIRECT\n:\n[[alpha]]", + "#REDIRECT\n:[[alpha]]", + "#REDIRECT\n[[alpha]]", + "#REDIRECT \n[[alpha]]", + "#REDIRECT [[alpha]]", + "#REDIRECT : [[alpha]]", + "#REDIRECT :[[alpha]]", + "#REDIRECT [[alpha]]", + "#REDIRECT:\t[[alpha]]", + "#REDIRECT:\n[[alpha]]", + "#REDIRECT: [[alpha]]", + "#REDIRECT:[[alpha]]", + "#REDIRECT[[alpha]]", + "#REDIRECT[[alpha]]\n\nbeta", + "#REDIRECT[[alpha]]\n beta", + "#REDIRECT[[alpha]]\nbeta", + "#REDIRECT[[alpha]] \nbeta", + "#REDIRECT[[alpha]] beta", + "#REDIRECT[[alpha]] beta", + "#REDIRECT[[alpha]]''beta", + "#REDIRECT[[alpha]]beta", + "#REDIRECT[[alpha|]]", + "#REDIRECT[[alpha|]]beta", + "#REDIRECT[[alpha|beta\ngamma]]", + "#REDIRECT[[alpha|beta]]", + "#REDIRECT[[alpha|beta]]=gamma=", + "#REDIRECT[[alpha|beta]]gamma", + "#ReDiReCt[[alpha]]", + "#rEdIrEcT[[alpha]]", + "#redirect[[alpha]]", + ], + ), + ( + "table", + &[ + " {|\n |}", + " {|\n|}", + "alpha\n{|\nbeta\n|}", + "{|", + "{|\n |}", + "{|\n!\n alpha\n|}", + "{|\n!\n!\n|}", + "{|\n!\nalpha\n\nbeta\n|}", + "{|\n!\nalpha\n\n|}", + "{|\n!\nalpha\nbeta\n|}", + "{|\n!\nalpha \n|}", + "{|\n!\n|\n|}", + "{|\n!\n|-\n|}", + "{|\n!\n|}", + "{|\n! alpha\n|}", + "{|\n!!\n|}", + "{|\n!!!\n|}", + "{|\n!!!!\n|}", + "{|\n!!!|\n|}", + "{|\n!alpha\n\nbeta\n|}", + "{|\n!alpha\nbeta\n|}", + "{|\n!alpha\nbeta|gamma\n|}", + "{|\n!alpha\n|}", + "{|\n!alpha!!beta\n|}", + "{|\n!alpha!beta\n|}", + "{|\n!alpha|beta\n|}", + "{|\n!alpha||beta\n|}", + "{|\n!|\n|}", + "{|\n!|!!\n|}", + "{|\n!|alpha\n|}", + "{|\n!|alpha|beta\n|}", + "{|\n!||\n|}", + "{|\n!||alpha\n|}", + "{|\n!|||\n|}", + "{|\n*alpha\n|}", + "{|\n=alpha=\n|}", + "{|\nalpha\n|}", + "{|\n|", + "{|\n|\n alpha\n|}", + "{|\n|\n!\n|}", + "{|\n|\n*alpha\n|}", + "{|\n|\n=alpha=\n|}", + "{|\n|\nalpha\n\nbeta\n|}", + "{|\n|\nalpha\n\n|}", + "{|\n|\nalpha\nbeta\n|}", + "{|\n|\nalpha \n|}", + "{|\n|\n|\n|}", + "{|\n|\n|-\n|}", + "{|\n|\n|}", + "{|\n| alpha\n|}", + "{|\n|+\n alpha\n|}", + "{|\n|+\n*alpha\n|}", + "{|\n|+\n=alpha=\n|}", + "{|\n|+\nalpha\n\nbeta\n|}", + "{|\n|+\nalpha\nbeta\n|}", + "{|\n|+\nalpha\n|}", + "{|\n|+\n|+\n|}", + "{|\n|+\n|}", + "{|\n|+ alpha\n|}", + "{|\n|+!!\n|}", + "{|\n|+alpha\n\nbeta\n|}", + "{|\n|+alpha\nbeta\n|}", + "{|\n|+alpha\n|}", + "{|\n|+alpha \n|}", + "{|\n|+|\n|}", + "{|\n|+|alpha|\n|}", + "{|\n|+|alpha|beta\n|}", + "{|\n|+||\n|}", + "{|\n|+||alpha\n|}", + "{|\n|+|||\n|}", + "{|\n|-\n alpha\n|}", + "{|\n|-\n!\n|}", + "{|\n|-\n*alpha\n|}", + "{|\n|-\n=alpha=\n|}", + "{|\n|-\nalpha\n|}", + "{|\n|-\n|\n|}", + "{|\n|-\n|-\n|}", + "{|\n|-\n|}", + "{|\n|- alpha\n|}", + "{|\n|-alpha\n\n|}", + "{|\n|-alpha\n|}", + "{|\n|-alpha \n|}", + "{|\n|alpha\n\nbeta\n|}", + "{|\n|alpha\nbeta\n|}", + "{|\n|alpha\nbeta|gamma\n|}", + "{|\n|alpha\n|}", + "{|\n|alpha!!beta\n|}", + "{|\n|alpha!beta\n|}", + "{|\n|alpha|\n|}", + "{|\n|alpha|beta\n|}", + "{|\n|alpha||beta\n|}", + "{|\n||\n|}", + "{|\n||alpha\n|}", + "{|\n|||\n|}", + "{|\n||||\n|}", + "{|\n|}", + "{|\n|}\t\nalpha", + "{|\n|}\n\n\nalpha", + "{|\n|}\n\nalpha", + "{|\n|}\nalpha", + "{|\n|} \nalpha", + "{|\n|}alpha", + "{|alpha\nbeta\n|}", + "{|alpha\n|}", + ], + ), + ( + "tag", + &[ + "
", + "
", + "", + "", + "beta", + "", + "", + "", + " alpha", + "alpha", + "", + "", + "
", + "
", + "", + "
", + "", + "", + "beta", + "", + "", + "", + " alpha", + "alpha", + "", + "", + "
", + "
", + "alphabeta", + "", + "", + "", + "", + "\talpha", + "\nalpha", + " alpha", + "", + "alpha\t", + "alpha\n", + "alpha ", + "alpha", + "alpha", + ], + ), + ( + "template", + &[ + "*alpha}}", + "[[alpha|beta}}]]", + "alpha {{beta}}", + "alpha {{beta}} gamma", + "alpha{{beta}}", + "alpha{{beta}}gamma", + "{{\nalpha}}", + "{{''}}", + "{{[[alpha|beta}}", + "{{alpha", + "{{alpha\n|beta}}", + "{{alpha\n|}}", + "{{alpha\n}}", + "{{alpha|", + "{{alpha|\nbeta}}", + "{{alpha|\n}}", + "{{alpha| beta}}", + "{{alpha|''}}", + "{{alpha|beta", + "{{alpha|beta\n=gamma}}", + "{{alpha|beta\n}}", + "{{alpha|beta =gamma}}", + "{{alpha|beta }}", + "{{alpha|beta=\ngamma}}", + "{{alpha|beta= gamma}}", + "{{alpha|beta=gamma\n}}", + "{{alpha|beta=gamma }}", + "{{alpha|beta=gamma=delta}}", + "{{alpha|beta=gamma|delta=epsilon}}", + "{{alpha|beta=gamma|delta}}", + "{{alpha|beta=gamma}}", + "{{alpha|beta=}}", + "{{alpha|beta|gamma=delta}}", + "{{alpha|beta|gamma}}", + "{{alpha|beta}", + "{{alpha|beta}}", + "{{alpha|beta}} gamma", + "{{alpha|beta}}gamma", + "{{alpha|}", + "{{alpha|}}", + "{{alpha}", + "{{alpha}}", + "{{alpha}} beta", + "{{alpha}}beta", + "}}", + ], + ), +]; -- cgit v1.2.3-70-g09d2