mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
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:
@@ -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..] };
|
||||
|
||||
@@ -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(`
|
||||
|
||||
Reference in New Issue
Block a user