dbrgn / tealdeer

A very fast implementation of tldr in Rust.
https://dbrgn.github.io/tealdeer/
Apache License 2.0
4.09k stars 124 forks source link

Line iterator: Improve test functions #316

Closed qknogxxb closed 1 year ago

qknogxxb commented 1 year ago

@niklasmohrin As you mentioned in #314, I improved test functions on LineIterator. With your counter example code:

let mut previous = 0;
if let Err(e) = Read::bytes(&mut self.reader)
    .find(|b| {
        let res = previous == b'\n';
        previous = *b.as_ref().unwrap();
        res
    })
    .transpose()

The test function will fail:

❯ cargo test test_first_line
   Compiling tealdeer v1.6.1 (/home/potato/repos/tealdeer)
    Finished test [unoptimized + debuginfo] target(s) in 2.76s
     Running unittests src/main.rs (target/debug/deps/tldr-8d4cf65b28f436c9)

running 2 tests
test line_iterator::test::test_first_line_old_format ... ok
test line_iterator::test::test_first_line_new_format ... FAILED

failures:

---- line_iterator::test::test_first_line_new_format stdout ----
thread 'line_iterator::test::test_first_line_new_format' panicked at 'assertion failed: `(left == right)`
  left: `ExampleCode("Description")`,
 right: `Description("Description")`', src/line_iterator.rs:122:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    line_iterator::test::test_first_line_new_format

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 14 filtered out; finished in 0.00s

error: test failed, to rerun pass `--bin tldr`

Do you think this is good enough? Or you have another idea?

qknogxxb commented 1 year ago

And... It's wired that I didn't find any specific .md located in my ~/.cache/tealdeer/tldr-pages is a "new format". In other words, they are all "old format", which means that my contribution code will never run. Anyway, this has nothing to do with this PR, I just mention this here.

niklasmohrin commented 1 year ago

Yeah, I am not exactly sure what the idea between old and new format is or if there are any plans for migrating towards one or another. I think we talked about this some time ago, the info is probably buried in some comment somewhere. @dbrgn Do you remember what that was about?

dbrgn commented 1 year ago

Support for the new format was added here: https://github.com/dbrgn/tealdeer/pull/32

See discussion at https://github.com/tldr-pages/tldr/pull/958

From what I can tell, the new format was never accepted. So I guess we could remove it from tealdeer as well...

niklasmohrin commented 1 year ago

Well, thanks for the contribution anyways :)