diff options
author | 2023-02-22 13:55:42 -0800 | |
---|---|---|
committer | 2023-02-22 13:55:42 -0800 | |
commit | 424045835c9e5cbaa02111fcbfeee7c3b5781e4a (patch) | |
tree | aeba7d1eb1471de7c6a046e4a1930bb864fcd0fe | |
parent | e8c9c644cae8793e1eeb241168c6c10fb7d3fb37 (diff) | |
download | bun-424045835c9e5cbaa02111fcbfeee7c3b5781e4a.tar.gz bun-424045835c9e5cbaa02111fcbfeee7c3b5781e4a.tar.zst bun-424045835c9e5cbaa02111fcbfeee7c3b5781e4a.zip |
wiptest -> test (#2131)
* +/- for object diff, quote more strings
* wiptest -> test
* quote strings fix
-rw-r--r-- | src/bun.js/api/bun.zig | 1 | ||||
-rw-r--r-- | src/bun.js/bindings/exports.zig | 6 | ||||
-rw-r--r-- | src/bun.js/test/jest.zig | 112 | ||||
-rw-r--r-- | src/cli.zig | 2 | ||||
-rw-r--r-- | src/cli/test_command.zig | 9 |
5 files changed, 97 insertions, 33 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index 0e17d089f..f979472dc 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -247,7 +247,6 @@ pub fn inspect( false, false, false, - false, ); buffered_writer.flush() catch { return JSC.C.JSValueMakeUndefined(ctx); diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index aeced9a69..1d4c01778 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -968,7 +968,6 @@ pub const ZigConsoleClient = struct { true, true, false, - false, ) else if (message_type == .Log) { _ = console.writer.write("\n") catch 0; @@ -1018,7 +1017,6 @@ pub const ZigConsoleClient = struct { add_newline: bool, flush: bool, order_properties: bool, - quote_strings: bool, ) void { var fmt: ZigConsoleClient.Formatter = undefined; defer { @@ -1034,7 +1032,6 @@ pub const ZigConsoleClient = struct { .remaining_values = &[_]JSValue{}, .globalThis = global, .ordered_properties = order_properties, - .quote_strings = quote_strings, }; const tag = ZigConsoleClient.Formatter.Tag.get(vals[0], global); @@ -1112,7 +1109,6 @@ pub const ZigConsoleClient = struct { .remaining_values = vals[0..len][1..], .globalThis = global, .ordered_properties = order_properties, - .quote_strings = quote_strings, }; var tag: ZigConsoleClient.Formatter.Tag.Result = undefined; @@ -1893,6 +1889,7 @@ pub const ZigConsoleClient = struct { writer.print(comptime Output.prettyFmt("<r><red>", enable_ansi_colors), .{}); } + if (jsType != .RegExpObject) writer.writeAll("\""); if (str.is16Bit()) { // streaming print writer.print("{s}", .{str}); @@ -1907,6 +1904,7 @@ pub const ZigConsoleClient = struct { writer.writeAll(buf); } } + if (jsType != .RegExpObject) writer.writeAll("\""); if (jsType == .RegExpObject and enable_ansi_colors) { writer.print(comptime Output.prettyFmt("<r>", enable_ansi_colors), .{}); diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 90c595037..41d7d41f7 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -96,7 +96,6 @@ pub const DiffFormatter = struct { false, false, true, - true, ); buffered_writer.flush() catch unreachable; @@ -114,7 +113,6 @@ pub const DiffFormatter = struct { false, false, true, - true, ); buffered_writer.flush() catch unreachable; } @@ -132,14 +130,10 @@ pub const DiffFormatter = struct { return; } - const equal_fmt = "<d>{s}<r>"; - const delete_fmt = "<red>{s}<r>"; - const insert_fmt = "<green>{s}<r>"; - switch (this.received.determineDiffMethod(this.expected, this.globalObject)) { .none => { const fmt = "Expected: <green>{any}<r>\nReceived: <red>{any}<r>"; - var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = this.globalObject, .quote_strings = true }; + var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = this.globalObject }; if (Output.enable_ansi_colors) { try writer.print(Output.prettyFmt(fmt, true), .{ this.expected.toFmt(this.globalObject, &formatter), @@ -160,21 +154,49 @@ pub const DiffFormatter = struct { var diffs = try dmp.diff(default_allocator, received_slice, expected_slice, false); defer diffs.deinit(default_allocator); - try writer.writeAll(Output.prettyFmt("Expected: ", true)); + const equal_fmt = "<d>{s}<r>"; + const delete_fmt = "<red>{s}<r>"; + const insert_fmt = "<green>{s}<r>"; + + try writer.writeAll("Expected: "); for (diffs.items) |df| { switch (df.operation) { .delete => continue, - .insert => try writer.print(Output.prettyFmt(insert_fmt, true), .{df.text}), - .equal => try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text}), + .insert => { + if (Output.enable_ansi_colors) { + try writer.print(Output.prettyFmt(insert_fmt, true), .{df.text}); + } else { + try writer.print(Output.prettyFmt(insert_fmt, false), .{df.text}); + } + }, + .equal => { + if (Output.enable_ansi_colors) { + try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text}); + } else { + try writer.print(Output.prettyFmt(equal_fmt, false), .{df.text}); + } + }, } } - try writer.writeAll(Output.prettyFmt("\nReceived: ", true)); + try writer.writeAll("\nReceived: "); for (diffs.items) |df| { switch (df.operation) { .insert => continue, - .delete => try writer.print(Output.prettyFmt(delete_fmt, true), .{df.text}), - .equal => try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text}), + .delete => { + if (Output.enable_ansi_colors) { + try writer.print(Output.prettyFmt(delete_fmt, true), .{df.text}); + } else { + try writer.print(Output.prettyFmt(delete_fmt, false), .{df.text}); + } + }, + .equal => { + if (Output.enable_ansi_colors) { + try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text}); + } else { + try writer.print(Output.prettyFmt(equal_fmt, false), .{df.text}); + } + }, } } return; @@ -185,34 +207,74 @@ pub const DiffFormatter = struct { var diffs = try dmp.diffLines(default_allocator, received_slice, expected_slice); defer diffs.deinit(default_allocator); + const equal_fmt = "<d> {s}<r>"; + const delete_fmt = "<red>+ {s}<r>"; + const insert_fmt = "<green>- {s}<r>"; + var insert_count: usize = 0; var delete_count: usize = 0; for (diffs.items) |df| { + var prev: usize = 0; + var curr: usize = 0; switch (df.operation) { .equal => { - try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text}); + while (curr < df.text.len) { + if (curr == df.text.len - 1 or df.text[curr] == '\n' and curr != 0) { + if (Output.enable_ansi_colors) { + try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text[prev .. curr + 1]}); + } else { + try writer.print(Output.prettyFmt(equal_fmt, false), .{df.text[prev .. curr + 1]}); + } + prev = curr + 1; + } + curr += 1; + } }, .insert => { - for (df.text) |c| { - if (c == '\n') insert_count += 1; + while (curr < df.text.len) { + if (curr == df.text.len - 1 or df.text[curr] == '\n' and curr != 0) { + insert_count += 1; + if (Output.enable_ansi_colors) { + try writer.print(Output.prettyFmt(insert_fmt, true), .{df.text[prev .. curr + 1]}); + } else { + try writer.print(Output.prettyFmt(insert_fmt, false), .{df.text[prev .. curr + 1]}); + } + prev = curr + 1; + } + curr += 1; } - try writer.print(Output.prettyFmt(insert_fmt, true), .{df.text}); }, .delete => { - for (df.text) |c| { - if (c == '\n') delete_count += 1; + while (curr < df.text.len) { + if (curr == df.text.len - 1 or df.text[curr] == '\n' and curr != 0) { + delete_count += 1; + if (Output.enable_ansi_colors) { + try writer.print(Output.prettyFmt(delete_fmt, true), .{df.text[prev .. curr + 1]}); + } else { + try writer.print(Output.prettyFmt(delete_fmt, false), .{df.text[prev .. curr + 1]}); + } + prev = curr + 1; + } + curr += 1; } - try writer.print(Output.prettyFmt(delete_fmt, true), .{df.text}); }, } } - try writer.print(Output.prettyFmt("\n\n<green>- Expected - {d}<r>\n", true), .{insert_count}); - try writer.print(Output.prettyFmt("<red>+ Received + {d}<r>", true), .{delete_count}); + if (Output.enable_ansi_colors) { + try writer.print(Output.prettyFmt("\n\n<green>- Expected - {d}<r>\n", true), .{insert_count}); + try writer.print(Output.prettyFmt("<red>+ Received + {d}<r>", true), .{delete_count}); + return; + } + try writer.print("\n\n- Expected - {d}\n", .{insert_count}); + try writer.print("+ Received + {d}", .{delete_count}); return; }, - .word => {}, + .word => { + // not implemented + // https://github.com/google/diff-match-patch/wiki/Line-or-Word-Diffs#word-mode + }, } return; } @@ -502,7 +564,7 @@ pub const Expect = struct { if (pass) return thisValue; // handle failure - var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject, .quote_strings = true }; + var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject }; if (not) { const signature = comptime getSignature("toBe", "<green>expected<r>", true); const fmt = signature ++ "\n\nExpected: not <green>{any}<r>\n"; @@ -1191,7 +1253,7 @@ pub const Expect = struct { if (pass) return thisValue; // handle failure - var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject, .quote_strings = true }; + var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject }; if (not) { if (expected_property != null) { const signature = comptime getSignature("toHaveProperty", "<green>path<r><d>, <r><green>value<r>", true); diff --git a/src/cli.zig b/src/cli.zig index 5b0b47edd..c9daad5b5 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -938,7 +938,7 @@ pub const Command = struct { }, RootCommandMatcher.case("c"), RootCommandMatcher.case("create") => .CreateCommand, - RootCommandMatcher.case(TestCommand.name) => .TestCommand, + RootCommandMatcher.case(TestCommand.name), RootCommandMatcher.case(TestCommand.old_name) => .TestCommand, RootCommandMatcher.case("pm") => .PackageManagerCommand, diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index 2b0f82bbd..f5760dfea 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -342,11 +342,16 @@ const Scanner = struct { }; pub const TestCommand = struct { - pub const name = "wiptest"; + pub const name = "test"; + pub const old_name = "wiptest"; pub fn exec(ctx: Command.Context) !void { if (comptime is_bindgen) unreachable; // print the version so you know its doing stuff if it takes a sec - Output.prettyErrorln("<r><b>bun wiptest <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{}); + if (strings.eqlComptime(ctx.positionals[0], old_name)) { + Output.prettyErrorln("<r><b>bun wiptest <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{}); + } else { + Output.prettyErrorln("<r><b>bun test <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{}); + } Output.flush(); var env_loader = brk: { |