Fix inline snapshot whitespace matching bug (#19564)

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
This commit is contained in:
pfg
2025-05-09 15:37:30 -07:00
committed by GitHub
parent de487713ed
commit a4bc1c8a35
2 changed files with 16 additions and 1 deletions

View File

@@ -2765,7 +2765,7 @@ pub const Expect = struct {
}
}
const end_indent = if (std.mem.lastIndexOfScalar(u8, str_in, '\n')) |c| c + 1 else return give_up_2; // there has to have been at least a single newline to get here
for (str_in[end_indent..]) |c| if (c != ' ' and c != 't') return give_up_2; // we already checked, but the last line is not all whitespace again
for (str_in[end_indent..]) |c| if (c != ' ' and c != '\t') return give_up_2; // we already checked, but the last line is not all whitespace again
// done
return .{ .trimmed = trimmed_buf[0 .. trimmed_buf.len - dst.len], .start_indent = indent_str, .end_indent = str_in[end_indent..] };

View File

@@ -847,6 +847,21 @@ indentation"
`,
);
});
it("#16403", () => {
tester.test(v =>
v(
'\tit(\'should get range of notes\', () => {\n\t\tconst range = ["C2", "B2"];\n\n\t\texpect(range).toMatchInlineSnapshot();\n\t});\n',
'\tit(\'should get range of notes\', () => {\n\t\tconst range = ["C2", "B2"];\n\n\t\texpect(range).toMatchInlineSnapshot(`\n\t\t [\n\t\t "ab",\n\t\t "cd",\n\t\t ]\n\t\t`);\n\t});\n',
'\tit(\'should get range of notes\', () => {\n\t\tconst range = ["C2", "B2"];\n\n\t\texpect(range).toMatchInlineSnapshot(`\n\t\t [\n\t\t "C2",\n\t\t "B2",\n\t\t ]\n\t\t`);\n\t});\n',
),
);
tester.testUpdateOnly(v =>
v(
'\tit(\'should get range of notes\', () => {\n\t\tconst range = ["C2", "B2"];\n\n\t\texpect(range).toMatchInlineSnapshot(`\n\t\t\t[\n\t\t\t "ab",\n\t\t\t "cd",\n\t\t\t]\n\t\t`);\n\t});\n',
'\tit(\'should get range of notes\', () => {\n\t\tconst range = ["C2", "B2"];\n\n\t\texpect(range).toMatchInlineSnapshot(`\n\t\t\t[\n\t\t\t "C2",\n\t\t\t "B2",\n\t\t\t]\n\t\t`);\n\t});\n',
),
);
});
});
test("indented inline snapshots", () => {
expect("a\nb").toMatchInlineSnapshot(`