rust-analyzer / expect-test

Minimalistic snapshot testing for Rust.
Apache License 2.0
248 stars 22 forks source link

Use the minimal number of escapes when updating tests #28

Closed ecstatic-morse closed 2 years ago

ecstatic-morse commented 2 years ago

Currently, expect-test uses a raw string with at least one hash when blessing tests. This is a bit verbose for single-line output that doesn't contain any quotes or escaped characters.

This PR parses each patch to find the simplest string literal that can represent it losslessly, and uses that instead. For now, multiline patches continue to use raw string literals (with the minimum number of hashes), although I think they could use regular ones.

matklad commented 2 years ago

Yeah, we intentionally didn't pick the simplest literal -- the benefit of using r#" everywhere is consistency. But I also agree that this is unfortunate for single-line expects. I think the logic we want here is:

ecstatic-morse commented 2 years ago

Updated version uses StrLitKind::Raw(1 /*hash*/) instead of StrLitKind::Raw(0) for patches containing newlines or backslash escapes.

bors[bot] commented 2 years ago

Build succeeded: