diff options
author | 2023-07-30 10:17:02 +0200 | |
---|---|---|
committer | 2023-07-30 01:17:02 -0700 | |
commit | 40a9ba63409694443058f558df2e480a8f16ff54 (patch) | |
tree | 9f9dc46fa5cff3da8abeeeed37562c0aeaa77159 /src | |
parent | 681be10294c19b8ce402ec44df5cd6554e2c86c0 (diff) | |
download | bun-40a9ba63409694443058f558df2e480a8f16ff54.tar.gz bun-40a9ba63409694443058f558df2e480a8f16ff54.tar.zst bun-40a9ba63409694443058f558df2e480a8f16ff54.zip |
Improv. (#3885)
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/test/expect.zig | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 07fbca03c..c56818efc 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -28,6 +28,17 @@ pub const Counter = struct { actual: u32 = 0, }; +const JSTypeOfMap = bun.ComptimeStringMap([]const u8, .{ + .{ "function", "function" }, + .{ "object", "object" }, + .{ "bigint", "bigint" }, + .{ "boolean", "boolean" }, + .{ "number", "number" }, + .{ "string", "string" }, + .{ "symbol", "symbol" }, + .{ "undefined", "undefined" }, +}); + pub var active_test_expectation_counter: Counter = .{}; /// https://jestjs.io/docs/expect @@ -316,7 +327,7 @@ pub const Expect = struct { } else { _msg = ZigString.fromBytes("passes by .pass() assertion"); } - + active_test_expectation_counter.actual += 1; const not = this.flags.not; @@ -364,12 +375,12 @@ pub const Expect = struct { globalObject.throwInvalidArgumentType("fail", "message", "string"); return .zero; } - + value.toZigString(&_msg, globalObject); } else { _msg = ZigString.fromBytes("fails by .fail() assertion"); } - + active_test_expectation_counter.actual += 1; const not = this.flags.not; @@ -2317,15 +2328,7 @@ pub const Expect = struct { return .zero; } - if (!std.mem.eql(u8, expectedAsStr, "function") and - !std.mem.eql(u8, expectedAsStr, "object") and - !std.mem.eql(u8, expectedAsStr, "bigint") and - !std.mem.eql(u8, expectedAsStr, "boolean") and - !std.mem.eql(u8, expectedAsStr, "number") and - !std.mem.eql(u8, expectedAsStr, "string") and - !std.mem.eql(u8, expectedAsStr, "symbol") and - !std.mem.eql(u8, expectedAsStr, "undefined")) - { + if (!JSTypeOfMap.has(expectedAsStr)) { globalThis.throwInvalidArguments("toBeTypeOf() requires a valid type string argument ('function', 'object', 'bigint', 'boolean', 'number', 'string', 'symbol', 'undefined')", .{}); return .zero; } @@ -2356,7 +2359,7 @@ pub const Expect = struct { return .zero; } - pass = std.mem.eql(u8, expectedAsStr, whatIsTheType); + pass = strings.eql(expectedAsStr, whatIsTheType); if (not) pass = !pass; if (pass) return thisValue; |