hashbrown icon indicating copy to clipboard operation
hashbrown copied to clipboard

"Pony" is misspelled as "Poney" in dozens of places in map.rs.

Open fadedbee opened this issue 1 year ago • 1 comments

The length of the correct spelling is also less, so char count test results will need to be adjusted.

https://github.com/rust-lang/hashbrown/blob/master/src/map.rs#L1294 and onward,

fadedbee avatar Mar 01 '23 08:03 fadedbee

In your closed pull request, you can simply correct not only the spelling, but also the tests themselves. Just run cargo test --doc after correcting the spelling and the compiler will show you which tests need to be corrected. Unfortunately rustdoc only seems to point to the start line of the test, something like this:

failures:

---- src\map.rs - map::Entry<'a,K,V,S,A>::or_insert_with_key (line 5086) stdout ----
Test executable failed (exit code: 101).

stderr:
thread 'main' panicked at 'assertion failed: `(left == right)`
   left: `8`,
  right: `9`', src\map.rs:10:1
stack backtrace:

Here line 5086 is the line you are looking for in the src\map.rs file where the failed test starts:

    use hashbrown::HashMap;

    let mut map: HashMap<&str, usize> = HashMap::new();

    // nonexistent key
    map.entry("ponyland").or_insert_with_key(|key| key.chars().count());
    assert_eq!(map["ponyland"], 9);

    // existing key
    *map.entry("ponyland").or_insert_with_key(|key| key.chars().count() * 10) *= 2
    assert_eq!(map["ponyland"], 18);

Go to line 10 inside the test, i.e. assert_eq!(map["ponyland"], 9); and change 9 to 8, i.e. assert_eq!(map["ponyland"], 8);

The numbering doesn't converge because rustdoc wraps the body of the function (which you actually see above) into a real test function like the one below. Honestly, I don't remember the exact wrapping rule, see rustdoc.

#[test]
fn test {
     use hashbrown::HashMap;

     let mut map: HashMap<&str, usize> = HashMap::new();

     // nonexistent key
     map.entry("ponyland").or_insert_with_key(|key| key.chars().count());
     assert_eq!(map["ponyland"], 9);

     // existing key
     *map.entry("ponyland").or_insert_with_key(|key| key.chars().count() * 10) *= 2
     assert_eq!(map["ponyland"], 18);
}

JustForFun88 avatar Mar 02 '23 07:03 JustForFun88