From: Huck Boles Date: Sun, 14 May 2023 22:18:26 +0000 (-0500) Subject: benchmarks and tests X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=c41a8acaf893637e490dfa6ad577a68db1d6b5d6;p=metaforge.git benchmarks and tests --- diff --git a/.gitignore b/.gitignore index 9c45757..f3f425c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /target -/test/build/ +files/site/build diff --git a/Cargo.toml b/Cargo.toml index a8716f3..81a5157 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,9 @@ pretty_assertions = "1" criterion = "0.4" [[bench]] -name = "build_site" +name = "build_metafile" +harness = false + +[[bench]] +name = "map_dir" harness = false diff --git a/benches/build_site.rs b/benches/build_metafile.rs similarity index 74% rename from benches/build_site.rs rename to benches/build_metafile.rs index 96304d2..52dba97 100644 --- a/benches/build_site.rs +++ b/benches/build_metafile.rs @@ -16,13 +16,16 @@ pub fn build_file_benchmark(c: &mut Criterion) { c.bench_function("build benchmark file", |b| { b.iter(|| { - let string = std::fs::read_to_string(black_box(&source)).unwrap(); - let file = metaforge::parse_file(string, black_box(&opts)).unwrap(); - let mut path = opts - .build - .join(source.strip_prefix(black_box(&opts.source)).unwrap()); + let string = std::fs::read_to_string(black_box(&source)).expect("read file"); + let file = metaforge::parse_file(string, black_box(&opts)).expect("parse file"); + let mut path = opts.build.join( + source + .strip_prefix(black_box(&opts.source)) + .expect("strip path"), + ); path.set_extension("html"); - std::fs::write(path, metaforge::build_metafile(&file).unwrap()).unwrap(); + std::fs::write(path, metaforge::build_metafile(&file).expect("build file")) + .expect("write file"); }) }); } diff --git a/files/site/build/dir1/dir.html b/files/site/build/dir1/dir.html deleted file mode 100644 index e0b7905..0000000 --- a/files/site/build/dir1/dir.html +++ /dev/null @@ -1,28 +0,0 @@ - - -
HEADER
- -

LIST

-This is to test using arrays as lists. - - - - - - diff --git a/files/site/build/dir1/sub_dir1/deep1/deep.html b/files/site/build/dir1/sub_dir1/deep1/deep.html deleted file mode 100644 index a60088b..0000000 --- a/files/site/build/dir1/sub_dir1/deep1/deep.html +++ /dev/null @@ -1,5 +0,0 @@ - -

SIMPLE SUBSTITUTION

-

variable: GOOD

- - diff --git a/files/site/build/dir1/sub_dir1/deep2/deep.html b/files/site/build/dir1/sub_dir1/deep2/deep.html deleted file mode 100644 index 27c9159..0000000 --- a/files/site/build/dir1/sub_dir1/deep2/deep.html +++ /dev/null @@ -1,5 +0,0 @@ - - -GOOD - - diff --git a/files/site/build/dir1/sub_dir1/sub_dir.html b/files/site/build/dir1/sub_dir1/sub_dir.html deleted file mode 100644 index a510f98..0000000 --- a/files/site/build/dir1/sub_dir1/sub_dir.html +++ /dev/null @@ -1,17 +0,0 @@ - - -
HEADER
- -

LINKS

-

This should create a group of bold links A Website B Place C Dest

- - - - - diff --git a/files/site/build/dir1/sub_dir2/sub_dir.html b/files/site/build/dir1/sub_dir2/sub_dir.html deleted file mode 100644 index 6907021..0000000 --- a/files/site/build/dir1/sub_dir2/sub_dir.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - -

BLANK

-

This should have no header or footer

- - - - - diff --git a/files/site/build/dir1/sub_dir3/sub_dir.html b/files/site/build/dir1/sub_dir3/sub_dir.html deleted file mode 100644 index 52ea22b..0000000 --- a/files/site/build/dir1/sub_dir3/sub_dir.html +++ /dev/null @@ -1,11 +0,0 @@ - - -
HEADER
- -

HEADER LIST

-

This should have a list in the header

- - - - - diff --git a/files/site/build/dir2/dir.html b/files/site/build/dir2/dir.html deleted file mode 100644 index e3465ee..0000000 --- a/files/site/build/dir2/dir.html +++ /dev/null @@ -1,19 +0,0 @@ - -

MARKDOWN

- -

This is a test for how various markdown elements translate

-

Small Header

- -

tiny header

-

Fancy Text With -Adornments

-

-Inline HTML -

-

a link

- - diff --git a/files/site/build/root.html b/files/site/build/root.html deleted file mode 100644 index 139ffbf..0000000 --- a/files/site/build/root.html +++ /dev/null @@ -1,12 +0,0 @@ - - -
HEADER
- -

ROOT

-

This is to test that the default base works without any -defintions.

- - - - - diff --git a/files/site/source/root.meta b/files/site/source/root.meta index 957a2d3..3af0ab7 100644 --- a/files/site/source/root.meta +++ b/files/site/source/root.meta @@ -1,2 +1,2 @@ -# ROOT -This is to test that the default base works without any defintions. +&{ base = 'text' } +TEST diff --git a/src/builder.rs b/src/builder.rs index ff8e702..ad0d00f 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -248,15 +248,11 @@ mod tests { } #[test] - fn test_build_metafile() -> Result<()> { + fn test_metafile_to_string() -> Result<()> { let opts = build_options()?; let path = opts.source.join("dir1/sub_dir1/deep2/deep.meta"); - let expanded = "\n\nGOOD\n\n\n"; - build_metafile(&MetaFile::build(path, &opts)?)?; - assert_eq!( - std::fs::read_to_string(opts.build.join("dir1/sub_dir1/deep2/deep.html"))?, - expanded - ); + let expanded = "GOOD"; + assert_eq!(build_metafile(&MetaFile::build(path, &opts)?)?, expanded); Ok(()) } diff --git a/tests/build_dir.rs b/tests/build_dir.rs new file mode 100644 index 0000000..f18d0f6 --- /dev/null +++ b/tests/build_dir.rs @@ -0,0 +1,4 @@ +use color_eyre::Result; + +#[test] +fn build_dir() -> Result<()> {}