cessen / ropey

A utf8 text rope for manipulating and editing large texts.
MIT License
1.04k stars 46 forks source link

getting an extra blank line when iterating over a slice #15

Closed craigschmidt closed 6 years ago

craigschmidt commented 6 years ago

I'm new to rust, so sorry if I'm doing something dumb, but I'm seeing a weird bug. When iterating over a slice with lines, I get an extra empty line. If you make a new program with cargo like this, it fails. However, I added the same test to ropey as a test in the iter.rs file, and it passed. I don't understand how that can be.

Thanks, Craig

extern crate ropey;

use ropey::Rope;

fn main() {

    let text = "Hello there!\nHow goes it?";
    let rope = Rope::from_str(text);

    // should be the same as rope
    let slice = rope.slice(..);

    // but we get an extra empty line when iterating over the slice
    assert!(slice.lines().count() == rope.lines().count());
}

#[cfg(test)]
mod tests {
    use Rope;

    #[test]
    fn lines_from_slice() {

        let text = "Hello there!\nHow goes it?";
        let rope = Rope::from_str(text);

        // should be the same as rope
        let slice = rope.slice(..);

        // but we get an extra empty line when iterating over the slice
        assert!(slice.lines().count() == rope.lines().count());
    }

}
craigschmidt commented 6 years ago

My Cargo.toml looks like this:

[package]
name = "iterbug"
version = "0.1.0"
authors = ["Craig Schmidt <craig@craigschmidt.com>"]

[dependencies]
ropey = { git = "https://github.com/cessen/ropey", branch = "master" }
cessen commented 6 years ago

Thanks so much for the bug report! Looking into it now. :-)

cessen commented 6 years ago

Found the bug! Working on a fix now.

Thank you again! I really appreciate you taking the time to file such a thorough bug report.

cessen commented 6 years ago

Fixed in bc7f3a2a59c0587951861773bf71115eb9805403.