From 0c590e90564870fa8600460c866c7395b7d865cd Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sun, 3 Sep 2023 23:02:01 +0200 Subject: docs: add spans example --- tests/misc.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/misc.rs b/tests/misc.rs index 416e506..0db0606 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -1,3 +1,9 @@ +use std::{ + fs::File, + io::{BufRead, BufReader}, + process::Command, +}; + use similar_asserts::assert_eq; use walkdir::{DirEntry, WalkDir}; @@ -45,3 +51,31 @@ fn is_source_file(entry: &DirEntry) -> bool { !filename.starts_with('.') // .git, etc. } + +#[test] +fn example_output_in_readme() { + let output = Command::new("cargo") + .args(["run", "--example", "spans"]) + .output() + .unwrap() + .stdout; + + let expected = std::str::from_utf8(&output) + .unwrap() + .trim_end() + .lines() + .map(|s| s.trim_end().to_string()) + .collect::>() + .join("\n"); + + let actual = BufReader::new(File::open("README.md").unwrap()) + .lines() + .flatten() + .skip_while(|l| l != "```output id=spans") + .skip(1) + .take_while(|l| l != "```") + .collect::>() + .join("\n"); + + assert_eq!(actual, expected); +} -- cgit v1.2.3