Closed ecstatic-morse closed 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:
expect!["foo"]
expect![[r#"foo"#]]
Updated version uses StrLitKind::Raw(1 /*hash*/)
instead of StrLitKind::Raw(0)
for patches containing newlines or backslash escapes.
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.