diff options
| author | Martin Fischer <martin@push-f.com> | 2023-09-03 23:02:01 +0200 | 
|---|---|---|
| committer | Martin Fischer <martin@push-f.com> | 2023-09-03 23:02:01 +0200 | 
| commit | 0c590e90564870fa8600460c866c7395b7d865cd (patch) | |
| tree | d702e200ed5b815a32b6bbd3cf7c6e8c5c370c9c /tests | |
| parent | 6e6bbcd053c6114a9fa75052b09e701eaa2f3465 (diff) | |
docs: add spans example
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/misc.rs | 34 | 
1 files changed, 34 insertions, 0 deletions
| 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::<Vec<_>>() +        .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::<Vec<_>>() +        .join("\n"); + +    assert_eq!(actual, expected); +} | 
