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
Escaped characters detection in literals #231
Escaped characters detection in literals #231
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow @ferranpujolcamins, you took this to the next level!
This is looking really good! I cloned your branch and played around with it and it feels very slick! 😄 Just a few small comments.
Known issue: AssertInlineSnapshot still searches only for "" and multiline string literals (it does not search #""" """# for example)
One interesting side effect is that it'll automatically insert more #
s than are needed when re-recording. Do you think you'll have time to address this soon?
I'm giving it a try |
I managed to make it work. Not without pain! Substrings are tricky. Mutating self in |
Hey @ferranpujolcamins! Looks like we're close but not quite there yet. If you run the following test block: func testAny() {
struct User { let id: Int, name: String, bio: String }
let user = User(id: 1, name: ##"Bl#""#obby"##, bio: "Blobbed around the world.")
assertSnapshot(matching: user, as: .dump)
_assertInlineSnapshot(matching: user, as: .dump, with: #####"""
"""#####)
} The leading The logic you're building on is definitely the most complicated part of the lib, sorry! Let us know if we can help in any way. |
I see! This won't be an easy change after all. Let's do this: After that, we can keep working on this one. |
Would be cool to add swift-prelude as dependency? |
Mmmm I see it depends on this package so we can't use it here :( |
Ok, I've rebased onto master. The tests work as follows (it's a little bit confusing): The recorded snapshots, are in turn well formed tests that are added to the test target.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really fun stuff! @mbrandonw and I looked over it today and would love to help you land it in any way possible. The subject of the PR is still a "WIP" and you mention that you still have some things you wanted to work on. Can you let us know what they are and how we can unblock you?
assertSnapshot(source: newSource, diffable: diffable) | ||
} | ||
|
||
// TODO: add more tests like this with different amount of lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanna flag this before merging.
} | ||
} | ||
|
||
// Class that is extended with the generated code to check that it builds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff!
Yeah I just added a couple of tests. Should be ready to merge. If we find some corner case later let's add a regression test! Thanks guys! |
Gentle ping ;) |
Beautiful work! This'll eliminate a major gotcha for folks. Thanks again for contributing! |
Thank you guys for working on this useful project! |
Followup of #228, Fixes #230
This PR fixes inline snapshot tests containing special characters. AssertInlineSnapshot now checks whether the snapshot contains special characters or not. If it does, escapes the snapshot literal appropriately.
Known issue: AssertInlineSnapshot still searches only for "" and multiline string literals (it does not search #""" """# for example)