-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When applying inline snapshot, generate prefix/suffix using char offsets #140
Conversation
This looks good. The start and end come from Still not sure why I couldn't reproduce though! |
One more note — the existing code doesn't seem to run the I'm not sure how we ended up here — this PR solves the problems but is basically a reversion of https://github.com/mitsuhiko/insta/pull/43/files. As I wrote a couple of years ago now — would be great to find a way of testing this code better. Very open to ideas on how to do that and happy to execute. An aside — @c-spencer — I figured out why I couldn't replicate — I was using a different machine which had an older version of |
Aha, maybe the way the offsets were collected was changed (and with no tests, not caught)? Initial inclination would be something along the lines of tests in Alternatively an outside-in approach would be to just have a |
I'm sufficiently confused now that I will need to look into it. Maybe we were confused by "utf-8 character". Normally you would assume this to be defined as "Unicode Character" (char) and "UTF-8 Offset" (bytes). |
While I haven't looked into it enough — I can if you want me to — I'm fairly confident that @c-spencer 's suggestion is correct — that the code was correct 18 months ago, then something other than these lines changed, and now it's incorrect. So reverting these lines makes it work again. What are your thoughts on testing this code @mitsuhiko ? That seems like the underlying problem here. I haven't written much rust recently so not sure what the latest & greatest is for these sorts of high context tests. |
@max-sixty i will look into it now. |
Thanks. I will add tests now. |
Thanks @mitsuhiko ! FYI I've got a bit more time now so happy to take some of this on again. Though the crate is somewhat feature-complete at this stage. Tangentially — I had also tried doing inline snapshot tests for python, but decided it's probably not possible with standard |
Fixes #137
Previously the columns delimiting the replacement were being interpreted as byte offsets into their lines, rather than char offsets. This fix just updates the prefix/suffix construction to use a
chars
iterator.I wasn't sure on how/where to add tests for this, as this code is only run as part of
cargo-insta
, and the existing tests seem to only check the snapshot generation/equivalency, rather than inline application.Supporting are two action runs, before and after this change:
I've also tested locally on that repository and the patch is applied correctly (i.e. without duplicated parts of the previous snapshot in the suffix, as was happening for me and as described in #42 previously).