-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR #38 mv test suites from main crate
Merge branch 'test_crates'
- Loading branch information
Showing
19 changed files
with
192 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "test-html-ref" | ||
description = "Reference implementation HTML output comparison tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
jotdown = { path = "../.." } | ||
|
||
[lib] | ||
name = "test_html_ref" | ||
path = "lib.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
fn main() { | ||
let has_dj = std::fs::read_dir(".").unwrap().any(|e| { | ||
e.map_or(false, |e| { | ||
e.path() | ||
.extension() | ||
.map_or(false, |ext| ext.to_str() == Some("dj")) | ||
}) | ||
}); | ||
if has_dj { | ||
let status = std::process::Command::new("make") | ||
.status() | ||
.expect("failed to execute make"); | ||
assert!(status.success()); | ||
} else { | ||
std::fs::write("ref.rs", &[b'\n']).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#[cfg(test)] | ||
mod r#ref; | ||
|
||
#[macro_export] | ||
macro_rules! compare { | ||
($src:expr, $expected:expr) => { | ||
use jotdown::Render; | ||
let src = $src; | ||
let expected = std::fs::read_to_string($expected).expect("read failed"); | ||
let p = jotdown::Parser::new(src); | ||
let mut actual = String::new(); | ||
jotdown::html::Renderer::default() | ||
.push(p, &mut actual) | ||
.unwrap(); | ||
assert_eq!(actual, expected, "\n{}", { | ||
use std::io::Write; | ||
let mut child = std::process::Command::new("diff") | ||
.arg("--color=always") | ||
.arg("-") | ||
.arg($expected) | ||
.stdin(std::process::Stdio::piped()) | ||
.stdout(std::process::Stdio::piped()) | ||
.spawn() | ||
.expect("spawn diff failed"); | ||
let mut stdin = child.stdin.take().unwrap(); | ||
let actual = actual.clone(); | ||
std::thread::spawn(move || stdin.write_all(actual.as_bytes()).unwrap()); | ||
let stdout = child.wait_with_output().unwrap().stdout; | ||
String::from_utf8(stdout).unwrap() | ||
}); | ||
}; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "test-html-ut" | ||
description = "HTML output unit tests." | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
jotdown = { path = "../.." } | ||
|
||
[lib] | ||
name = "test_html_ut" | ||
path = "lib.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
let status = std::process::Command::new("make") | ||
.status() | ||
.expect("failed to execute make"); | ||
assert!(status.success()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#[macro_export] | ||
macro_rules! compare { | ||
($src:expr, $expected:expr) => { | ||
use jotdown::Render; | ||
let src = $src; | ||
let expected = $expected; | ||
let p = jotdown::Parser::new(src); | ||
let mut actual = String::new(); | ||
jotdown::html::Renderer::default() | ||
.push(p, &mut actual) | ||
.unwrap(); | ||
assert_eq!( | ||
actual.trim(), | ||
expected.trim(), | ||
concat!( | ||
"\n", | ||
"\x1b[0;1m========================= INPUT ============================\x1b[0m\n", | ||
"\x1b[2m{}", | ||
"\x1b[0;1m=================== ACTUAL vs EXPECTED =====================\x1b[0m\n", | ||
"{}", | ||
"\x1b[0;1m============================================================\x1b[0m\n", | ||
), | ||
$src, | ||
{ | ||
let a = actual.trim().split('\n'); | ||
let b = expected.trim().split('\n'); | ||
let max = a.clone().count().max(b.clone().count()); | ||
let a_width = a.clone().map(|a| a.len()).max().unwrap_or(0); | ||
a.chain(std::iter::repeat("")) | ||
.zip(b.chain(std::iter::repeat(""))) | ||
.take(max) | ||
.map(|(a, b)| { | ||
format!( | ||
"\x1b[{}m{:a_width$}\x1b[0m {}= \x1b[{}m{}\x1b[0m\n", | ||
if a == b { "2" } else { "31" }, | ||
a, | ||
if a == b { '=' } else { '!' }, | ||
if a == b { "2" } else { "32" }, | ||
b, | ||
a_width = a_width, | ||
) | ||
}) | ||
.collect::<String>() | ||
}, | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.