diff --git a/src/ArenaAllocator.zig b/src/ArenaAllocator.zig index c059626a69..fcc99ea15a 100644 --- a/src/ArenaAllocator.zig +++ b/src/ArenaAllocator.zig @@ -245,42 +245,3 @@ pub const ArenaAllocator = struct { } } }; - -test "ArenaAllocator (reset with preheating)" { - var arena_allocator = ArenaAllocator.init(std.testing.allocator); - defer arena_allocator.deinit(); - // provides some variance in the allocated data - var rng_src = std.rand.DefaultPrng.init(19930913); - const random = rng_src.random(); - var rounds: usize = 25; - while (rounds > 0) { - rounds -= 1; - _ = arena_allocator.reset(.retain_capacity); - var alloced_bytes: usize = 0; - const total_size: usize = random.intRangeAtMost(usize, 256, 16384); - while (alloced_bytes < total_size) { - const size = random.intRangeAtMost(usize, 16, 256); - const alignment = 32; - const slice = try arena_allocator.allocator().alignedAlloc(u8, alignment, size); - try std.testing.expect(std.mem.isAligned(@intFromPtr(slice.ptr), alignment)); - try std.testing.expectEqual(size, slice.len); - alloced_bytes += slice.len; - } - } -} - -test "ArenaAllocator (reset while retaining a buffer)" { - var arena_allocator = ArenaAllocator.init(std.testing.allocator); - defer arena_allocator.deinit(); - const a = arena_allocator.allocator(); - - // Create two internal buffers - _ = try a.alloc(u8, 1); - _ = try a.alloc(u8, 1000); - - // Check that we have at least two buffers - try std.testing.expect(arena_allocator.state.buffer_list.first.?.next != null); - - // This retains the first allocated buffer - try std.testing.expect(arena_allocator.reset(.{ .retain_with_limit = 1 })); -} diff --git a/src/ast/base.zig b/src/ast/base.zig index d9bcda83d3..738ac64255 100644 --- a/src/ast/base.zig +++ b/src/ast/base.zig @@ -289,37 +289,3 @@ pub const Ref = packed struct(u64) { return try writer.write([2]u32{ self.sourceIndex(), self.innerIndex() }); } }; - -test "Ref" { - { - const first = .{ .inner_index = 0, .source_index = 1, .is_source_contents_slice = true }; - const ref = Ref.initSourceEnd(.{ .inner_index = 0, .source_index = 1, .is_source_contents_slice = true }); - try std.testing.expectEqual(ref.innerIndex(), first.inner_index); - try std.testing.expectEqual(ref.sourceIndex(), first.source_index); - try std.testing.expectEqual(ref.isSourceContentsSlice(), first.is_source_contents_slice); - } - - { - const first = .{ .inner_index = 100, .source_index = 0, .is_source_contents_slice = true }; - const ref = Ref.initSourceEnd(.{ .inner_index = 100, .source_index = 0, .is_source_contents_slice = true }); - try std.testing.expectEqual(ref.innerIndex(), first.inner_index); - try std.testing.expectEqual(ref.sourceIndex(), first.source_index); - try std.testing.expectEqual(ref.isSourceContentsSlice(), first.is_source_contents_slice); - } - - { - const first = .{ .inner_index = 20, .source_index = 100, .is_source_contents_slice = true }; - const ref = Ref.initSourceEnd(.{ .inner_index = 20, .source_index = 100, .is_source_contents_slice = true }); - try std.testing.expectEqual(ref.innerIndex(), first.inner_index); - try std.testing.expectEqual(ref.sourceIndex(), first.source_index); - try std.testing.expectEqual(ref.isSourceContentsSlice(), first.is_source_contents_slice); - } - - { - const first = .{ .inner_index = 30, .source_index = 100, .is_source_contents_slice = false }; - const ref = Ref.initSourceEnd(.{ .inner_index = 30, .source_index = 100, .is_source_contents_slice = false }); - try std.testing.expectEqual(ref.innerIndex(), first.inner_index); - try std.testing.expectEqual(ref.sourceIndex(), first.source_index); - try std.testing.expectEqual(ref.isSourceContentsSlice(), first.is_source_contents_slice); - } -} diff --git a/src/base64/base64.zig b/src/base64/base64.zig index 8345350969..8a495c8775 100644 --- a/src/base64/base64.zig +++ b/src/base64/base64.zig @@ -401,18 +401,6 @@ const zig_base64 = struct { } }; - test "base64" { - @setEvalBranchQuota(8000); - try testBase64(); - comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU="); - } - - test "base64 url_safe_no_pad" { - @setEvalBranchQuota(8000); - try testBase64UrlSafeNoPad(); - comptime try testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU"); - } - fn testBase64() !void { const codecs = standard; diff --git a/src/bit_set.zig b/src/bit_set.zig index 7279456277..1f2fc4681c 100644 --- a/src/bit_set.zig +++ b/src/bit_set.zig @@ -1895,124 +1895,3 @@ fn testStaticBitSet(comptime Set: type, comptime Container: @Type(.EnumLiteral)) try testPureBitSet(Set); } - -test "IntegerBitSet" { - try testStaticBitSet(IntegerBitSet(0), .IntegerBitSet); - try testStaticBitSet(IntegerBitSet(1), .IntegerBitSet); - try testStaticBitSet(IntegerBitSet(2), .IntegerBitSet); - try testStaticBitSet(IntegerBitSet(5), .IntegerBitSet); - try testStaticBitSet(IntegerBitSet(8), .IntegerBitSet); - try testStaticBitSet(IntegerBitSet(32), .IntegerBitSet); - try testStaticBitSet(IntegerBitSet(64), .IntegerBitSet); - try testStaticBitSet(IntegerBitSet(127), .IntegerBitSet); -} - -test "ArrayBitSet" { - inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| { - try testStaticBitSet(ArrayBitSet(u8, size), .ArrayBitSet); - try testStaticBitSet(ArrayBitSet(u16, size), .ArrayBitSet); - try testStaticBitSet(ArrayBitSet(u32, size), .ArrayBitSet); - try testStaticBitSet(ArrayBitSet(u64, size), .ArrayBitSet); - try testStaticBitSet(ArrayBitSet(u128, size), .ArrayBitSet); - } -} - -test "DynamicBitSetUnmanaged" { - const allocator = std.testing.allocator; - var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300); - try testing.expectEqual(@as(usize, 0), a.count()); - a.deinit(allocator); - - a = try DynamicBitSetUnmanaged.initEmpty(allocator, 0); - defer a.deinit(allocator); - for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| { - const old_len = a.capacity(); - - var empty = try a.clone(allocator); - defer empty.deinit(allocator); - try testing.expectEqual(old_len, empty.capacity()); - for (0..old_len) |i| { - try testing.expectEqual(a.isSet(i), empty.isSet(i)); - } - - a.toggleSet(a); // zero a - empty.toggleSet(empty); - - try a.resize(allocator, size, true); - try empty.resize(allocator, size, false); - - if (size > old_len) { - try testing.expectEqual(size - old_len, a.count()); - } else { - try testing.expectEqual(@as(usize, 0), a.count()); - } - try testing.expectEqual(@as(usize, 0), empty.count()); - - var full = try DynamicBitSetUnmanaged.initFull(allocator, size); - defer full.deinit(allocator); - try testing.expectEqual(@as(usize, size), full.count()); - - try testEql(empty, full, size); - { - var even = try DynamicBitSetUnmanaged.initEmpty(allocator, size); - defer even.deinit(allocator); - fillEven(&even, size); - - var odd = try DynamicBitSetUnmanaged.initEmpty(allocator, size); - defer odd.deinit(allocator); - fillOdd(&odd, size); - - try testSubsetOf(empty, full, even, odd, size); - try testSupersetOf(empty, full, even, odd, size); - } - try testBitSet(&a, &full, size); - } -} - -test "DynamicBitSet" { - const allocator = std.testing.allocator; - var a = try DynamicBitSet.initEmpty(allocator, 300); - try testing.expectEqual(@as(usize, 0), a.count()); - a.deinit(); - - a = try DynamicBitSet.initEmpty(allocator, 0); - defer a.deinit(); - for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| { - const old_len = a.capacity(); - - var tmp = try a.clone(allocator); - defer tmp.deinit(); - try testing.expectEqual(old_len, tmp.capacity()); - for (0..old_len) |i| { - try testing.expectEqual(a.isSet(i), tmp.isSet(i)); - } - - a.toggleSet(a); // zero a - tmp.toggleSet(tmp); // zero tmp - - try a.resize(size, true); - try tmp.resize(size, false); - - if (size > old_len) { - try testing.expectEqual(size - old_len, a.count()); - } else { - try testing.expectEqual(@as(usize, 0), a.count()); - } - try testing.expectEqual(@as(usize, 0), tmp.count()); - - var b = try DynamicBitSet.initFull(allocator, size); - defer b.deinit(); - try testing.expectEqual(@as(usize, size), b.count()); - - try testEql(tmp, b, size); - try testBitSet(&a, &b, size); - } -} - -test "StaticBitSet" { - try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0)); - try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5)); - try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize))); - try testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1)); - try testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500)); -} diff --git a/src/boringssl.zig b/src/boringssl.zig index de03293d31..dce10b3d1d 100644 --- a/src/boringssl.zig +++ b/src/boringssl.zig @@ -206,7 +206,3 @@ pub fn checkServerIdentity( } return false; } - -test "load" { - load(); -} diff --git a/src/bun.js/node/node_os.zig b/src/bun.js/node/node_os.zig index 800cad45ac..9cb4b6bc57 100644 --- a/src/bun.js/node/node_os.zig +++ b/src/bun.js/node/node_os.zig @@ -875,44 +875,3 @@ fn netmaskToCIDRSuffix(mask: anytype) ?u8 { if (first_zero < @bitSizeOf(T) and first_zero < last_one) return null; return first_zero; } -test "netmaskToCIDRSuffix" { - const ipv4_tests = .{ - .{ "255.255.255.255", 32 }, - .{ "255.255.255.254", 31 }, - .{ "255.255.255.252", 30 }, - .{ "255.255.255.128", 25 }, - .{ "255.255.255.0", 24 }, - .{ "255.255.128.0", 17 }, - .{ "255.255.0.0", 16 }, - .{ "255.128.0.0", 9 }, - .{ "255.0.0.0", 8 }, - .{ "224.0.0.0", 3 }, - .{ "192.0.0.0", 2 }, - .{ "128.0.0.0", 1 }, - .{ "0.0.0.0", 0 }, - - // invalid masks - .{ "255.0.0.255", null }, - .{ "128.0.0.255", null }, - .{ "128.0.0.1", null }, - }; - inline for (ipv4_tests) |t| { - const addr = try std.net.Address.parseIp4(t[0], 0); - try std.testing.expectEqual(@as(?u8, t[1]), netmaskToCIDRSuffix(addr.in.sa.addr)); - } - - const ipv6_tests = .{ - .{ "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128 }, - .{ "ffff:ffff:ffff:ffff::", 64 }, - .{ "::", 0 }, - - // invalid masks - .{ "ff00:1::", null }, - .{ "0:1::", null }, - }; - inline for (ipv6_tests) |t| { - const addr = try std.net.Address.parseIp6(t[0], 0); - const bits = @as(u128, @bitCast(addr.in6.sa.addr)); - try std.testing.expectEqual(@as(?u8, t[1]), netmaskToCIDRSuffix(bits)); - } -} diff --git a/src/cli/add_completions.zig b/src/cli/add_completions.zig index 1267ea1592..53ba3bfbef 100644 --- a/src/cli/add_completions.zig +++ b/src/cli/add_completions.zig @@ -84,16 +84,3 @@ pub const biggest_list: usize = brk: { }; const index_blob = "add_completions.index.blob"; - -test "entries" { - const items = index.get(FirstLetter.r); - var found_react = false; - for (items) |item| { - try std.testing.expectEqual(item[0], 'r'); - if (std.mem.eql(u8, item, "react")) { - found_react = true; - } - } - - try std.testing.expect(found_react); -} diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 4ac070822c..e05fa56f0b 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -1725,109 +1725,3 @@ pub const BunXFastPath = struct { }; } }; - -test "replacePackageManagerRun" { - var copy_script = std.ArrayList(u8).init(default_allocator); - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "yarn run foo"); - try std.testing.expectEqualStrings(copy_script.items, "bun run foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "yarn install foo"); - try std.testing.expectEqualStrings(copy_script.items, "yarn install foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "yarn --prod"); - try std.testing.expectEqualStrings(copy_script.items, "yarn --prod"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "yarn -prod"); - try std.testing.expectEqualStrings(copy_script.items, "yarn -prod"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "yarn"); - try std.testing.expectEqualStrings(copy_script.items, "yarn"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "yarn "); - try std.testing.expectEqualStrings(copy_script.items, "yarn "); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "npm "); - try std.testing.expectEqualStrings(copy_script.items, "npm "); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "npm bacon run"); - try std.testing.expectEqualStrings(copy_script.items, "npm bacon run"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "yarn bacon foo"); - try std.testing.expectEqualStrings(copy_script.items, "bun run bacon foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "yarn npm run foo"); - try std.testing.expectEqualStrings(copy_script.items, "yarn npm run foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "npm run foo"); - try std.testing.expectEqualStrings(copy_script.items, "bun run foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "bpm run foo"); - try std.testing.expectEqualStrings(copy_script.items, "bpm run foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "pnpm run foo"); - try std.testing.expectEqualStrings(copy_script.items, "bun run foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "foopnpm run foo"); - try std.testing.expectEqualStrings(copy_script.items, "foopnpm run foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "foopnpm rune foo"); - try std.testing.expectEqualStrings(copy_script.items, "foopnpm rune foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "foopnpm ru foo"); - try std.testing.expectEqualStrings(copy_script.items, "foopnpm ru foo"); - } - - { - copy_script.clearRetainingCapacity(); - try RunCommand.replacePackageManagerRun(©_script, "'npm run foo'"); - try std.testing.expectEqualStrings(copy_script.items, "'bun run foo'"); - } -} diff --git a/src/defines.zig b/src/defines.zig index 4c1071f548..1da7bd9386 100644 --- a/src/defines.zig +++ b/src/defines.zig @@ -308,20 +308,3 @@ pub const Define = struct { }; const expect = std.testing.expect; -test "UserDefines" { - js_ast.Stmt.Data.Store.create(default_allocator); - js_ast.Expr.Data.Store.create(default_allocator); - var orig = RawDefines.init(default_allocator); - try orig.put("process.env.NODE_ENV", "\"development\""); - try orig.put("globalThis", "window"); - var log = logger.Log.init(default_allocator); - var data = try DefineData.from_input(orig, &log, default_allocator); - - try expect(data.contains("process.env.NODE_ENV")); - try expect(data.contains("globalThis")); - const globalThis = data.get("globalThis"); - const val = data.get("process.env.NODE_ENV"); - try expect(val != null); - try expect(val.?.value.e_string.eql([]const u8, "development")); - try std.testing.expectEqualStrings(globalThis.?.original_name.?, "window"); -} diff --git a/src/enums.zig b/src/enums.zig index bb0c8d8090..dd916f32a8 100644 --- a/src/enums.zig +++ b/src/enums.zig @@ -58,13 +58,6 @@ pub fn tagName(comptime E: type, e: E) ?[]const u8 { } else null; } -test tagName { - const E = enum(u8) { a, b, _ }; - try testing.expect(tagName(E, .a) != null); - try testing.expectEqualStrings("a", tagName(E, .a).?); - try testing.expect(tagName(E, @as(E, @enumFromInt(42))) == null); -} - /// Determines the length of a direct-mapped enum array, indexed by /// @intCast(usize, @intFromEnum(enum_value)). /// If the enum is non-exhaustive, the resulting length will only be enough @@ -121,21 +114,6 @@ pub fn directEnumArray( return directEnumArrayDefault(E, Data, null, max_unused_slots, init_values); } -test "std.enums.directEnumArray" { - const E = enum(i4) { a = 4, b = 6, c = 2 }; - const runtime_false: bool = false; - const array = directEnumArray(E, bool, 4, .{ - .a = true, - .b = runtime_false, - .c = true, - }); - - try testing.expectEqual([7]bool, @TypeOf(array)); - try testing.expectEqual(true, array[4]); - try testing.expectEqual(false, array[6]); - try testing.expectEqual(true, array[2]); -} - /// Initializes an array of Data which can be indexed by /// @intCast(usize, @intFromEnum(enum_value)). The enum must be exhaustive. /// If the enum contains any fields with values that cannot be represented @@ -163,34 +141,6 @@ pub fn directEnumArrayDefault( return result; } -test "std.enums.directEnumArrayDefault" { - const E = enum(i4) { a = 4, b = 6, c = 2 }; - const runtime_false: bool = false; - const array = directEnumArrayDefault(E, bool, false, 4, .{ - .a = true, - .b = runtime_false, - }); - - try testing.expectEqual([7]bool, @TypeOf(array)); - try testing.expectEqual(true, array[4]); - try testing.expectEqual(false, array[6]); - try testing.expectEqual(false, array[2]); -} - -test "std.enums.directEnumArrayDefault slice" { - const E = enum(i4) { a = 4, b = 6, c = 2 }; - const runtime_b = "b"; - const array = directEnumArrayDefault(E, []const u8, "default", 4, .{ - .a = "a", - .b = runtime_b, - }); - - try testing.expectEqual([7][]const u8, @TypeOf(array)); - try testing.expectEqualSlices(u8, "a", array[4]); - try testing.expectEqualSlices(u8, "b", array[6]); - try testing.expectEqualSlices(u8, "default", array[2]); -} - /// Cast an enum literal, value, or string to the enum value of type E /// with the same name. pub fn nameCast(comptime E: type, comptime value: anytype) E { @@ -212,28 +162,6 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E { }; } -test "std.enums.nameCast" { - const A = enum(u1) { a = 0, b = 1 }; - const B = enum(u1) { a = 1, b = 0 }; - try testing.expectEqual(A.a, nameCast(A, .a)); - try testing.expectEqual(A.a, nameCast(A, A.a)); - try testing.expectEqual(A.a, nameCast(A, B.a)); - try testing.expectEqual(A.a, nameCast(A, "a")); - try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a"))); - try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a"))); - try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a"))); - - try testing.expectEqual(B.a, nameCast(B, .a)); - try testing.expectEqual(B.a, nameCast(B, A.a)); - try testing.expectEqual(B.a, nameCast(B, B.a)); - try testing.expectEqual(B.a, nameCast(B, "a")); - - try testing.expectEqual(B.b, nameCast(B, .b)); - try testing.expectEqual(B.b, nameCast(B, A.b)); - try testing.expectEqual(B.b, nameCast(B, B.b)); - try testing.expectEqual(B.b, nameCast(B, "b")); -} - /// A set of enum elements, backed by a bitfield. If the enum /// is not dense, a mapping will be constructed from enum values /// to dense indices. This type does no dynamic allocation and @@ -510,210 +438,6 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type { }; } -test "EnumMultiset" { - const Ball = enum { red, green, blue }; - - const empty = EnumMultiset(Ball).initEmpty(); - const r0_g1_b2 = EnumMultiset(Ball).init(.{ - .red = 0, - .green = 1, - .blue = 2, - }); - const ten_of_each = EnumMultiset(Ball).initWithCount(10); - - try testing.expectEqual(empty.count(), 0); - try testing.expectEqual(r0_g1_b2.count(), 3); - try testing.expectEqual(ten_of_each.count(), 30); - - try testing.expect(!empty.contains(.red)); - try testing.expect(!empty.contains(.green)); - try testing.expect(!empty.contains(.blue)); - - try testing.expect(!r0_g1_b2.contains(.red)); - try testing.expect(r0_g1_b2.contains(.green)); - try testing.expect(r0_g1_b2.contains(.blue)); - - try testing.expect(ten_of_each.contains(.red)); - try testing.expect(ten_of_each.contains(.green)); - try testing.expect(ten_of_each.contains(.blue)); - - { - var copy = ten_of_each; - copy.removeAll(.red); - try testing.expect(!copy.contains(.red)); - - // removeAll second time does nothing - copy.removeAll(.red); - try testing.expect(!copy.contains(.red)); - } - - { - var copy = ten_of_each; - copy.addAssertSafe(.red, 6); - try testing.expectEqual(copy.getCount(.red), 16); - } - - { - var copy = ten_of_each; - try copy.add(.red, 6); - try testing.expectEqual(copy.getCount(.red), 16); - - try testing.expectError(error.Overflow, copy.add(.red, std.math.maxInt(usize))); - } - - { - var copy = ten_of_each; - copy.remove(.red, 4); - try testing.expectEqual(copy.getCount(.red), 6); - - // subtracting more it contains does not underflow - copy.remove(.green, 14); - try testing.expectEqual(copy.getCount(.green), 0); - } - - try testing.expectEqual(empty.getCount(.green), 0); - try testing.expectEqual(r0_g1_b2.getCount(.green), 1); - try testing.expectEqual(ten_of_each.getCount(.green), 10); - - { - var copy = empty; - copy.setCount(.red, 6); - try testing.expectEqual(copy.getCount(.red), 6); - } - - { - var copy = r0_g1_b2; - copy.addSetAssertSafe(ten_of_each); - try testing.expectEqual(copy.getCount(.red), 10); - try testing.expectEqual(copy.getCount(.green), 11); - try testing.expectEqual(copy.getCount(.blue), 12); - } - - { - var copy = r0_g1_b2; - try copy.addSet(ten_of_each); - try testing.expectEqual(copy.getCount(.red), 10); - try testing.expectEqual(copy.getCount(.green), 11); - try testing.expectEqual(copy.getCount(.blue), 12); - - const full = EnumMultiset(Ball).initWithCount(std.math.maxInt(usize)); - try testing.expectError(error.Overflow, copy.addSet(full)); - } - - { - var copy = ten_of_each; - copy.removeSet(r0_g1_b2); - try testing.expectEqual(copy.getCount(.red), 10); - try testing.expectEqual(copy.getCount(.green), 9); - try testing.expectEqual(copy.getCount(.blue), 8); - - copy.removeSet(ten_of_each); - try testing.expectEqual(copy.getCount(.red), 0); - try testing.expectEqual(copy.getCount(.green), 0); - try testing.expectEqual(copy.getCount(.blue), 0); - } - - try testing.expect(empty.eql(empty)); - try testing.expect(r0_g1_b2.eql(r0_g1_b2)); - try testing.expect(ten_of_each.eql(ten_of_each)); - try testing.expect(!empty.eql(r0_g1_b2)); - try testing.expect(!r0_g1_b2.eql(ten_of_each)); - try testing.expect(!ten_of_each.eql(empty)); - - try testing.expect(empty.subsetOf(empty)); - try testing.expect(r0_g1_b2.subsetOf(r0_g1_b2)); - try testing.expect(empty.subsetOf(r0_g1_b2)); - try testing.expect(r0_g1_b2.subsetOf(ten_of_each)); - try testing.expect(!ten_of_each.subsetOf(r0_g1_b2)); - try testing.expect(!r0_g1_b2.subsetOf(empty)); - - try testing.expect(empty.supersetOf(empty)); - try testing.expect(r0_g1_b2.supersetOf(r0_g1_b2)); - try testing.expect(r0_g1_b2.supersetOf(empty)); - try testing.expect(ten_of_each.supersetOf(r0_g1_b2)); - try testing.expect(!r0_g1_b2.supersetOf(ten_of_each)); - try testing.expect(!empty.supersetOf(r0_g1_b2)); - - { - // with multisets it could be the case where two - // multisets are neither subset nor superset of each - // other. - - const r10 = EnumMultiset(Ball).init(.{ - .red = 10, - }); - const b10 = EnumMultiset(Ball).init(.{ - .blue = 10, - }); - - try testing.expect(!r10.subsetOf(b10)); - try testing.expect(!b10.subsetOf(r10)); - try testing.expect(!r10.supersetOf(b10)); - try testing.expect(!b10.supersetOf(r10)); - } - - { - const result = r0_g1_b2.plusAssertSafe(ten_of_each); - try testing.expectEqual(result.getCount(.red), 10); - try testing.expectEqual(result.getCount(.green), 11); - try testing.expectEqual(result.getCount(.blue), 12); - } - - { - const result = try r0_g1_b2.plus(ten_of_each); - try testing.expectEqual(result.getCount(.red), 10); - try testing.expectEqual(result.getCount(.green), 11); - try testing.expectEqual(result.getCount(.blue), 12); - - const full = EnumMultiset(Ball).initWithCount(std.math.maxInt(usize)); - try testing.expectError(error.Overflow, result.plus(full)); - } - - { - const result = ten_of_each.minus(r0_g1_b2); - try testing.expectEqual(result.getCount(.red), 10); - try testing.expectEqual(result.getCount(.green), 9); - try testing.expectEqual(result.getCount(.blue), 8); - } - - { - const result = ten_of_each.minus(r0_g1_b2).minus(ten_of_each); - try testing.expectEqual(result.getCount(.red), 0); - try testing.expectEqual(result.getCount(.green), 0); - try testing.expectEqual(result.getCount(.blue), 0); - } - - { - var copy = empty; - var it = copy.iterator(); - var entry = it.next().?; - try testing.expectEqual(entry.key, .red); - try testing.expectEqual(entry.value.*, 0); - entry = it.next().?; - try testing.expectEqual(entry.key, .green); - try testing.expectEqual(entry.value.*, 0); - entry = it.next().?; - try testing.expectEqual(entry.key, .blue); - try testing.expectEqual(entry.value.*, 0); - try testing.expectEqual(it.next(), null); - } - - { - var copy = r0_g1_b2; - var it = copy.iterator(); - var entry = it.next().?; - try testing.expectEqual(entry.key, .red); - try testing.expectEqual(entry.value.*, 0); - entry = it.next().?; - try testing.expectEqual(entry.key, .green); - try testing.expectEqual(entry.value.*, 1); - entry = it.next().?; - try testing.expectEqual(entry.key, .blue); - try testing.expectEqual(entry.value.*, 2); - try testing.expectEqual(it.next(), null); - } -} - /// An array keyed by an enum, backed by a dense array. /// If the enum is not dense, a mapping will be constructed from /// enum values to dense indices. This type does no dynamic @@ -914,87 +638,6 @@ pub fn IndexedSet(comptime I: type, comptime Ext: ?fn (type) type) type { }; } -test "pure EnumSet fns" { - const Suit = enum { spades, hearts, clubs, diamonds }; - - const empty = EnumSet(Suit).initEmpty(); - const full = EnumSet(Suit).initFull(); - const black = EnumSet(Suit).initMany(&[_]Suit{ .spades, .clubs }); - const red = EnumSet(Suit).initMany(&[_]Suit{ .hearts, .diamonds }); - - try testing.expect(empty.eql(empty)); - try testing.expect(full.eql(full)); - try testing.expect(!empty.eql(full)); - try testing.expect(!full.eql(empty)); - try testing.expect(!empty.eql(black)); - try testing.expect(!full.eql(red)); - try testing.expect(!red.eql(empty)); - try testing.expect(!black.eql(full)); - - try testing.expect(empty.subsetOf(empty)); - try testing.expect(empty.subsetOf(full)); - try testing.expect(full.subsetOf(full)); - try testing.expect(!black.subsetOf(red)); - try testing.expect(!red.subsetOf(black)); - - try testing.expect(full.supersetOf(full)); - try testing.expect(full.supersetOf(empty)); - try testing.expect(empty.supersetOf(empty)); - try testing.expect(!black.supersetOf(red)); - try testing.expect(!red.supersetOf(black)); - - try testing.expect(empty.complement().eql(full)); - try testing.expect(full.complement().eql(empty)); - try testing.expect(black.complement().eql(red)); - try testing.expect(red.complement().eql(black)); - - try testing.expect(empty.unionWith(empty).eql(empty)); - try testing.expect(empty.unionWith(full).eql(full)); - try testing.expect(full.unionWith(full).eql(full)); - try testing.expect(full.unionWith(empty).eql(full)); - try testing.expect(black.unionWith(red).eql(full)); - try testing.expect(red.unionWith(black).eql(full)); - - try testing.expect(empty.intersectWith(empty).eql(empty)); - try testing.expect(empty.intersectWith(full).eql(empty)); - try testing.expect(full.intersectWith(full).eql(full)); - try testing.expect(full.intersectWith(empty).eql(empty)); - try testing.expect(black.intersectWith(red).eql(empty)); - try testing.expect(red.intersectWith(black).eql(empty)); - - try testing.expect(empty.xorWith(empty).eql(empty)); - try testing.expect(empty.xorWith(full).eql(full)); - try testing.expect(full.xorWith(full).eql(empty)); - try testing.expect(full.xorWith(empty).eql(full)); - try testing.expect(black.xorWith(red).eql(full)); - try testing.expect(red.xorWith(black).eql(full)); - - try testing.expect(empty.differenceWith(empty).eql(empty)); - try testing.expect(empty.differenceWith(full).eql(empty)); - try testing.expect(full.differenceWith(full).eql(empty)); - try testing.expect(full.differenceWith(empty).eql(full)); - try testing.expect(full.differenceWith(red).eql(black)); - try testing.expect(full.differenceWith(black).eql(red)); -} - -test "std.enums.EnumSet const iterator" { - const Direction = enum { up, down, left, right }; - const diag_move = init: { - var move = EnumSet(Direction).initEmpty(); - move.insert(.right); - move.insert(.up); - break :init move; - }; - - var result = EnumSet(Direction).initEmpty(); - var it = diag_move.iterator(); - while (it.next()) |dir| { - result.insert(dir); - } - - try testing.expect(result.eql(diag_move)); -} - /// A map from keys to values, using an index lookup. Uses a /// bitfield to track presence and a dense array of values. /// This type does no allocation and can be copied by value. @@ -1273,19 +916,6 @@ pub fn ensureIndexer(comptime T: type) void { } } -test "std.enums.ensureIndexer" { - ensureIndexer(struct { - pub const Key = u32; - pub const count: usize = 8; - pub fn indexOf(k: Key) usize { - return @as(usize, @intCast(k)); - } - pub fn keyForIndex(index: usize) Key { - return @as(Key, @intCast(index)); - } - }); -} - pub fn EnumIndexer(comptime E: type) type { if (!@typeInfo(E).Enum.is_exhaustive) { @compileError("Cannot create an enum indexer for a non-exhaustive enum."); @@ -1370,67 +1000,3 @@ pub fn EnumIndexer(comptime E: type) type { } }; } - -test "std.enums.EnumIndexer dense zeroed" { - const E = enum(u2) { b = 1, a = 0, c = 2 }; - const Indexer = EnumIndexer(E); - ensureIndexer(Indexer); - try testing.expectEqual(E, Indexer.Key); - try testing.expectEqual(@as(usize, 3), Indexer.count); - - try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); - try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); - try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); - - try testing.expectEqual(E.a, Indexer.keyForIndex(0)); - try testing.expectEqual(E.b, Indexer.keyForIndex(1)); - try testing.expectEqual(E.c, Indexer.keyForIndex(2)); -} - -test "std.enums.EnumIndexer dense positive" { - const E = enum(u4) { c = 6, a = 4, b = 5 }; - const Indexer = EnumIndexer(E); - ensureIndexer(Indexer); - try testing.expectEqual(E, Indexer.Key); - try testing.expectEqual(@as(usize, 3), Indexer.count); - - try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); - try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); - try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); - - try testing.expectEqual(E.a, Indexer.keyForIndex(0)); - try testing.expectEqual(E.b, Indexer.keyForIndex(1)); - try testing.expectEqual(E.c, Indexer.keyForIndex(2)); -} - -test "std.enums.EnumIndexer dense negative" { - const E = enum(i4) { a = -6, c = -4, b = -5 }; - const Indexer = EnumIndexer(E); - ensureIndexer(Indexer); - try testing.expectEqual(E, Indexer.Key); - try testing.expectEqual(@as(usize, 3), Indexer.count); - - try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); - try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); - try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); - - try testing.expectEqual(E.a, Indexer.keyForIndex(0)); - try testing.expectEqual(E.b, Indexer.keyForIndex(1)); - try testing.expectEqual(E.c, Indexer.keyForIndex(2)); -} - -test "std.enums.EnumIndexer sparse" { - const E = enum(i4) { a = -2, c = 6, b = 4 }; - const Indexer = EnumIndexer(E); - ensureIndexer(Indexer); - try testing.expectEqual(E, Indexer.Key); - try testing.expectEqual(@as(usize, 3), Indexer.count); - - try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); - try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); - try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); - - try testing.expectEqual(E.a, Indexer.keyForIndex(0)); - try testing.expectEqual(E.b, Indexer.keyForIndex(1)); - try testing.expectEqual(E.c, Indexer.keyForIndex(2)); -} diff --git a/src/env_loader.zig b/src/env_loader.zig index 7f2f04d20d..5a094a9d88 100644 --- a/src/env_loader.zig +++ b/src/env_loader.zig @@ -1253,196 +1253,5 @@ pub var instance: ?*Loader = null; const expectString = std.testing.expectEqualStrings; const expect = std.testing.expect; -test "DotEnv Loader - basic" { - const VALID_ENV = - \\API_KEY=verysecure - \\process.env.WAT=ABCDEFGHIJKLMNOPQRSTUVWXYZZ10239457123 - \\DOUBLE-QUOTED_SHOULD_PRESERVE_NEWLINES=" - \\ya - \\" - \\DOUBLE_QUOTES_ESCAPABLE="\"yoooo\"" - \\SINGLE_QUOTED_SHOULDNT_PRESERVE_NEWLINES='yo - \\' - \\ - \\SINGLE_QUOTED_DOESNT_PRESERVES_QUOTES='yo' - \\ - \\# Line Comment - \\UNQUOTED_SHOULDNT_PRESERVE_NEWLINES_AND_TRIMS_TRAILING_SPACE=yo # Inline Comment - \\ - \\ LEADING_SPACE_IS_TRIMMED=yes - \\ - \\LEADING_SPACE_IN_UNQUOTED_VALUE_IS_TRIMMED= yes - \\ - \\SPACE_BEFORE_EQUALS_SIGN =yes - \\ - \\LINES_WITHOUT_EQUAL_ARE_IGNORED - \\ - \\NO_VALUE_IS_EMPTY_STRING= - \\LINES_WITHOUT_EQUAL_ARE_IGNORED - \\ - \\IGNORING_DOESNT_BREAK_OTHER_LINES='yes' - \\ - \\NESTED_VALUE='$API_KEY' - \\ - \\NESTED_VALUE_WITH_CURLY_BRACES='${API_KEY}' - \\NESTED_VALUE_WITHOUT_OPENING_CURLY_BRACE='$API_KEY}' - \\ - \\RECURSIVE_NESTED_VALUE=$NESTED_VALUE:$API_KEY - \\ - \\RECURSIVE_NESTED_VALUE_WITH_CURLY_BRACES=${NESTED_VALUE}:${API_KEY} - \\ - \\NESTED_VALUES_RESPECT_ESCAPING='\$API_KEY' - \\ - \\NESTED_VALUES_WITH_CURLY_BRACES_RESPECT_ESCAPING='\${API_KEY}' - \\ - \\EMPTY_SINGLE_QUOTED_VALUE_IS_EMPTY_STRING='' - \\ - \\EMPTY_DOUBLE_QUOTED_VALUE_IS_EMPTY_STRING="" - \\ - \\VALUE_WITH_MULTIPLE_VALUES_SET_IN_SAME_FILE='' - \\ - \\VALUE_WITH_MULTIPLE_VALUES_SET_IN_SAME_FILE='good' - \\ - ; - const source = logger.Source.initPathString(".env", VALID_ENV); - var map = Map.init(default_allocator); - inline for (.{ true, false }) |override| { - Parser.parse( - &source, - default_allocator, - &map, - override, - false, - ); - try expectString(map.get("NESTED_VALUES_RESPECT_ESCAPING").?, "\\$API_KEY"); - try expectString(map.get("NESTED_VALUES_WITH_CURLY_BRACES_RESPECT_ESCAPING").?, "\\${API_KEY}"); - - try expectString(map.get("NESTED_VALUE").?, "verysecure"); - try expectString(map.get("NESTED_VALUE_WITH_CURLY_BRACES").?, "verysecure"); - try expectString(map.get("NESTED_VALUE_WITHOUT_OPENING_CURLY_BRACE").?, "verysecure}"); - try expectString(map.get("RECURSIVE_NESTED_VALUE").?, "verysecure:verysecure"); - try expectString(map.get("RECURSIVE_NESTED_VALUE_WITH_CURLY_BRACES").?, "verysecure:verysecure"); - - try expectString(map.get("API_KEY").?, "verysecure"); - try expectString(map.get("process.env.WAT").?, "ABCDEFGHIJKLMNOPQRSTUVWXYZZ10239457123"); - try expectString(map.get("DOUBLE-QUOTED_SHOULD_PRESERVE_NEWLINES").?, "\nya\n"); - try expectString(map.get("SINGLE_QUOTED_SHOULDNT_PRESERVE_NEWLINES").?, "yo"); - try expectString(map.get("SINGLE_QUOTED_DOESNT_PRESERVES_QUOTES").?, "yo"); - try expectString(map.get("UNQUOTED_SHOULDNT_PRESERVE_NEWLINES_AND_TRIMS_TRAILING_SPACE").?, "yo"); - try expect(map.get("LINES_WITHOUT_EQUAL_ARE_IGNORED") == null); - try expectString(map.get("LEADING_SPACE_IS_TRIMMED").?, "yes"); - try expect(map.get("NO_VALUE_IS_EMPTY_STRING").?.len == 0); - try expectString(map.get("IGNORING_DOESNT_BREAK_OTHER_LINES").?, "yes"); - try expectString(map.get("LEADING_SPACE_IN_UNQUOTED_VALUE_IS_TRIMMED").?, "yes"); - try expectString(map.get("SPACE_BEFORE_EQUALS_SIGN").?, "yes"); - try expectString(map.get("EMPTY_SINGLE_QUOTED_VALUE_IS_EMPTY_STRING").?, ""); - try expectString(map.get("EMPTY_DOUBLE_QUOTED_VALUE_IS_EMPTY_STRING").?, ""); - try expectString(map.get("VALUE_WITH_MULTIPLE_VALUES_SET_IN_SAME_FILE").?, "good"); - } -} - -test "DotEnv Loader - Nested values with curly braces" { - const VALID_ENV = - \\DB_USER=postgres - \\DB_PASS=xyz - \\DB_HOST=localhost - \\DB_PORT=5432 - \\DB_NAME=db - \\ - \\DB_USER2=${DB_USER} - \\ - \\DATABASE_URL="postgresql://${DB_USER}:${DB_PASS}@${DB_HOST}:${DB_PORT}/${DB_NAME}?pool_timeout=30&connection_limit=22" - \\ - ; - const source = logger.Source.initPathString(".env", VALID_ENV); - var map = Map.init(default_allocator); - Parser.parse( - &source, - default_allocator, - &map, - true, - false, - ); - try expectString(map.get("DB_USER").?, "postgres"); - try expectString(map.get("DB_USER2").?, "postgres"); - try expectString(map.get("DATABASE_URL").?, "postgresql://postgres:xyz@localhost:5432/db?pool_timeout=30&connection_limit=22"); -} - -test "DotEnv Process" { - var map = Map.init(default_allocator); - var process = try std.process.getEnvMap(default_allocator); - var loader = Loader.init(&map, default_allocator); - loader.loadProcess(); - - try expectString(loader.map.get("TMPDIR").?, bun.getenvZ("TMPDIR").?); - try expect(loader.map.get("TMPDIR").?.len > 0); - - try expectString(loader.map.get("USER").?, process.get("USER").?); - try expect(loader.map.get("USER").?.len > 0); - try expectString(loader.map.get("HOME").?, process.get("HOME").?); - try expect(loader.map.get("HOME").?.len > 0); -} - -test "DotEnv Loader - copyForDefine" { - const UserDefine = bun.StringArrayHashMap(string); - const UserDefinesArray = @import("./defines.zig").UserDefinesArray; - var map = Map.init(default_allocator); - var loader = Loader.init(&map, default_allocator); - const framework_keys = [_]string{ "process.env.BACON", "process.env.HOSTNAME" }; - const framework_values = [_]string{ "true", "\"localhost\"" }; - const framework = Api.StringMap{ - .keys = framework_keys[0..], - .value = framework_values[0..], - }; - - const user_overrides: string = - \\BACON=false - \\HOSTNAME=example.com - \\THIS_SHOULDNT_BE_IN_DEFINES_MAP=true - \\ - ; - - const skip_user_overrides: string = - \\THIS_SHOULDNT_BE_IN_DEFINES_MAP=true - \\ - ; - - loader.loadFromString(skip_user_overrides, false); - - var user_defines = UserDefine.init(default_allocator); - var env_defines = UserDefinesArray.init(default_allocator); - var buf = try loader.copyForDefine(UserDefine, &user_defines, UserDefinesArray, &env_defines, framework, .disable, "", default_allocator); - - try expect(user_defines.get("process.env.THIS_SHOULDNT_BE_IN_DEFINES_MAP") == null); - - user_defines = UserDefine.init(default_allocator); - env_defines = UserDefinesArray.init(default_allocator); - - loader.loadFromString(user_overrides, true); - - buf = try loader.copyForDefine( - UserDefine, - &user_defines, - UserDefinesArray, - &env_defines, - framework, - Api.DotEnvBehavior.load_all, - "", - default_allocator, - ); - - try expect(env_defines.get("process.env.BACON") != null); - try expectString(env_defines.get("process.env.BACON").?.value.e_string.data, "false"); - try expectString(env_defines.get("process.env.HOSTNAME").?.value.e_string.data, "example.com"); - try expect(env_defines.get("process.env.THIS_SHOULDNT_BE_IN_DEFINES_MAP") != null); - - user_defines = UserDefine.init(default_allocator); - env_defines = UserDefinesArray.init(default_allocator); - - buf = try loader.copyForDefine(UserDefine, &user_defines, UserDefinesArray, &env_defines, framework, .prefix, "HO", default_allocator); - - try expectString(env_defines.get("process.env.HOSTNAME").?.value.e_string.data, "example.com"); - try expect(env_defines.get("process.env.THIS_SHOULDNT_BE_IN_DEFINES_MAP") == null); -} pub const home_env = if (Environment.isWindows) "USERPROFILE" else "HOME"; diff --git a/src/exact_size_matcher.zig b/src/exact_size_matcher.zig index 9e5095e7f2..1b780f54eb 100644 --- a/src/exact_size_matcher.zig +++ b/src/exact_size_matcher.zig @@ -79,22 +79,3 @@ pub fn ExactSizeMatcher(comptime max_bytes: usize) type { const eight = ExactSizeMatcher(8); const expect = std.testing.expect; -test "ExactSizeMatcher 5 letter" { - const word = "yield"; - try expect(eight.match(word) == eight.case("yield")); - try expect(eight.match(word) != eight.case("yields")); -} - -test "ExactSizeMatcher 4 letter" { - const Four = ExactSizeMatcher(4); - const word = "from".*; - try expect(Four.match(word) == Four.case("from")); - try expect(Four.match(word) != Four.case("fro")); -} - -test "ExactSizeMatcher 12 letter" { - const Four = ExactSizeMatcher(12); - const word = "from"; - try expect(Four.match(word) == Four.case("from")); - try expect(Four.match(word) != Four.case("fro")); -} diff --git a/src/fs.zig b/src/fs.zig index 1d9d2ff082..a90eda8bba 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1847,14 +1847,3 @@ pub const Path = struct { // defer std.os.close(opened); // } - -test "PathName.init" { - var file = "/root/directory/file.ext".*; - const res = PathName.init( - &file, - ); - - try std.testing.expectEqualStrings(res.dir, "/root/directory"); - try std.testing.expectEqualStrings(res.base, "file"); - try std.testing.expectEqualStrings(res.ext, ".ext"); -} diff --git a/src/futex.zig b/src/futex.zig index d8d9a8a303..734449f3c5 100644 --- a/src/futex.zig +++ b/src/futex.zig @@ -399,174 +399,3 @@ const PosixFutex = struct { } }); }; - -test "Futex - wait/wake" { - var value = Atomic(u32).init(0); - Futex.wait(&value, 1, null) catch unreachable; - - const wait_noop_result = Futex.wait(&value, 0, 0); - try testing.expectError(error.TimedOut, wait_noop_result); - - const wait_longer_result = Futex.wait(&value, 0, std.time.ns_per_ms); - try testing.expectError(error.TimedOut, wait_longer_result); - - Futex.wake(&value, 0); - Futex.wake(&value, 1); - Futex.wake(&value, std.math.maxInt(u32)); -} - -test "Futex - Signal" { - if (single_threaded) { - return error.SkipZigTest; - } - - const Paddle = struct { - value: Atomic(u32) = Atomic(u32).init(0), - current: u32 = 0, - - fn run(self: *@This(), hit_to: *@This()) !void { - var iterations: usize = 4; - while (iterations > 0) : (iterations -= 1) { - var value: u32 = undefined; - while (true) { - value = self.value.load(.Acquire); - if (value != self.current) break; - Futex.wait(&self.value, self.current, null) catch unreachable; - } - - try testing.expectEqual(value, self.current + 1); - self.current = value; - - _ = hit_to.value.fetchAdd(1, .Release); - Futex.wake(&hit_to.value, 1); - } - } - }; - - var ping = Paddle{}; - var pong = Paddle{}; - - const t1 = try std.Thread.spawn(.{}, Paddle.run, .{ &ping, &pong }); - defer t1.join(); - - const t2 = try std.Thread.spawn(.{}, Paddle.run, .{ &pong, &ping }); - defer t2.join(); - - _ = ping.value.fetchAdd(1, .Release); - Futex.wake(&ping.value, 1); -} - -test "Futex - Broadcast" { - if (single_threaded) { - return error.SkipZigTest; - } - - const Context = struct { - threads: [4]std.Thread = undefined, - broadcast: Atomic(u32) = Atomic(u32).init(0), - notified: Atomic(usize) = Atomic(usize).init(0), - - const BROADCAST_EMPTY = 0; - const BROADCAST_SENT = 1; - const BROADCAST_RECEIVED = 2; - - fn runSender(self: *@This()) !void { - self.broadcast.store(BROADCAST_SENT, .Monotonic); - Futex.wake(&self.broadcast, @as(u32, @intCast(self.threads.len))); - - while (true) { - const broadcast = self.broadcast.load(.Acquire); - if (broadcast == BROADCAST_RECEIVED) break; - try testing.expectEqual(broadcast, BROADCAST_SENT); - Futex.wait(&self.broadcast, broadcast, null) catch unreachable; - } - } - - fn runReceiver(self: *@This()) void { - while (true) { - const broadcast = self.broadcast.load(.Acquire); - if (broadcast == BROADCAST_SENT) break; - assert(broadcast == BROADCAST_EMPTY); - Futex.wait(&self.broadcast, broadcast, null) catch unreachable; - } - - const notified = self.notified.fetchAdd(1, .Monotonic); - if (notified + 1 == self.threads.len) { - self.broadcast.store(BROADCAST_RECEIVED, .Release); - Futex.wake(&self.broadcast, 1); - } - } - }; - - var ctx = Context{}; - for (ctx.threads) |*thread| - thread.* = try std.Thread.spawn(.{}, Context.runReceiver, .{&ctx}); - defer for (ctx.threads) |thread| - thread.join(); - - // Try to wait for the threads to start before running runSender(). - // NOTE: not actually needed for correctness. - std.time.sleep(16 * std.time.ns_per_ms); - try ctx.runSender(); - - const notified = ctx.notified.load(.Monotonic); - try testing.expectEqual(notified, ctx.threads.len); -} - -test "Futex - Chain" { - if (single_threaded) { - return error.SkipZigTest; - } - - const Signal = struct { - value: Atomic(u32) = Atomic(u32).init(0), - - fn wait(self: *@This()) void { - while (true) { - const value = self.value.load(.Acquire); - if (value == 1) break; - assert(value == 0); - Futex.wait(&self.value, 0, null) catch unreachable; - } - } - - fn notify(self: *@This()) void { - assert(self.value.load(.Unordered) == 0); - self.value.store(1, .Release); - Futex.wake(&self.value, 1); - } - }; - - const Context = struct { - completed: Signal = .{}, - threads: [4]struct { - thread: std.Thread, - signal: Signal, - } = undefined, - - fn run(self: *@This(), index: usize) void { - const this_signal = &self.threads[index].signal; - - var next_signal = &self.completed; - if (index + 1 < self.threads.len) { - next_signal = &self.threads[index + 1].signal; - } - - this_signal.wait(); - next_signal.notify(); - } - }; - - var ctx = Context{}; - for (&ctx.threads, 0..) |*entry, index| { - entry.signal = .{}; - entry.thread = try std.Thread.spawn(.{}, Context.run, .{ &ctx, index }); - } - - ctx.threads[0].signal.notify(); - ctx.completed.wait(); - - for (ctx.threads) |entry| { - entry.thread.join(); - } -} diff --git a/src/glob_ascii.zig b/src/glob_ascii.zig index 5de16b0d1d..38914eface 100644 --- a/src/glob_ascii.zig +++ b/src/glob_ascii.zig @@ -26,11 +26,6 @@ const math = std.math; const mem = std.mem; const expect = std.testing.expect; -test "unclosed_braces" { - try expect(match("src/foo.{ts,tsx", "src/foo.{ts,tsx")); - try expect(match("src/**/foo.{ts,tsx", "src/lmao/bro/foo.{ts,tsx")); -} - // These store character indices into the glob and path strings. path_index: usize = 0, glob_index: usize = 0, @@ -121,27 +116,6 @@ const BraceIndex = struct { end: u32 = 0, }; -test "glob_preprocess" { - try expect(match("{*.foo,*.ts,*.tsx}", "lmao.foo")); - try expect(match("hello\\ friends", "hello\\ friends")); - - // var brace_indices = std.mem.zeroes([10]BraceIndex); - // var brace_indices_len: u8 = 0; - // var glob: []const u8 = "{a}"; - - // _ = preprocess_glob(glob, &brace_indices, &brace_indices_len, 0); - // try std.testing.expectEqualDeep(@as(u8, 1), brace_indices_len); - // try std.testing.expectEqualDeep(@as(BraceIndex, .{.start = 0, .end = 2}), brace_indices[0]); - - // brace_indices = std.mem.zeroes([10]BraceIndex); - // brace_indices_len = 0; - // glob = "{a,{b,c}}"; - // _ = preprocess_glob(glob, &brace_indices, &brace_indices_len, 0); - // try std.testing.expectEqualDeep(@as(u8, 2), brace_indices_len); - // try std.testing.expectEqualDeep(@as(BraceIndex, .{.start = 0, .end = 8}), brace_indices[0]); - // try std.testing.expectEqualDeep(@as(BraceIndex, .{.start = 2, .end = 7}), brace_indices[1]); -} - pub fn preprocess_glob(glob: []const u8, brace_indices: *[10]BraceIndex, brace_indices_len: *u8, search_count: *u8, i: *u32) ?u32 { while (i.* < glob.len) { const c = glob[i]; diff --git a/src/install/install.zig b/src/install/install.zig index 23bf985a70..26eaf41a92 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -11095,182 +11095,3 @@ pub const PackageManifestError = error{ }; pub const LifecycleScriptSubprocess = @import("./lifecycle_script_runner.zig").LifecycleScriptSubprocess; - -test "UpdateRequests.parse" { - var log = logger.Log.init(default_allocator); - var array = PackageManager.UpdateRequest.Array.init(0) catch unreachable; - - const updates: []const []const u8 = &.{ - "@bacon/name", - "foo", - "bar", - "baz", - "boo@1.0.0", - "bing@latest", - "github:bar/foo", - }; - var reqs = PackageManager.UpdateRequest.parse(default_allocator, &log, updates, &array, .add); - - try std.testing.expectEqualStrings(reqs[0].name, "@bacon/name"); - try std.testing.expectEqualStrings(reqs[1].name, "foo"); - try std.testing.expectEqualStrings(reqs[2].name, "bar"); - try std.testing.expectEqualStrings(reqs[3].name, "baz"); - try std.testing.expectEqualStrings(reqs[4].name, "boo"); - try std.testing.expectEqualStrings(reqs[7].name, "github:bar/foo"); - try std.testing.expectEqual(reqs[4].version.tag, Dependency.Version.Tag.npm); - try std.testing.expectEqualStrings(reqs[4].version.literal.slice("boo@1.0.0"), "1.0.0"); - try std.testing.expectEqual(reqs[5].version.tag, Dependency.Version.Tag.dist_tag); - try std.testing.expectEqualStrings(reqs[5].version.literal.slice("bing@1.0.0"), "latest"); - try std.testing.expectEqual(updates.len, 7); -} - -test "PackageManager.Options - default registry, default values" { - const allocator = default_allocator; - var log = logger.Log.init(allocator); - defer log.deinit(); - var env = DotEnv.Loader.init(&DotEnv.Map.init(allocator), allocator); - var options = PackageManager.Options{}; - - try options.load(allocator, &log, &env, null, null); - - try std.testing.expectEqualStrings("", options.scope.name); - try std.testing.expectEqualStrings("", options.scope.auth); - try std.testing.expectEqualStrings(Npm.Registry.default_url, options.scope.url.href); - try std.testing.expectEqualStrings("", options.scope.token); -} - -test "PackageManager.Options - default registry, custom token" { - const allocator = default_allocator; - var log = logger.Log.init(allocator); - defer log.deinit(); - var env = DotEnv.Loader.init(&DotEnv.Map.init(allocator), allocator); - var install = Api.BunInstall{ - .default_registry = Api.NpmRegistry{ - .url = "", - .username = "foo", - .password = "bar", - .token = "baz", - }, - .native_bin_links = &.{}, - }; - var options = PackageManager.Options{}; - - try options.load(allocator, &log, &env, null, &install); - - try std.testing.expectEqualStrings("", options.scope.name); - try std.testing.expectEqualStrings("", options.scope.auth); - try std.testing.expectEqualStrings(Npm.Registry.default_url, options.scope.url.href); - try std.testing.expectEqualStrings("baz", options.scope.token); -} - -test "PackageManager.Options - default registry, custom URL" { - const allocator = default_allocator; - var log = logger.Log.init(allocator); - defer log.deinit(); - var env = DotEnv.Loader.init(&DotEnv.Map.init(allocator), allocator); - var install = Api.BunInstall{ - .default_registry = Api.NpmRegistry{ - .url = "https://example.com/", - .username = "foo", - .password = "bar", - .token = "", - }, - .native_bin_links = &.{}, - }; - var options = PackageManager.Options{}; - - try options.load(allocator, &log, &env, null, &install); - - try std.testing.expectEqualStrings("", options.scope.name); - try std.testing.expectEqualStrings("Zm9vOmJhcg==", options.scope.auth); - try std.testing.expectEqualStrings("https://example.com/", options.scope.url.href); - try std.testing.expectEqualStrings("", options.scope.token); -} - -test "PackageManager.Options - scoped registry" { - const allocator = default_allocator; - var log = logger.Log.init(allocator); - defer log.deinit(); - var env = DotEnv.Loader.init(&DotEnv.Map.init(allocator), allocator); - var install = Api.BunInstall{ - .scoped = Api.NpmRegistryMap{ - .scopes = &.{ - "foo", - }, - .registries = &.{ - Api.NpmRegistry{ - .url = "", - .username = "", - .password = "", - .token = "bar", - }, - }, - }, - .native_bin_links = &.{}, - }; - var options = PackageManager.Options{}; - - try options.load(allocator, &log, &env, null, &install); - - try std.testing.expectEqualStrings("", options.scope.name); - try std.testing.expectEqualStrings("", options.scope.auth); - try std.testing.expectEqualStrings(Npm.Registry.default_url, options.scope.url.href); - try std.testing.expectEqualStrings("", options.scope.token); - - const scoped = options.registries.getPtr(Npm.Registry.Scope.hash(Npm.Registry.Scope.getName("foo"))); - - try std.testing.expect(scoped != null); - if (scoped) |scope| { - try std.testing.expectEqualStrings("foo", scope.name); - try std.testing.expectEqualStrings("", scope.auth); - try std.testing.expectEqualStrings(Npm.Registry.default_url, scope.url.href); - try std.testing.expectEqualStrings("bar", scope.token); - } -} - -test "PackageManager.Options - mixed default/scoped registry" { - const allocator = default_allocator; - var log = logger.Log.init(allocator); - defer log.deinit(); - var env = DotEnv.Loader.init(&DotEnv.Map.init(allocator), allocator); - var install = Api.BunInstall{ - .default_registry = Api.NpmRegistry{ - .url = "https://example.com/", - .username = "", - .password = "", - .token = "foo", - }, - .scoped = Api.NpmRegistryMap{ - .scopes = &.{ - "bar", - }, - .registries = &.{ - Api.NpmRegistry{ - .url = "", - .username = "baz", - .password = "moo", - .token = "", - }, - }, - }, - .native_bin_links = &.{}, - }; - var options = PackageManager.Options{}; - - try options.load(allocator, &log, &env, null, &install); - - try std.testing.expectEqualStrings("", options.scope.name); - try std.testing.expectEqualStrings("", options.scope.auth); - try std.testing.expectEqualStrings("https://example.com/", options.scope.url.href); - try std.testing.expectEqualStrings("foo", options.scope.token); - - const scoped = options.registries.getPtr(Npm.Registry.Scope.hash(Npm.Registry.Scope.getName("bar"))); - - try std.testing.expect(scoped != null); - if (scoped) |scope| { - try std.testing.expectEqualStrings("bar", scope.name); - try std.testing.expectEqualStrings("YmF6Om1vbw==", scope.auth); - try std.testing.expectEqualStrings("https://example.com/", scope.url.href); - try std.testing.expectEqualStrings("", scope.token); - } -} diff --git a/src/install/semver.zig b/src/install/semver.zig index fb90aa7815..6819792722 100644 --- a/src/install/semver.zig +++ b/src/install/semver.zig @@ -2279,383 +2279,4 @@ pub const SemverObject = struct { } }; -const expect = if (Environment.isTest) struct { - pub var counter: usize = 0; - pub fn isRangeMatch(input: string, version_str: string) bool { - var parsed = Version.parse(SlicedString.init(version_str, version_str)); - assert(parsed.valid); - // assert(strings.eql(parsed.version.raw.slice(version_str), version_str)); - - var list = Query.parse( - default_allocator, - input, - SlicedString.init(input, input), - ) catch |err| Output.panic("Test fail due to error {s}", .{@errorName(err)}); - - return list.satisfies(parsed.version.min()); - } - - pub fn range(input: string, version_str: string, src: std.builtin.SourceLocation) void { - Output.initTest(); - defer counter += 1; - if (!isRangeMatch(input, version_str)) { - Output.panic("Fail Expected range \"{s}\" to match \"{s}\"\nAt: {s}:{d}:{d} in {s}", .{ - input, - version_str, - src.file, - src.line, - src.column, - src.fn_name, - }); - } - } - pub fn notRange(input: string, version_str: string, src: std.builtin.SourceLocation) void { - Output.initTest(); - defer counter += 1; - if (isRangeMatch(input, version_str)) { - Output.panic("Fail Expected range \"{s}\" NOT match \"{s}\"\nAt: {s}:{d}:{d} in {s}", .{ - input, - version_str, - src.file, - src.line, - src.column, - src.fn_name, - }); - } - } - - pub fn done(src: std.builtin.SourceLocation) void { - Output.prettyErrorln("{d} passed expectations in {s}", .{ counter, src.fn_name }); - Output.flush(); - counter = 0; - } - - pub fn version(input: string, v: [3]?u32, src: std.builtin.SourceLocation) void { - Output.initTest(); - defer counter += 1; - const result = Version.parse(SlicedString.init(input, input)); - assert(result.valid); - - if (v[0] != result.version.major or v[1] != result.version.minor or v[2] != result.version.patch) { - Output.panic("Fail Expected version \"{s}\" to match \"{?d}.{?d}.{?d}\" but received \"{?d}.{?d}.{?d}\"\nAt: {s}:{d}:{d} in {s}", .{ - input, - v[0], - v[1], - v[2], - result.version.major, - result.version.minor, - result.version.patch, - src.file, - src.line, - src.column, - src.fn_name, - }); - } - } - - pub fn versionT(input: string, v: Version, src: std.builtin.SourceLocation) void { - Output.initTest(); - defer counter += 1; - - var result = Version.parse(SlicedString.init(input, input)); - if (!v.eql(result.version.min())) { - Output.panic("Fail Expected version \"{s}\" to match \"{?d}.{?d}.{?d}\" but received \"{?d}.{?d}.{?d}\"\nAt: {s}:{d}:{d} in {s}", .{ - input, - v.major, - v.minor, - v.patch, - result.version.major, - result.version.minor, - result.version.patch, - src.file, - src.line, - src.column, - src.fn_name, - }); - } - } -} else {}; - -test "Version parsing" { - defer expect.done(@src()); - const X: ?u32 = null; - - expect.version("1.0.0", .{ 1, 0, 0 }, @src()); - expect.version("1.1.0", .{ 1, 1, 0 }, @src()); - expect.version("1.1.1", .{ 1, 1, 1 }, @src()); - expect.version("1.1.0", .{ 1, 1, 0 }, @src()); - expect.version("0.1.1", .{ 0, 1, 1 }, @src()); - expect.version("0.0.1", .{ 0, 0, 1 }, @src()); - expect.version("0.0.0", .{ 0, 0, 0 }, @src()); - - expect.version("*", .{ X, X, X }, @src()); - expect.version("x", .{ X, X, X }, @src()); - expect.version("0", .{ 0, X, X }, @src()); - expect.version("0.0", .{ 0, 0, X }, @src()); - expect.version("0.0.0", .{ 0, 0, 0 }, @src()); - - expect.version("1.x", .{ 1, X, X }, @src()); - expect.version("2.2.x", .{ 2, 2, X }, @src()); - expect.version("2.x.2", .{ 2, X, 2 }, @src()); - - expect.version("1.X", .{ 1, X, X }, @src()); - expect.version("2.2.X", .{ 2, 2, X }, @src()); - expect.version("2.X.2", .{ 2, X, 2 }, @src()); - - expect.version("1.*", .{ 1, X, X }, @src()); - expect.version("2.2.*", .{ 2, 2, X }, @src()); - expect.version("2.*.2", .{ 2, X, 2 }, @src()); - expect.version("3", .{ 3, X, X }, @src()); - expect.version("3.x", .{ 3, X, X }, @src()); - expect.version("3.x.x", .{ 3, X, X }, @src()); - expect.version("3.*.*", .{ 3, X, X }, @src()); - expect.version("3.X.x", .{ 3, X, X }, @src()); - - { - var v = Version{ - .major = 1, - .minor = 0, - .patch = 0, - }; - var input: string = "1.0.0-beta"; - v.tag.pre = SlicedString.init(input, input["1.0.0-".len..]).external(); - expect.versionT(input, v, @src()); - } - - { - var v = Version{ - .major = 1, - .minor = 0, - .patch = 0, - }; - var input: string = "1.0.0beta"; - v.tag.pre = SlicedString.init(input, input["1.0.0".len..]).external(); - expect.versionT(input, v, @src()); - } - - { - var v = Version{ - .major = 1, - .minor = 0, - .patch = 0, - }; - var input: string = "1.0.0-build101"; - v.tag.pre = SlicedString.init(input, input["1.0.0-".len..]).external(); - expect.versionT(input, v, @src()); - } - - { - var v = Version{ - .major = 0, - .minor = 21, - .patch = 0, - }; - var input: string = "0.21.0-beta-96ca8d915-20211115"; - v.tag.pre = SlicedString.init(input, input["0.21.0-".len..]).external(); - expect.versionT(input, v, @src()); - } - - { - var v = Version{ - .major = 1, - .minor = 0, - .patch = 0, - }; - var input: string = "1.0.0-beta+build101"; - v.tag.build = SlicedString.init(input, input["1.0.0-beta+".len..]).external(); - v.tag.pre = SlicedString.init(input, input["1.0.0-".len..][0..4]).external(); - expect.versionT(input, v, @src()); - } - - var buf: [1024]u8 = undefined; - - var triplet = [3]?u32{ null, null, null }; - var x: u32 = 0; - var y: u32 = 0; - var z: u32 = 0; - - while (x < 32) : (x += 1) { - while (y < 32) : (y += 1) { - while (z < 32) : (z += 1) { - triplet[0] = x; - triplet[1] = y; - triplet[2] = z; - expect.version(try std.fmt.bufPrint(&buf, "{d}.{d}.{d}", .{ x, y, z }), triplet, @src()); - triplet[0] = z; - triplet[1] = x; - triplet[2] = y; - expect.version(try std.fmt.bufPrint(&buf, "{d}.{d}.{d}", .{ z, x, y }), triplet, @src()); - - triplet[0] = y; - triplet[1] = x; - triplet[2] = z; - expect.version(try std.fmt.bufPrint(&buf, "{d}.{d}.{d}", .{ y, x, z }), triplet, @src()); - } - } - } -} - -test "Range parsing" { - defer expect.done(@src()); - - expect.range("~1.2.3", "1.2.3", @src()); - expect.range("~1.2", "1.2.0", @src()); - expect.range("~1", "1.0.0", @src()); - expect.range("~1", "1.2.0", @src()); - expect.range("~1", "1.2.999", @src()); - expect.range("~0.2.3", "0.2.3", @src()); - expect.range("~0.2", "0.2.0", @src()); - expect.range("~0.2", "0.2.1", @src()); - - expect.range("~0 ", "0.0.0", @src()); - - expect.notRange("~1.2.3", "1.3.0", @src()); - expect.notRange("~1.2", "1.3.0", @src()); - expect.notRange("~1", "2.0.0", @src()); - expect.notRange("~0.2.3", "0.3.0", @src()); - expect.notRange("~0.2.3", "1.0.0", @src()); - expect.notRange("~0 ", "1.0.0", @src()); - expect.notRange("~0.2", "0.1.0", @src()); - expect.notRange("~0.2", "0.3.0", @src()); - - expect.notRange("~3.0.5", "3.3.0", @src()); - - expect.range("^1.1.4", "1.1.4", @src()); - - expect.range(">=3", "3.5.0", @src()); - expect.notRange(">=3", "2.999.999", @src()); - expect.range(">=3", "3.5.1", @src()); - expect.range(">=3", "4", @src()); - - expect.range("<6 >= 5", "5.0.0", @src()); - expect.notRange("<6 >= 5", "4.0.0", @src()); - expect.notRange("<6 >= 5", "6.0.0", @src()); - expect.notRange("<6 >= 5", "6.0.1", @src()); - - expect.range(">2", "3", @src()); - expect.notRange(">2", "2.1", @src()); - expect.notRange(">2", "2", @src()); - expect.notRange(">2", "1.0", @src()); - expect.notRange(">1.3", "1.3.1", @src()); - expect.range(">1.3", "2.0.0", @src()); - expect.range(">2.1.0", "2.2.0", @src()); - expect.range("<=2.2.99999", "2.2.0", @src()); - expect.range(">=2.1.99999", "2.2.0", @src()); - expect.range("<2.2.99999", "2.2.0", @src()); - expect.range(">2.1.99999", "2.2.0", @src()); - expect.range(">1.0.0", "2.0.0", @src()); - expect.range("1.0.0", "1.0.0", @src()); - expect.notRange("1.0.0", "2.0.0", @src()); - - expect.range("1.0.0 || 2.0.0", "1.0.0", @src()); - expect.range("2.0.0 || 1.0.0", "1.0.0", @src()); - expect.range("1.0.0 || 2.0.0", "2.0.0", @src()); - expect.range("2.0.0 || 1.0.0", "2.0.0", @src()); - expect.range("2.0.0 || >1.0.0", "2.0.0", @src()); - - expect.range(">1.0.0 <2.0.0 <2.0.1 >1.0.1", "1.0.2", @src()); - - expect.range("2.x", "2.0.0", @src()); - expect.range("2.x", "2.1.0", @src()); - expect.range("2.x", "2.2.0", @src()); - expect.range("2.x", "2.3.0", @src()); - expect.range("2.x", "2.1.1", @src()); - expect.range("2.x", "2.2.2", @src()); - expect.range("2.x", "2.3.3", @src()); - - expect.range("<2.0.1 >1.0.0", "2.0.0", @src()); - expect.range("<=2.0.1 >=1.0.0", "2.0.0", @src()); - - expect.range("^2", "2.0.0", @src()); - expect.range("^2", "2.9.9", @src()); - expect.range("~2", "2.0.0", @src()); - expect.range("~2", "2.1.0", @src()); - expect.range("~2.2", "2.2.1", @src()); - - { - const passing = [_]string{ "2.4.0", "2.4.1", "3.0.0", "3.0.1", "3.1.0", "3.2.0", "3.3.0", "3.3.1", "3.4.0", "3.5.0", "3.6.0", "3.7.0", "2.4.2", "3.8.0", "3.9.0", "3.9.1", "3.9.2", "3.9.3", "3.10.0", "3.10.1", "4.0.0", "4.0.1", "4.1.0", "4.2.0", "4.2.1", "4.3.0", "4.4.0", "4.5.0", "4.5.1", "4.6.0", "4.6.1", "4.7.0", "4.8.0", "4.8.1", "4.8.2", "4.9.0", "4.10.0", "4.11.0", "4.11.1", "4.11.2", "4.12.0", "4.13.0", "4.13.1", "4.14.0", "4.14.1", "4.14.2", "4.15.0", "4.16.0", "4.16.1", "4.16.2", "4.16.3", "4.16.4", "4.16.5", "4.16.6", "4.17.0", "4.17.1", "4.17.2", "4.17.3", "4.17.4", "4.17.5", "4.17.9", "4.17.10", "4.17.11", "2.0.0", "2.1.0" }; - - for (passing) |item| { - expect.range("^2 <2.2 || > 2.3", item, @src()); - expect.range("> 2.3 || ^2 <2.2", item, @src()); - } - - const not_passing = [_]string{ - "0.1.0", - "0.10.0", - "0.2.0", - "0.2.1", - "0.2.2", - "0.3.0", - "0.3.1", - "0.3.2", - "0.4.0", - "0.4.1", - "0.4.2", - "0.5.0", - // "0.5.0-rc.1", - "0.5.1", - "0.5.2", - "0.6.0", - "0.6.1", - "0.7.0", - "0.8.0", - "0.8.1", - "0.8.2", - "0.9.0", - "0.9.1", - "0.9.2", - "1.0.0", - "1.0.1", - "1.0.2", - "1.1.0", - "1.1.1", - "1.2.0", - "1.2.1", - "1.3.0", - "1.3.1", - "2.2.0", - "2.2.1", - "2.3.0", - // "1.0.0-rc.1", - // "1.0.0-rc.2", - // "1.0.0-rc.3", - }; - - for (not_passing) |item| { - expect.notRange("^2 <2.2 || > 2.3", item, @src()); - expect.notRange("> 2.3 || ^2 <2.2", item, @src()); - } - } - expect.range("2.1.0 || > 2.2 || >3", "2.1.0", @src()); - expect.range(" > 2.2 || >3 || 2.1.0", "2.1.0", @src()); - expect.range(" > 2.2 || 2.1.0 || >3", "2.1.0", @src()); - expect.range("> 2.2 || 2.1.0 || >3", "2.3.0", @src()); - expect.notRange("> 2.2 || 2.1.0 || >3", "2.2.1", @src()); - expect.notRange("> 2.2 || 2.1.0 || >3", "2.2.0", @src()); - expect.range("> 2.2 || 2.1.0 || >3", "2.3.0", @src()); - expect.range("> 2.2 || 2.1.0 || >3", "3.0.1", @src()); - expect.range("~2", "2.0.0", @src()); - expect.range("~2", "2.1.0", @src()); - - expect.range("1.2.0 - 1.3.0", "1.2.2", @src()); - expect.range("1.2 - 1.3", "1.2.2", @src()); - expect.range("1 - 1.3", "1.2.2", @src()); - expect.range("1 - 1.3", "1.3.0", @src()); - expect.range("1.2 - 1.3", "1.3.1", @src()); - expect.notRange("1.2 - 1.3", "1.4.0", @src()); - expect.range("1 - 1.3", "1.3.1", @src()); - - expect.notRange("1.2 - 1.3 || 5.0", "6.4.0", @src()); - expect.range("1.2 - 1.3 || 5.0", "1.2.1", @src()); - expect.range("5.0 || 1.2 - 1.3", "1.2.1", @src()); - expect.range("1.2 - 1.3 || 5.0", "5.0", @src()); - expect.range("5.0 || 1.2 - 1.3", "5.0", @src()); - expect.range("1.2 - 1.3 || 5.0", "5.0.2", @src()); - expect.range("5.0 || 1.2 - 1.3", "5.0.2", @src()); - expect.range("1.2 - 1.3 || 5.0", "5.0.2", @src()); - expect.range("5.0 || 1.2 - 1.3", "5.0.2", @src()); - expect.range("5.0 || 1.2 - 1.3 || >8", "9.0.2", @src()); -} - const assert = bun.assert; diff --git a/src/io/fifo.zig b/src/io/fifo.zig index fbb9a91d73..e9a7ab1fab 100644 --- a/src/io/fifo.zig +++ b/src/io/fifo.zig @@ -55,51 +55,3 @@ pub fn FIFO(comptime T: type) type { } }; } - -test "push/pop/peek/remove" { - const testing = @import("std").testing; - - const Foo = struct { next: ?*@This() = null }; - - var one: Foo = .{}; - var two: Foo = .{}; - var three: Foo = .{}; - - var fifo: FIFO(Foo) = .{}; - - fifo.push(&one); - try testing.expectEqual(@as(?*Foo, &one), fifo.peek()); - - fifo.push(&two); - fifo.push(&three); - try testing.expectEqual(@as(?*Foo, &one), fifo.peek()); - - fifo.remove(&one); - try testing.expectEqual(@as(?*Foo, &two), fifo.pop()); - try testing.expectEqual(@as(?*Foo, &three), fifo.pop()); - try testing.expectEqual(@as(?*Foo, null), fifo.pop()); - - fifo.push(&one); - fifo.push(&two); - fifo.push(&three); - fifo.remove(&two); - try testing.expectEqual(@as(?*Foo, &one), fifo.pop()); - try testing.expectEqual(@as(?*Foo, &three), fifo.pop()); - try testing.expectEqual(@as(?*Foo, null), fifo.pop()); - - fifo.push(&one); - fifo.push(&two); - fifo.push(&three); - fifo.remove(&three); - try testing.expectEqual(@as(?*Foo, &one), fifo.pop()); - try testing.expectEqual(@as(?*Foo, &two), fifo.pop()); - try testing.expectEqual(@as(?*Foo, null), fifo.pop()); - - fifo.push(&one); - fifo.push(&two); - fifo.remove(&two); - fifo.push(&three); - try testing.expectEqual(@as(?*Foo, &one), fifo.pop()); - try testing.expectEqual(@as(?*Foo, &three), fifo.pop()); - try testing.expectEqual(@as(?*Foo, null), fifo.pop()); -} diff --git a/src/io/heap.zig b/src/io/heap.zig index 1100b59685..1001bd914b 100644 --- a/src/io/heap.zig +++ b/src/io/heap.zig @@ -174,207 +174,3 @@ pub fn IntrusiveField(comptime T: type) type { next: ?*T = null, }; } - -test "heap" { - const Elem = struct { - const Self = @This(); - value: usize = 0, - heap: IntrusiveField(Self) = .{}, - }; - - const Heap = Intrusive(Elem, void, (struct { - fn less(ctx: void, a: *Elem, b: *Elem) bool { - _ = ctx; - return a.value < b.value; - } - }).less); - - var a: Elem = .{ .value = 12 }; - var b: Elem = .{ .value = 24 }; - var c: Elem = .{ .value = 7 }; - var d: Elem = .{ .value = 9 }; - - var h: Heap = .{ .context = {} }; - h.insert(&a); - h.insert(&b); - h.insert(&c); - h.insert(&d); - h.remove(&d); - - const testing = std.testing; - try testing.expect(h.deleteMin().?.value == 7); - try testing.expect(h.deleteMin().?.value == 12); - try testing.expect(h.deleteMin().?.value == 24); - try testing.expect(h.deleteMin() == null); -} - -test "heap remove root" { - const Elem = struct { - const Self = @This(); - value: usize = 0, - heap: IntrusiveField(Self) = .{}, - }; - - const Heap = Intrusive(Elem, void, (struct { - fn less(ctx: void, a: *Elem, b: *Elem) bool { - _ = ctx; - return a.value < b.value; - } - }).less); - - var a: Elem = .{ .value = 12 }; - var b: Elem = .{ .value = 24 }; - - var h: Heap = .{ .context = {} }; - h.insert(&a); - h.insert(&b); - h.remove(&a); - - const testing = std.testing; - try testing.expect(h.deleteMin().?.value == 24); - try testing.expect(h.deleteMin() == null); -} - -test "heap remove with children" { - const Elem = struct { - const Self = @This(); - value: usize = 0, - heap: IntrusiveField(Self) = .{}, - }; - - const Heap = Intrusive(Elem, void, (struct { - fn less(ctx: void, a: *Elem, b: *Elem) bool { - _ = ctx; - return a.value < b.value; - } - }).less); - - var a: Elem = .{ .value = 36 }; - var b: Elem = .{ .value = 24 }; - var c: Elem = .{ .value = 12 }; - - var h: Heap = .{ .context = {} }; - h.insert(&a); - h.insert(&b); - h.insert(&c); - h.remove(&b); - - const testing = std.testing; - try testing.expect(h.deleteMin().?.value == 12); - try testing.expect(h.deleteMin().?.value == 36); - try testing.expect(h.deleteMin() == null); -} - -test "heap equal values" { - const testing = std.testing; - - const Elem = struct { - const Self = @This(); - value: usize = 0, - heap: IntrusiveField(Self) = .{}, - }; - - const Heap = Intrusive(Elem, void, (struct { - fn less(ctx: void, a: *Elem, b: *Elem) bool { - _ = ctx; - return a.value < b.value; - } - }).less); - - var a: Elem = .{ .value = 1 }; - var b: Elem = .{ .value = 2 }; - var c: Elem = .{ .value = 3 }; - var d: Elem = .{ .value = 4 }; - - var h: Heap = .{ .context = {} }; - h.insert(&a); - h.insert(&b); - h.insert(&c); - h.insert(&d); - - try testing.expect(h.deleteMin().?.value == 1); - try testing.expect(h.deleteMin().?.value == 2); - try testing.expect(h.deleteMin().?.value == 3); - try testing.expect(h.deleteMin().?.value == 4); - try testing.expect(h.deleteMin() == null); -} - -test "heap: million values" { - const testing = std.testing; - const alloc = testing.allocator; - - const Elem = struct { - const Self = @This(); - value: usize = 0, - heap: IntrusiveField(Self) = .{}, - }; - - const Heap = Intrusive(Elem, void, (struct { - fn less(ctx: void, a: *Elem, b: *Elem) bool { - _ = ctx; - return a.value < b.value; - } - }).less); - - const NUM_TIMERS: usize = 1000 * 1000; - var elems = try alloc.alloc(Elem, NUM_TIMERS); - defer alloc.free(elems); - - var i: usize = 0; - var value: usize = 0; - while (i < NUM_TIMERS) : (i += 1) { - if (i % 100 == 0) value += 1; - elems[i] = .{ .value = value }; - } - - var h: Heap = .{ .context = {} }; - for (elems) |*elem| { - h.insert(elem); - } - - var count: usize = 0; - var last: usize = 0; - while (h.deleteMin()) |elem| { - count += 1; - try testing.expect(elem.value >= last); - last = elem.value; - } - try testing.expect(h.deleteMin() == null); - try testing.expect(count == NUM_TIMERS); -} - -test "heap: dangling next pointer" { - const testing = std.testing; - const Elem = struct { - const Self = @This(); - value: usize = 0, - heap: IntrusiveField(Self) = .{}, - }; - - const Heap = Intrusive(Elem, void, (struct { - fn less(ctx: void, a: *Elem, b: *Elem) bool { - _ = ctx; - return a.value < b.value; - } - }).less); - - var a: Elem = .{ .value = 2 }; - var b: Elem = .{ .value = 4 }; - var c: Elem = .{ .value = 5 }; - var d: Elem = .{ .value = 1 }; - var e: Elem = .{ .value = 3 }; - - var h: Heap = .{ .context = {} }; - h.insert(&a); - h.insert(&b); - h.insert(&c); - h.insert(&d); - h.insert(&e); - - try testing.expect(h.deleteMin().?.value == 1); - try testing.expect(h.deleteMin().?.value == 2); - try testing.expect(h.deleteMin().?.value == 3); - try testing.expect(h.deleteMin().?.value == 4); - try testing.expect(h.deleteMin().?.value == 5); - try testing.expect(h.deleteMin() == null); -} diff --git a/src/js_ast.zig b/src/js_ast.zig index d0ad8ff66e..02306a5405 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -5489,10 +5489,6 @@ pub const Expr = struct { }; }; -test "Byte size of Expr" { - try std.io.getStdErr().writeAll(comptime std.fmt.comptimePrint("\n\nByte Size {d}\n\n", .{@sizeOf(Expr.Data)})); -} - pub const EnumValue = struct { loc: logger.Loc, ref: Ref, diff --git a/src/js_lexer.zig b/src/js_lexer.zig index 47b8a8db3f..96e396c8de 100644 --- a/src/js_lexer.zig +++ b/src/js_lexer.zig @@ -3458,31 +3458,3 @@ fn indexOfInterestingCharacterInStringLiteral(text_: []const u8, quote: u8) ?usi return null; } - -test "isIdentifier" { - const expect = std.testing.expect; - try expect(!isIdentifierStart(0x2029)); - try expect(!isIdentifierStart(0)); - try expect(!isIdentifierStart(1)); - try expect(!isIdentifierStart(2)); - try expect(!isIdentifierStart(3)); - try expect(!isIdentifierStart(4)); - try expect(!isIdentifierStart(5)); - try expect(!isIdentifierStart(6)); - try expect(!isIdentifierStart(7)); - try expect(!isIdentifierStart(8)); - try expect(!isIdentifierStart(9)); - try expect(!isIdentifierStart(0x2028)); - try expect(!isIdentifier("\\u2028")); - try expect(!isIdentifier("\\u2029")); - - try expect(!isIdentifierContinue(':')); - try expect(!isIdentifier("javascript:")); - - try expect(isIdentifier("javascript")); - - try expect(!isIdentifier(":2")); - try expect(!isIdentifier("2:")); - try expect(isIdentifier("$")); - try expect(!isIdentifier("$:")); -} diff --git a/src/js_lexer/identifier.zig b/src/js_lexer/identifier.zig index 77308fcd20..71bbd7c4ae 100644 --- a/src/js_lexer/identifier.zig +++ b/src/js_lexer/identifier.zig @@ -137,28 +137,6 @@ pub const JumpTableInline = struct { } }; -// test "isIdentifier" { -// Bitset.init(); - -// const expect = std.testing.expect; -// try expect(!Bitset.isIdentifierStart(0x2029)); -// try expect(!Bitset.isIdentifierStart(0x2028)); -// try expect(!Bitset.isIdentifier("\\u2028")); -// try expect(!Bitset.isIdentifier("\\u2029")); - -// try expect(!Bitset.isIdentifierPart(':')); -// try expect(!Bitset.isIdentifier("javascript:")); - -// try expect(Bitset.isIdentifier("javascript")); - -// try expect(!Bitset.isIdentifier(":2")); -// try expect(!Bitset.isIdentifier("2:")); -// try expect(Bitset.isIdentifier("$")); -// try expect(!Bitset.isIdentifier("$:")); - -// try expect(Bitset.isIdentifier("ಠ_ಠ")); -// } - // // ----- The benchmark ------ // const std = @import("std"); @@ -2041,11 +2019,3 @@ pub const JumpTableInline = struct { // ); // } // } - -// test "Print size of bitset" { -// var err = std.io.getStdErr(); -// try err.writer().print( -// "Size is: {d} + {d}\n", -// .{ @sizeOf(@TypeOf(Bitset.id_start)), @sizeOf(@TypeOf(Bitset.id_continue)) }, -// ); -// } diff --git a/src/js_lexer_tables.zig b/src/js_lexer_tables.zig index 8f8fe04206..c18bd77e87 100644 --- a/src/js_lexer_tables.zig +++ b/src/js_lexer_tables.zig @@ -828,19 +828,3 @@ pub const jsxEntity = ComptimeStringMap(CodePoint, .{ .{ "zwj", @as(CodePoint, 0x200D) }, .{ "zwnj", @as(CodePoint, 0x200C) }, }); - -test "tokenToString" { - try expectString(tokenToString.get(T.t_end_of_file), "end of file"); -} - -// test "jsxEntity" { -// try alloc.setup(std.heap.page_allocator); - -// initJSXEntityMap() catch |err| { -// @panic(@errorName(err)); -// }; - -// if (jsxEntity.get("sim")) |v| { -// expect(v == 0x223C); -// } -// } diff --git a/src/js_printer.zig b/src/js_printer.zig index 70b40041bd..642c5940a1 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -446,18 +446,6 @@ pub fn writeJSONString(input: []const u8, comptime Writer: type, writer: Writer, try writer.writeAll("\""); } -test "quoteForJSON" { - const allocator = default_allocator; - try std.testing.expectEqualStrings( - "\"I don't need any quotes.\"", - (try quoteForJSON("I don't need any quotes.", MutableString.init(allocator, 0) catch unreachable, false)).list.items, - ); - try std.testing.expectEqualStrings( - "\"I need a quote for \\\"this\\\".\"", - (try quoteForJSON("I need a quote for \"this\".", MutableString.init(allocator, 0) catch unreachable, false)).list.items, - ); -} - pub const SourceMapHandler = struct { ctx: *anyopaque, callback: Callback, diff --git a/src/json_parser.zig b/src/json_parser.zig index 8110aa3c53..2e9eff0e4c 100644 --- a/src/json_parser.zig +++ b/src/json_parser.zig @@ -989,29 +989,3 @@ fn expectPrintedJSON(_contents: string, expected: string) !void { try std.testing.expectEqualStrings(expected, js); } - -test "ParseJSON" { - try expectPrintedJSON("true", "true"); - try expectPrintedJSON("false", "false"); - try expectPrintedJSON("1", "1"); - try expectPrintedJSON("10", "10"); - try expectPrintedJSON("100", "100"); - try expectPrintedJSON("100.1", "100.1"); - try expectPrintedJSON("19.1", "19.1"); - try expectPrintedJSON("19.12", "19.12"); - try expectPrintedJSON("3.4159820837456", "3.4159820837456"); - try expectPrintedJSON("-10000.25", "-10000.25"); - try expectPrintedJSON("\"hi\"", "\"hi\""); - try expectPrintedJSON("{\"hi\": 1, \"hey\": \"200\", \"boom\": {\"yo\": true}}", "{\"hi\": 1, \"hey\": \"200\", \"boom\": {\"yo\": true } }"); - try expectPrintedJSON("{\"hi\": \"hey\"}", "{\"hi\": \"hey\" }"); - try expectPrintedJSON( - "{\"hi\": [\"hey\", \"yo\"]}", - \\{"hi": [ - \\ "hey", - \\ "yo" - \\] } - , - ); - - // TODO: emoji? -} diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig index 6bebb1e076..19bd7e1478 100644 --- a/src/resolver/resolve_path.zig +++ b/src/resolver/resolve_path.zig @@ -1678,337 +1678,6 @@ pub fn normalizeStringNode( return out; } -test "joinAbsStringPosix" { - var t = tester.Tester.t(default_allocator); - defer t.report(@src()); - const string = []const u8; - const cwd = "/Users/jarredsumner/Code/app/"; - - _ = t.expect( - "/project/.pnpm/lodash@4.17.21/node_modules/lodash/eq", - try default_allocator.dupe(u8, joinAbsString(cwd, &[_]string{ - "/project/.pnpm/lodash@4.17.21/node_modules/lodash/", - "./eq", - }, .posix)), - @src(), - ); - - _ = t.expect( - "/foo/lodash/eq.js", - joinAbsString(cwd, &[_]string{ "/foo/lodash/", "./eq.js" }, .posix), - @src(), - ); - - _ = t.expect( - "/foo/lodash/eq.js", - joinAbsString(cwd, &[_]string{ "/foo/lodash", "./eq.js" }, .posix), - @src(), - ); - - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/bar/file.js", - joinAbsString(cwd, &[_]string{ "foo", "bar", "file.js" }, .posix), - @src(), - ); - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "foo", "bar", "../file.js" }, .posix), - @src(), - ); - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "foo", "./bar", "../file.js" }, .posix), - @src(), - ); - - _ = t.expect( - "/Users/jarredsumner/file.js", - joinAbsString(cwd, &[_]string{ "", "../../file.js" }, .posix), - @src(), - ); - - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "././././foo", "././././bar././././", "../file.js" }, .posix), - @src(), - ); - _ = t.expect( - "/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "/Code/app", "././././foo", "././././bar././././", "../file.js" }, .posix), - @src(), - ); - - _ = t.expect( - "/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "/Code/app", "././././foo", ".", "././././bar././././", ".", "../file.js" }, .posix), - @src(), - ); - - _ = t.expect( - "/Code/app/file.js", - joinAbsString(cwd, &[_]string{ "/Code/app", "././././foo", "..", "././././bar././././", ".", "../file.js" }, .posix), - @src(), - ); -} - -test "joinAbsStringLoose" { - var t = tester.Tester.t(default_allocator); - defer t.report(@src()); - const string = []const u8; - const cwd = "/Users/jarredsumner/Code/app"; - - _ = t.expect( - "/bar/foo", - joinAbsString(cwd, &[_]string{ - "/bar/foo", - "/bar/foo", - }, .loose), - @src(), - ); - - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/bar/file.js", - joinAbsString(cwd, &[_]string{ "foo", "bar", "file.js" }, .loose), - @src(), - ); - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "foo", "bar", "../file.js" }, .loose), - @src(), - ); - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "foo", "./bar", "../file.js" }, .loose), - @src(), - ); - - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "././././foo", "././././bar././././", "../file.js" }, .loose), - @src(), - ); - - _ = t.expect( - "/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "/Code/app", "././././foo", "././././bar././././", "../file.js" }, .loose), - @src(), - ); - - _ = t.expect( - "/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "/Code/app", "././././foo", ".", "././././bar././././", ".", "../file.js" }, .loose), - @src(), - ); - - _ = t.expect( - "/Code/app/file.js", - joinAbsString(cwd, &[_]string{ "/Code/app", "././././foo", "..", "././././bar././././", ".", "../file.js" }, .loose), - @src(), - ); - - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/bar/file.js", - joinAbsString(cwd, &[_]string{ "foo", "bar", "file.js" }, .loose), - @src(), - ); - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "foo", "bar", "../file.js" }, .loose), - @src(), - ); - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "foo", "./bar", "../file.js" }, .loose), - @src(), - ); - - _ = t.expect( - "/Users/jarredsumner/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ ".\\.\\.\\.\\foo", "././././bar././././", "..\\file.js" }, .loose), - @src(), - ); - - _ = t.expect( - "/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "/Code/app", "././././foo", "././././bar././././", "../file.js" }, .loose), - @src(), - ); - - _ = t.expect( - "/Code/app/foo/file.js", - joinAbsString(cwd, &[_]string{ "/Code/app", "././././foo", ".", "././././bar././././", ".", "../file.js" }, .loose), - @src(), - ); - - _ = t.expect( - "/Code/app/file.js", - joinAbsString(cwd, &[_]string{ "/Code/app", "././././foo", "..", "././././bar././././", ".", "../file.js" }, .loose), - @src(), - ); -} - -test "joinStringBuf" { - var t = tester.Tester.t(default_allocator); - defer t.report(@src()); - - const fixtures = .{ - .{ &[_][]const u8{ ".", "x/b", "..", "/b/c.js" }, "x/b/c.js" }, - .{ &[_][]const u8{}, "." }, - .{ &[_][]const u8{ "/.", "x/b", "..", "/b/c.js" }, "/x/b/c.js" }, - .{ &[_][]const u8{ "/foo", "../../../bar" }, "/bar" }, - .{ &[_][]const u8{ "foo", "../../../bar" }, "../../bar" }, - .{ &[_][]const u8{ "foo/", "../../../bar" }, "../../bar" }, - .{ &[_][]const u8{ "foo/x", "../../../bar" }, "../bar" }, - .{ &[_][]const u8{ "foo/x", "./bar" }, "foo/x/bar" }, - .{ &[_][]const u8{ "foo/x/", "./bar" }, "foo/x/bar" }, - .{ &[_][]const u8{ "foo/x/", ".", "bar" }, "foo/x/bar" }, - .{ &[_][]const u8{"./"}, "./" }, - .{ &[_][]const u8{ ".", "./" }, "./" }, - .{ &[_][]const u8{ ".", ".", "." }, "." }, - .{ &[_][]const u8{ ".", "./", "." }, "." }, - .{ &[_][]const u8{ ".", "/./", "." }, "." }, - .{ &[_][]const u8{ ".", "/////./", "." }, "." }, - .{ &[_][]const u8{"."}, "." }, - .{ &[_][]const u8{ "", "." }, "." }, - .{ &[_][]const u8{ "", "foo" }, "foo" }, - .{ &[_][]const u8{ "foo", "/bar" }, "foo/bar" }, - .{ &[_][]const u8{ "", "/foo" }, "/foo" }, - .{ &[_][]const u8{ "", "", "/foo" }, "/foo" }, - .{ &[_][]const u8{ "", "", "foo" }, "foo" }, - .{ &[_][]const u8{ "foo", "" }, "foo" }, - .{ &[_][]const u8{ "foo/", "" }, "foo/" }, - .{ &[_][]const u8{ "foo", "", "/bar" }, "foo/bar" }, - .{ &[_][]const u8{ "./", "..", "/foo" }, "../foo" }, - .{ &[_][]const u8{ "./", "..", "..", "/foo" }, "../../foo" }, - .{ &[_][]const u8{ ".", "..", "..", "/foo" }, "../../foo" }, - .{ &[_][]const u8{ "", "..", "..", "/foo" }, "../../foo" }, - - .{ &[_][]const u8{"/"}, "/" }, - .{ &[_][]const u8{ "/", "." }, "/" }, - .{ &[_][]const u8{ "/", ".." }, "/" }, - .{ &[_][]const u8{ "/", "..", ".." }, "/" }, - .{ &[_][]const u8{""}, "." }, - .{ &[_][]const u8{ "", "" }, "." }, - .{ &[_][]const u8{" /foo"}, " /foo" }, - .{ &[_][]const u8{ " ", "foo" }, " /foo" }, - .{ &[_][]const u8{ " ", "." }, " " }, - .{ &[_][]const u8{ " ", "/" }, " /" }, - .{ &[_][]const u8{ " ", "" }, " " }, - .{ &[_][]const u8{ "/", "foo" }, "/foo" }, - .{ &[_][]const u8{ "/", "/foo" }, "/foo" }, - .{ &[_][]const u8{ "/", "//foo" }, "/foo" }, - .{ &[_][]const u8{ "/", "", "/foo" }, "/foo" }, - .{ &[_][]const u8{ "", "/", "foo" }, "/foo" }, - .{ &[_][]const u8{ "", "/", "/foo" }, "/foo" }, - - .{ &[_][]const u8{ "", "..", "..", "..", "/foo" }, "../../../foo" }, - .{ &[_][]const u8{ "", "..", "..", "bar", "/foo" }, "../../bar/foo" }, - .{ &[_][]const u8{ "", "..", "..", "bar", "/foo", "../" }, "../../bar/" }, - }; - inline for (fixtures) |fixture| { - const expected = fixture[1]; - const buf = try default_allocator.alloc(u8, 2048); - _ = t.expect(expected, joinStringBuf(buf, fixture[0], .posix), @src()); - } -} - -test "normalizeStringPosix" { - var t = tester.Tester.t(default_allocator); - defer t.report(@src()); - var buf: [2048]u8 = undefined; - var buf2: [2048]u8 = undefined; - // Don't mess up strings that - _ = t.expect("../../bar", normalizeStringNode("../foo../../../bar", &buf, .posix), @src()); - _ = t.expect("foo/bar.txt", try normalizeStringAlloc(default_allocator, "/foo/bar.txt", true, .posix), @src()); - _ = t.expect("foo/bar.txt", try normalizeStringAlloc(default_allocator, "/foo/bar.txt", false, .posix), @src()); - _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/foo/bar", true, .posix), @src()); - _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/foo/bar", false, .posix), @src()); - _ = t.expect("/foo/bar", normalizeStringNode("/././foo/././././././bar/../bar/../bar", &buf2, .posix), @src()); - _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/foo/bar", false, .posix), @src()); - _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/foo/bar//////", false, .posix), @src()); - _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/////foo/bar//////", false, .posix), @src()); - _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/////foo/bar", false, .posix), @src()); - _ = t.expect("", try normalizeStringAlloc(default_allocator, "/////", false, .posix), @src()); - _ = t.expect("..", try normalizeStringAlloc(default_allocator, "../boom/../", true, .posix), @src()); - _ = t.expect("", try normalizeStringAlloc(default_allocator, "./", true, .posix), @src()); -} - -test "normalizeStringWindows" { - var t = tester.Tester.t(default_allocator); - defer t.report(@src()); - - // Don't mess up strings that - _ = t.expect("foo\\bar.txt", try normalizeStringAlloc(default_allocator, "\\foo\\bar.txt", true, .windows), @src()); - _ = t.expect("foo\\bar.txt", try normalizeStringAlloc(default_allocator, "\\foo\\bar.txt", false, .windows), @src()); - _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\foo\\bar", true, .windows), @src()); - _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\foo\\bar", false, .windows), @src()); - _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\.\\.\\foo\\.\\.\\.\\.\\.\\.\\bar\\..\\bar\\..\\bar", true, .windows), @src()); - _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\foo\\bar", false, .windows), @src()); - _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\foo\\bar\\\\\\\\\\\\", false, .windows), @src()); - _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\\\\\\\\\foo\\bar\\\\\\\\\\\\", false, .windows), @src()); - _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\\\\\\\\\foo\\bar", false, .windows), @src()); - _ = t.expect("", try normalizeStringAlloc(default_allocator, "\\\\\\\\\\", false, .windows), @src()); - _ = t.expect("..", try normalizeStringAlloc(default_allocator, "..\\boom\\..\\", true, .windows), @src()); - _ = t.expect("", try normalizeStringAlloc(default_allocator, ".\\", true, .windows), @src()); -} - -test "relative" { - var t = tester.Tester.t(default_allocator); - defer t.report(@src()); - - const fixtures = .{ - .{ "/var/lib", "/var", ".." }, - .{ "/var/lib", "/bin", "../../bin" }, - .{ "/var/lib", "/var/lib", "" }, - .{ "/var/lib", "/var/apache", "../apache" }, - .{ "/var/", "/var/lib", "lib" }, - .{ "/", "/var/lib", "var/lib" }, - .{ "/foo/test", "/foo/test/bar/package.json", "bar/package.json" }, - .{ "/Users/a/web/b/test/mails", "/Users/a/web/b", "../.." }, - .{ "/foo/bar/baz-quux", "/foo/bar/baz", "../baz" }, - .{ "/foo/bar/baz", "/foo/bar/baz-quux", "../baz-quux" }, - .{ "/baz-quux", "/baz", "../baz" }, - .{ "/baz", "/baz-quux", "../baz-quux" }, - .{ "/page1/page2/foo", "/", "../../.." }, - }; - - inline for (fixtures) |fixture| { - const from = fixture[0]; - const to = fixture[1]; - const expected = fixture[2]; - _ = t.expect(expected, try relativeAlloc(default_allocator, from, to), @src()); - } - - _ = t.expect("index.js", try relativeAlloc(default_allocator, "/app/public/", "/app/public/index.js"), @src()); - _ = t.expect("..", try relativeAlloc(default_allocator, "/app/public/index.js", "/app/public/"), @src()); - _ = t.expect("../../src/bacon.ts", try relativeAlloc(default_allocator, "/app/public/index.html", "/app/src/bacon.ts"), @src()); - _ = t.expect("../../../../bacon/foo/baz", try relativeAlloc(default_allocator, "/app/foo/bar/baz.js", "/bacon/foo/baz"), @src()); -} - -test "longestCommonPath" { - var t = tester.Tester.t(default_allocator); - defer t.report(@src()); - - const strs = [_][]const u8{ - "/var/boo/foo/", - "/var/boo/foo/baz/", - "/var/boo/foo/beep/", - "/var/boo/foo/beep/bleep", - "/bar/baz", - "/bar/not-related", - "/bar/file.txt", - }; - _ = t.expect("/var/boo/foo/", longestCommonPath(strs[0..2]), @src()); - _ = t.expect("/var/boo/foo/", longestCommonPath(strs[0..4]), @src()); - _ = t.expect("/var/boo/foo/beep/", longestCommonPath(strs[2..3]), @src()); - _ = t.expect("/bar/", longestCommonPath(strs[5..strs.len]), @src()); - _ = t.expect("/", longestCommonPath(&strs), @src()); - - const more = [_][]const u8{ "/app/public/index.html", "/app/public/index.js", "/app/public", "/app/src/bacon.ts" }; - _ = t.expect("/app/", longestCommonPath(&more), @src()); - _ = t.expect("/app/public/", longestCommonPath(more[0..2]), @src()); -} - pub fn basename(path: []const u8) []const u8 { if (path.len == 0) return &[_]u8{}; diff --git a/src/sha.zig b/src/sha.zig index f719e9a45d..04a6a4ff04 100644 --- a/src/sha.zig +++ b/src/sha.zig @@ -319,13 +319,3 @@ pub fn main() anyerror!void { } } } - -// TODO(sno2): update SHA256 test to include BoringSSL engine -// test "sha256" { -// const value: []const u8 = "hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world!"; -// var hash: SHA256.Digest = undefined; -// var hash2: SHA256.Digest = undefined; -// SHA256.hash(value, &hash); -// std.crypto.hash.sha2.Sha256.hash(value, &hash2, .{}); -// try std.testing.expectEqual(hash, hash2); -// } diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig index f0f77d6178..8804bd9d4d 100644 --- a/src/sourcemap/sourcemap.zig +++ b/src/sourcemap/sourcemap.zig @@ -693,41 +693,6 @@ pub fn encodeVLQWithLookupTable( encodeVLQ(value); } -test "encodeVLQ" { - const fixtures = .{ - .{ 2_147_483_647, "+/////D" }, - .{ -2_147_483_647, "//////D" }, - .{ 0, "A" }, - .{ 1, "C" }, - .{ -1, "D" }, - .{ 123, "2H" }, - .{ 123456789, "qxmvrH" }, - }; - inline for (fixtures) |fixture| { - const result = encodeVLQ(fixture[0]); - try std.testing.expectEqualStrings(fixture[1], result.bytes[0..result.len]); - } -} - -test "decodeVLQ" { - const fixtures = .{ - .{ 2_147_483_647, "+/////D" }, - .{ -2_147_483_647, "//////D" }, - .{ 0, "A" }, - .{ 1, "C" }, - .{ -1, "D" }, - .{ 123, "2H" }, - .{ 123456789, "qxmvrH" }, - }; - inline for (fixtures) |fixture| { - const result = decodeVLQ(fixture[1], 0); - try std.testing.expectEqual( - result.value, - fixture[0], - ); - } -} - // A single base 64 digit can contain 6 bits of data. For the base 64 variable // length quantities we use in the source map spec, the first bit is the sign, // the next four bits are the actual value, and the 6th bit is the continuation diff --git a/src/sourcemap/vlq_bench.zig b/src/sourcemap/vlq_bench.zig index 9476e77c20..1d6c40f2fb 100644 --- a/src/sourcemap/vlq_bench.zig +++ b/src/sourcemap/vlq_bench.zig @@ -321,38 +321,3 @@ pub fn main() anyerror!void { std.debug.print("[{d}] ILEB128 decode: {} in {}\n", .{ how_many, std.fmt.fmtIntSizeDec(byte_size), std.fmt.fmtDuration(elapsed) }); } } - -test "encodeVLQ" { - const fixtures = .{ - .{ 2_147_483_647, "+/////D" }, - .{ -2_147_483_647, "//////D" }, - .{ 0, "A" }, - .{ 1, "C" }, - .{ -1, "D" }, - .{ 123, "2H" }, - .{ 123456789, "qxmvrH" }, - }; - inline for (fixtures) |fixture| { - const result = SourceMap.encodeVLQ(fixture[0]); - try std.testing.expectEqualStrings(fixture[1], result.bytes[0..result.len]); - } -} - -test "decodeVLQ" { - const fixtures = .{ - .{ 2_147_483_647, "+/////D" }, - .{ -2_147_483_647, "//////D" }, - .{ 0, "A" }, - .{ 1, "C" }, - .{ -1, "D" }, - .{ 123, "2H" }, - .{ 123456789, "qxmvrH" }, - }; - inline for (fixtures) |fixture| { - const result = SourceMap.decodeVLQ(fixture[1], 0); - try std.testing.expectEqual( - result.value, - fixture[0], - ); - } -} diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 9fae3feccb..5cc94802f2 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -565,125 +565,6 @@ pub fn copyLowercaseIfNeeded(in: string, out: []u8) string { return if (any) out[0..in.len] else in; } -test "indexOf" { - const fixtures = .{ - .{ - "0123456789", - "456", - }, - .{ - "/foo/bar/baz/bacon/eggs/lettuce/tomatoe", - "bacon", - }, - .{ - "/foo/bar/baz/bacon////eggs/lettuce/tomatoe", - "eggs", - }, - .{ - "////////////////zfoo/bar/baz/bacon/eggs/lettuce/tomatoe", - "/", - }, - .{ - "/okay/well/thats/even/longer/now/well/thats/even/longer/now/well/thats/even/longer/now/foo/bar/baz/bacon/eggs/lettuce/tomatoe", - "/tomatoe", - }, - .{ - "/okay///////////so much length i can't believe it!much length i can't believe it!much length i can't believe it!much length i can't believe it!much length i can't believe it!much length i can't believe it!much length i can't believe it!much length i can't believe it!/well/thats/even/longer/now/well/thats/even/longer/now/well/thats/even/longer/now/foo/bar/baz/bacon/eggs/lettuce/tomatoe", - "/tomatoe", - }, - }; - - inline for (fixtures) |pair| { - try std.testing.expectEqual( - indexOf(pair[0], pair[1]).?, - std.mem.indexOf(u8, pair[0], pair[1]).?, - ); - } -} - -test "eqlComptimeCheckLen" { - try std.testing.expectEqual(eqlComptime("bun-darwin-aarch64.zip", "bun-darwin-aarch64.zip"), true); - const sizes = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 23, 22, 24 }; - inline for (sizes) |size| { - var buf: [size]u8 = undefined; - @memset(&buf, 'a'); - var buf_copy: [size]u8 = undefined; - @memset(&buf_copy, 'a'); - - var bad: [size]u8 = undefined; - @memset(&bad, 'b'); - try std.testing.expectEqual(std.mem.eql(u8, &buf, &buf_copy), eqlComptime(&buf, comptime brk: { - var buf_copy_: [size]u8 = undefined; - @memset(&buf_copy_, 'a'); - break :brk buf_copy_; - })); - - try std.testing.expectEqual(std.mem.eql(u8, &buf, &bad), eqlComptime(&bad, comptime brk: { - var buf_copy_: [size]u8 = undefined; - @memset(&buf_copy_, 'a'); - break :brk buf_copy_; - })); - } -} - -test "eqlComptimeUTF16" { - try std.testing.expectEqual(eqlComptimeUTF16(toUTF16Literal("bun-darwin-aarch64.zip"), "bun-darwin-aarch64.zip"), true); - const sizes = [_]u16{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 23, 22, 24 }; - inline for (sizes) |size| { - var buf: [size]u16 = undefined; - @memset(&buf, @as(u8, 'a')); - var buf_copy: [size]u16 = undefined; - @memset(&buf_copy, @as(u8, 'a')); - - var bad: [size]u16 = undefined; - @memset(&bad, @as(u16, 'b')); - try std.testing.expectEqual(std.mem.eql(u16, &buf, &buf_copy), eqlComptimeUTF16(&buf, comptime &brk: { - var buf_copy_: [size]u8 = undefined; - @memset(&buf_copy_, @as(u8, 'a')); - break :brk buf_copy_; - })); - - try std.testing.expectEqual(std.mem.eql(u16, &buf, &bad), eqlComptimeUTF16(&bad, comptime &brk: { - var buf_copy_: [size]u8 = undefined; - @memset(&buf_copy_, @as(u8, 'a')); - break :brk buf_copy_; - })); - } -} - -test "copyLowercase" { - { - const in = "Hello, World!"; - var out = std.mem.zeroes([in.len]u8); - const out_ = copyLowercase(in, &out); - try std.testing.expectEqualStrings(out_, "hello, world!"); - } - - { - const in = "_ListCache"; - var out = std.mem.zeroes([in.len]u8); - const out_ = copyLowercase(in, &out); - try std.testing.expectEqualStrings(out_, "_listcache"); - } -} - -test "StringOrTinyString" { - const correct: string = "helloooooooo"; - const big = "wawaweewaverylargeihaveachairwawaweewaverylargeihaveachairwawaweewaverylargeihaveachairwawaweewaverylargeihaveachair"; - var str = StringOrTinyString.init(correct); - try std.testing.expectEqualStrings(correct, str.slice()); - - str = StringOrTinyString.init(big); - try std.testing.expectEqualStrings(big, str.slice()); - try std.testing.expect(@sizeOf(StringOrTinyString) == 32); -} - -test "StringOrTinyString Lowercase" { - const correct: string = "HELLO!!!!!"; - var str = StringOrTinyString.initLowerCase(correct); - try std.testing.expectEqualStrings("hello!!!!!", str.slice()); -} - /// Copy a string into a buffer /// Return the copied version pub fn copy(buf: []u8, src: []const u8) []const u8 { @@ -850,15 +731,6 @@ pub fn countChar(self: string, char: u8) usize { return total; } -test "countChar" { - try std.testing.expectEqual(countChar("hello there", ' '), 1); - try std.testing.expectEqual(countChar("hello;;;there", ';'), 3); - try std.testing.expectEqual(countChar("hello there", 'z'), 0); - try std.testing.expectEqual(countChar("hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there ", ' '), 28); - try std.testing.expectEqual(countChar("hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there ", 'z'), 0); - try std.testing.expectEqual(countChar("hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there hello there", ' '), 27); -} - pub fn endsWithAnyComptime(self: string, comptime str: string) bool { if (comptime str.len < 10) { const last = self[self.len - 1]; @@ -3138,38 +3010,6 @@ pub fn escapeHTMLForUTF16Input(allocator: std.mem.Allocator, utf16: []const u16) } } -test "copyLatin1IntoUTF8 - ascii" { - const input: string = "hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!"; - var output = std.mem.zeroes([500]u8); - const result = copyLatin1IntoUTF8(&output, string, input); - try std.testing.expectEqual(input.len, result.read); - try std.testing.expectEqual(input.len, result.written); - - try std.testing.expectEqualSlices(u8, input, output[0..result.written]); -} - -test "copyLatin1IntoUTF8 - latin1" { - { - const input: string = &[_]u8{ 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 169 }; - var output = std.mem.zeroes([500]u8); - const expected = "hello world ©"; - const result = copyLatin1IntoUTF8(&output, string, input); - try std.testing.expectEqual(input.len, result.read); - - try std.testing.expectEqualSlices(u8, expected, output[0..result.written]); - } - - { - const input: string = &[_]u8{ 72, 169, 101, 108, 108, 169, 111, 32, 87, 111, 114, 169, 108, 100, 33 }; - var output = std.mem.zeroes([500]u8); - const expected = "H©ell©o Wor©ld!"; - const result = copyLatin1IntoUTF8(&output, string, input); - try std.testing.expectEqual(input.len, result.read); - - try std.testing.expectEqualSlices(u8, expected, output[0..result.written]); - } -} - pub fn latin1ToCodepointAssumeNotASCII(char: u8, comptime CodePointType: type) CodePointType { return @as( CodePointType, @@ -3947,14 +3787,6 @@ pub fn indexOfNeedsEscape(slice: []const u8) ?u32 { return null; } -test "indexOfNeedsEscape" { - const out = indexOfNeedsEscape( - \\la la la la la la la la la la la la la la la la "oh!" okay "well" - , - ); - try std.testing.expectEqual(out.?, 48); -} - pub fn indexOfCharZ(sliceZ: [:0]const u8, char: u8) ?u63 { const ptr = bun.C.strchr(sliceZ.ptr, char) orelse return null; const pos = @intFromPtr(ptr) - @intFromPtr(sliceZ.ptr); @@ -3991,41 +3823,6 @@ pub fn indexOfChar16Usize(slice: []const u16, char: u16) ?usize { return std.mem.indexOfScalar(u16, slice, char); } -test "indexOfChar" { - const pairs = .{ - .{ - "fooooooboooooofoooooofoooooofoooooofoooooozball", - 'b', - }, - .{ - "foooooofoooooofoooooofoooooofoooooofoooooozball", - 'z', - }, - .{ - "foooooofoooooofoooooofoooooofoooooofoooooozball", - 'a', - }, - .{ - "foooooofoooooofoooooofoooooofoooooofoooooozball", - 'l', - }, - .{ - "baconaopsdkaposdkpaosdkpaosdkaposdkpoasdkpoaskdpoaskdpoaskdpo;", - ';', - }, - .{ - ";baconaopsdkaposdkpaosdkpaosdkaposdkpoasdkpoaskdpoaskdpoaskdpo;", - ';', - }, - }; - inline for (pairs) |pair| { - try std.testing.expectEqual( - indexOfChar(pair.@"0", pair.@"1").?, - @as(u32, @truncate(std.mem.indexOfScalar(u8, pair.@"0", pair.@"1").?)), - ); - } -} - pub fn indexOfNotChar(slice: []const u8, char: u8) ?u32 { var remaining = slice; if (remaining.len == 0) @@ -4215,34 +4012,6 @@ pub fn encodeBytesToHex(destination: []u8, source: []const u8) usize { return to_read * 2; } -test "decodeHexToBytes" { - var buffer = std.mem.zeroes([1024]u8); - for (buffer, 0..) |_, i| { - buffer[i] = @as(u8, @truncate(i % 256)); - } - var written: [2048]u8 = undefined; - const hex = std.fmt.bufPrint(&written, "{}", .{std.fmt.fmtSliceHexLower(&buffer)}) catch unreachable; - var good: [4096]u8 = undefined; - var ours_buf: [4096]u8 = undefined; - const match = try std.fmt.hexToBytes(good[0..1024], hex); - const ours = decodeHexToBytes(&ours_buf, u8, hex); - try std.testing.expectEqualSlices(u8, match, ours_buf[0..ours]); - try std.testing.expectEqualSlices(u8, &buffer, ours_buf[0..ours]); -} - -// test "formatBytesToHex" { -// var buffer = std.mem.zeroes([1024]u8); -// for (buffer) |_, i| { -// buffer[i] = @truncate(u8, i % 256); -// } -// var written: [2048]u8 = undefined; -// var hex = std.fmt.bufPrint(&written, "{}", .{std.fmt.fmtSliceHexLower(&buffer)}) catch unreachable; -// var ours_buf: [4096]u8 = undefined; -// // var ours = formatBytesToHex(&ours_buf, &buffer); -// // try std.testing.expectEqualSlices(u8, match, ours_buf[0..ours]); -// try std.testing.expectEqualSlices(u8, &buffer, ours_buf[0..ours]); -// } - pub fn trimLeadingChar(slice: []const u8, char: u8) []const u8 { if (indexOfNotChar(slice, char)) |i| { return slice[i..]; @@ -4486,75 +4255,6 @@ pub fn @"nextUTF16NonASCIIOr$`\\"( return null; } -test "indexOfNotChar" { - { - var yes: [312]u8 = undefined; - for (0..yes.len) |i| { - @memset(yes, 'a'); - yes[i] = 'b'; - if (comptime Environment.allow_assert) assert(indexOfNotChar(&yes, 'a').? == i); - i += 1; - } - } -} - -test "trimLeadingChar" { - { - const yes = " fooo bar"; - try std.testing.expectEqualStrings(trimLeadingChar(yes, ' '), "fooo bar"); - } -} - -test "isAllASCII" { - const yes = "aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123"; - try std.testing.expectEqual(true, isAllASCII(yes)); - - const no = "aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdoka🙂sdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123"; - try std.testing.expectEqual(false, isAllASCII(no)); -} - -test "firstNonASCII" { - const yes = "aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123"; - try std.testing.expectEqual(true, firstNonASCII(yes) == null); - - { - const no = "aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdoka🙂sdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123"; - try std.testing.expectEqual(@as(u32, 50), firstNonASCII(no).?); - } - - { - const no = "aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd12312🙂3"; - try std.testing.expectEqual(@as(u32, 366), firstNonASCII(no).?); - } -} - -test "firstNonASCII16" { - @setEvalBranchQuota(99999); - const yes = std.mem.bytesAsSlice(u16, toUTF16Literal("aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123")); - try std.testing.expectEqual(true, firstNonASCII16(@TypeOf(yes), yes) == null); - - { - @setEvalBranchQuota(99999); - const no = std.mem.bytesAsSlice(u16, toUTF16Literal("aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdoka🙂sdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123")); - try std.testing.expectEqual(@as(u32, 50), firstNonASCII16(@TypeOf(no), no).?); - } - { - @setEvalBranchQuota(99999); - const no = std.mem.bytesAsSlice(u16, toUTF16Literal("🙂sdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123")); - try std.testing.expectEqual(@as(u32, 0), firstNonASCII16(@TypeOf(no), no).?); - } - { - @setEvalBranchQuota(99999); - const no = std.mem.bytesAsSlice(u16, toUTF16Literal("a🙂sdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123")); - try std.testing.expectEqual(@as(u32, 1), firstNonASCII16(@TypeOf(no), no).?); - } - { - @setEvalBranchQuota(99999); - const no = std.mem.bytesAsSlice(u16, toUTF16Literal("aspdokasdpokasdpokasd aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd123123aspdokasdpokasdpokasdaspdokasdpokasdpokasdaspdokasdpokasdpokasd12312🙂3")); - try std.testing.expectEqual(@as(u32, 366), firstNonASCII16(@TypeOf(no), no).?); - } -} - /// Convert potentially ill-formed UTF-8 or UTF-16 bytes to a Unicode Codepoint. /// - Invalid codepoints are replaced with `zero` parameter /// - Null bytes return 0 @@ -5149,62 +4849,6 @@ pub fn moveSlice(slice: string, from: string, to: string) string { return result; } -test "moveSlice" { - var input: string = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; - const cloned = try std.heap.page_allocator.dupe(u8, input); - - const slice = input[20..][0..10]; - - try std.testing.expectEqual(eqlLong(moveSlice(slice, input, cloned), slice, false), true); -} - -test "moveAllSlices" { - const Move = struct { - foo: string, - bar: string, - baz: string, - wrong: string, - }; - var input: string = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; - var move = Move{ .foo = input[20..], .bar = input[30..], .baz = input[10..20], .wrong = "baz" }; - var cloned = try std.heap.page_allocator.dupe(u8, input); - moveAllSlices(Move, &move, input, cloned); - const expected = Move{ .foo = cloned[20..], .bar = cloned[30..], .baz = cloned[10..20], .wrong = "bar" }; - try std.testing.expectEqual(move.foo.ptr, expected.foo.ptr); - try std.testing.expectEqual(move.bar.ptr, expected.bar.ptr); - try std.testing.expectEqual(move.baz.ptr, expected.baz.ptr); - try std.testing.expectEqual(move.foo.len, expected.foo.len); - try std.testing.expectEqual(move.bar.len, expected.bar.len); - try std.testing.expectEqual(move.baz.len, expected.baz.len); - try std.testing.expect(move.wrong.ptr != expected.wrong.ptr); -} - -test "join" { - const string_list = &[_]string{ "abc", "def", "123", "hello" }; - const list = try join(string_list, "-", std.heap.page_allocator); - try std.testing.expectEqualStrings("abc-def-123-hello", list); -} - -test "sortAsc" { - var string_list = [_]string{ "abc", "def", "123", "hello" }; - var sorted_string_list = [_]string{ "123", "abc", "def", "hello" }; - const sorted_join = try join(&sorted_string_list, "-", std.heap.page_allocator); - sortAsc(&string_list); - const string_join = try join(&string_list, "-", std.heap.page_allocator); - - try std.testing.expectEqualStrings(sorted_join, string_join); -} - -test "sortDesc" { - var string_list = [_]string{ "abc", "def", "123", "hello" }; - var sorted_string_list = [_]string{ "hello", "def", "abc", "123" }; - const sorted_join = try join(&sorted_string_list, "-", std.heap.page_allocator); - sortDesc(&string_list); - const string_join = try join(&string_list, "-", std.heap.page_allocator); - - try std.testing.expectEqualStrings(sorted_join, string_join); -} - pub usingnamespace @import("exact_size_matcher.zig"); pub const unicode_replacement = 0xFFFD; @@ -5214,14 +4858,6 @@ pub const unicode_replacement_str = brk: { break :brk out; }; -test "eqlCaseInsensitiveASCII" { - try std.testing.expect(eqlCaseInsensitiveASCII("abc", "ABC", true)); - try std.testing.expect(eqlCaseInsensitiveASCII("abc", "abc", true)); - try std.testing.expect(eqlCaseInsensitiveASCII("aBcD", "aBcD", true)); - try std.testing.expect(!eqlCaseInsensitiveASCII("aBcD", "NOOO", true)); - try std.testing.expect(!eqlCaseInsensitiveASCII("aBcD", "LENGTH CHECK", true)); -} - pub fn isIPAddress(input: []const u8) bool { var max_ip_address_buffer: [512]u8 = undefined; if (input.len > max_ip_address_buffer.len) return false; diff --git a/src/string_mutable.zig b/src/string_mutable.zig index 40cd995c30..9ff903e09f 100644 --- a/src/string_mutable.zig +++ b/src/string_mutable.zig @@ -447,29 +447,3 @@ pub const MutableString = struct { return bytes.len; } }; - -test "MutableString" { - const alloc = std.heap.page_allocator; - - var str = try MutableString.initCopy(alloc, "hello"); - try expect(str.eql("hello")); -} - -test "MutableString.ensureValidIdentifier" { - const alloc = std.heap.page_allocator; - - try std.testing.expectEqualStrings("jquery", try MutableString.ensureValidIdentifier("jquery", alloc)); - try std.testing.expectEqualStrings("jquery_foo", try MutableString.ensureValidIdentifier("jquery😋foo", alloc)); -} - -test "MutableString BufferedWriter" { - const alloc = std.heap.page_allocator; - - var str = try MutableString.init(alloc, 0); - var buffered_writer = str.bufferedWriter(); - var writer = buffered_writer.writer(); - try writer.writeAll("hello world hello world hello world hello world hello world hello world"); - try writer.context.flush(); - str = writer.context.context.*; - try std.testing.expectEqualStrings("hello world hello world hello world hello world hello world hello world", str.toOwnedSlice()); -} diff --git a/src/tagged_pointer.zig b/src/tagged_pointer.zig index 136aa70e68..fdcfb3d304 100644 --- a/src/tagged_pointer.zig +++ b/src/tagged_pointer.zig @@ -229,63 +229,3 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type { } }; } - -test "TaggedPointerUnion" { - const IntPrimitive = struct { val: u32 = 0 }; - const StringPrimitive = struct { val: []const u8 = "" }; - const Object = struct { blah: u32, val: u32 }; - // const Invalid = struct { - // wrong: bool = true, - // }; - const Union = TaggedPointerUnion(.{ IntPrimitive, StringPrimitive, Object }); - const str = try default_allocator.create(StringPrimitive); - str.* = StringPrimitive{ .val = "hello!" }; - var un = Union.init(str); - try std.testing.expect(un.is(StringPrimitive)); - try std.testing.expectEqualStrings(un.as(StringPrimitive).val, "hello!"); - try std.testing.expect(!un.is(IntPrimitive)); - const num = try default_allocator.create(IntPrimitive); - num.val = 9999; - - var un2 = Union.init(num); - - try std.testing.expect(un2.as(IntPrimitive).val == 9999); - - try std.testing.expect(un.tag() == .StringPrimitive); - try std.testing.expect(un2.tag() == .IntPrimitive); - - un2.repr.data = 0; - try std.testing.expect(un2.tag() != .IntPrimitive); - try std.testing.expect(un2.get(IntPrimitive) == null); - // try std.testing.expect(un2.is(Invalid) == false); -} - -test "TaggedPointer" { - const Hello = struct { - what: []const u8, - }; - - var hello_struct_ptr = try default_allocator.create(Hello); - hello_struct_ptr.* = Hello{ .what = "hiiii" }; - var tagged = TaggedPointer.init(hello_struct_ptr, 0); - try std.testing.expectEqual(tagged.get(Hello), hello_struct_ptr); - try std.testing.expectEqualStrings(tagged.get(Hello).what, hello_struct_ptr.what); - tagged = TaggedPointer.init(hello_struct_ptr, 100); - try std.testing.expectEqual(tagged.get(Hello), hello_struct_ptr); - try std.testing.expectEqualStrings(tagged.get(Hello).what, hello_struct_ptr.what); - tagged = TaggedPointer.init(hello_struct_ptr, std.math.maxInt(TagSize) - 500); - try std.testing.expectEqual(tagged.get(Hello), hello_struct_ptr); - try std.testing.expectEqual(tagged.data, std.math.maxInt(TagSize) - 500); - try std.testing.expectEqualStrings(tagged.get(Hello).what, hello_struct_ptr.what); - - var i: TagSize = 0; - while (i < std.math.maxInt(TagSize) - 1) : (i += 1) { - hello_struct_ptr = try default_allocator.create(Hello); - const what = try std.fmt.allocPrint(default_allocator, "hiiii {d}", .{i}); - hello_struct_ptr.* = Hello{ .what = what }; - try std.testing.expectEqualStrings(TaggedPointer.from(TaggedPointer.init(hello_struct_ptr, i).to()).get(Hello).what, what); - const this = TaggedPointer.from(TaggedPointer.init(hello_struct_ptr, i).to()); - try std.testing.expect(this.data == i); - try std.testing.expect(this.data != i + 1); - } -} diff --git a/src/thread_pool.zig b/src/thread_pool.zig index afe0efce07..283d640594 100644 --- a/src/thread_pool.zig +++ b/src/thread_pool.zig @@ -357,47 +357,6 @@ pub fn Do( wait_group.wait(); } -test "parallel for loop" { - Output.initTest(); - var thread_pool = ThreadPool.init(.{ .max_threads = 12 }); - const sleepy_time: u32 = 100; - const huge_array = &[_]u32{ - sleepy_time + std.rand.DefaultPrng.init(1).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(2).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(3).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(4).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(5).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(6).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(7).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(8).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(9).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(10).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(11).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(12).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(13).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(14).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(15).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(16).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(17).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(18).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(19).random().uintAtMost(u32, 20), - sleepy_time + std.rand.DefaultPrng.init(20).random().uintAtMost(u32, 20), - }; - const Runner = struct { - completed: usize = 0, - total: usize = 0, - pub fn run(ctx: *@This(), value: u32, _: usize) void { - std.time.sleep(value); - ctx.completed += 1; - bun.assert(ctx.completed <= ctx.total); - } - }; - const runny = try std.heap.page_allocator.create(Runner); - runny.* = .{ .total = huge_array.len }; - try thread_pool.doAndWait(std.heap.page_allocator, null, runny, Runner.run, std.mem.span(huge_array)); - try std.testing.expectEqual(huge_array.len, runny.completed); -} - /// Schedule a batch of tasks to be executed by some thread on the thread pool. pub fn schedule(self: *ThreadPool, batch: Batch) void { // Sanity check diff --git a/src/url.zig b/src/url.zig index ba1de42f1a..69e8e668c4 100644 --- a/src/url.zig +++ b/src/url.zig @@ -1442,473 +1442,4 @@ pub const Scanner = struct { const expect = std.testing.expect; const expectString = std.testing.expectEqualStrings; -test "Scanner.init" { - var scanner = Scanner.init("?hello=true"); - try expect(scanner.i == 1); - scanner = Scanner.init("hello=true"); - try expect(scanner.i == 0); -} - -test "Scanner.next" { - var scanner = Scanner.init("?hello=true&welcome=to&the=what&is=this&1=100&&&&bacon&&&&what=true&ok&=100"); - var result: Scanner.Result = undefined; - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding == false); - try expect(result.value_needs_decoding == false); - try expectString(result.rawName(scanner.query_string), "hello"); - try expectString(result.rawValue(scanner.query_string), "true"); - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding == false); - try expect(result.value_needs_decoding == false); - try expectString(result.rawName(scanner.query_string), "welcome"); - try expectString(result.rawValue(scanner.query_string), "to"); - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding == false); - try expect(result.value_needs_decoding == false); - try expectString(result.rawName(scanner.query_string), "the"); - try expectString(result.rawValue(scanner.query_string), "what"); - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding == false); - try expect(result.value_needs_decoding == false); - try expectString(result.rawName(scanner.query_string), "is"); - try expectString(result.rawValue(scanner.query_string), "this"); - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding == false); - try expect(result.value_needs_decoding == false); - try expectString(result.rawName(scanner.query_string), "1"); - try expectString(result.rawValue(scanner.query_string), "100"); - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding == false); - try expect(result.value_needs_decoding == false); - try expectString(result.rawName(scanner.query_string), "bacon"); - try expectString(result.rawValue(scanner.query_string), ""); - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding == false); - try expect(result.value_needs_decoding == false); - try expectString(result.rawName(scanner.query_string), "what"); - try expectString(result.rawValue(scanner.query_string), "true"); - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding == false); - try expect(result.value_needs_decoding == false); - try expectString(result.rawName(scanner.query_string), "ok"); - try expectString(result.rawValue(scanner.query_string), ""); - try expect(scanner.next() == null); -} - -test "Scanner.next - % encoded" { - var scanner = Scanner.init("?foo%20=%201023%20&%20what%20the%20fuck%20=%20am%20i%20looking%20at"); - var result: Scanner.Result = undefined; - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding); - try expect(result.value_needs_decoding); - try expectString(result.rawName(scanner.query_string), "foo%20"); - try expectString(result.rawValue(scanner.query_string), "%201023%20"); - result = scanner.next() orelse return try std.testing.expect(false); - try expect(result.name_needs_decoding); - try expect(result.value_needs_decoding); - try expectString(result.rawName(scanner.query_string), "%20what%20the%20fuck%20"); - try expectString(result.rawValue(scanner.query_string), "%20am%20i%20looking%20at"); - try expect(scanner.next() == null); -} - -test "PercentEncoding.decode" { - var buffer: [4096]u8 = undefined; - @memset(&buffer, 0); - - var stream = std.io.fixedBufferStream(&buffer); - const writer = stream.writer(); - const Writer = @TypeOf(writer); - - { - const written = try PercentEncoding.decode(Writer, writer, "hello%20world%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B"); - const correct = "hello world + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; - try expect(written == correct.len); - try expectString(buffer[0..written], correct); - } - - stream.reset(); - - { - const correct = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - const written = try PercentEncoding.decode(Writer, writer, correct); - try expect(written == correct.len); - try expectString(buffer[0..written], correct); - } - - stream.reset(); - - { - const correct = "hello my name is ?????"; - const written = try PercentEncoding.decode(Writer, writer, correct); - try expect(written == correct.len); - try expectString(buffer[0..written], correct); - } -} - -test "QueryStringMap (full)" { - - // This is copy pasted from a random twitter thread on Chrome - const url = "?cards_platform=Web-12&include_cards=1&include_ext_alt_text=true&include_quote_count=true&include_reply_count=1&tweet_mode=extended&dm_users=false&include_groups=true&include_inbox_timelines=true&include_ext_media_color=true&supports_reactions=true&muting_enabled=false&nsfw_filtering_enabled=false&cursor=GRwmkMCq6fLUnMAnFpDAquny1JzAJyUAAAA&filter_low_quality=true&include_quality=all&ext=mediaColor&ext=altText&ext=mediaStats&ext=highlightedLabel&ext=voiceInfo"; - // from chrome's devtools - const fixture = .{ - .cards_platform = "Web-12", - .include_cards = "1", - .include_ext_alt_text = "true", - .include_quote_count = "true", - .include_reply_count = "1", - .tweet_mode = "extended", - .dm_users = "false", - .include_groups = "true", - .include_inbox_timelines = "true", - .include_ext_media_color = "true", - .supports_reactions = "true", - .muting_enabled = "false", - .nsfw_filtering_enabled = "false", - .cursor = "GRwmkMCq6fLUnMAnFpDAquny1JzAJyUAAAA", - .filter_low_quality = "true", - .include_quality = "all", - .ext = &[_]string{ "mediaColor", "altText", "mediaStats", "highlightedLabel", "voiceInfo" }, - }; - - var map = (try QueryStringMap.init(std.testing.allocator, url)) orelse return try std.testing.expect(false); - defer map.deinit(); - try expectString(fixture.cards_platform, map.get("cards_platform").?); - try expectString(fixture.include_cards, map.get("include_cards").?); - try expectString(fixture.include_ext_alt_text, map.get("include_ext_alt_text").?); - try expectString(fixture.include_quote_count, map.get("include_quote_count").?); - try expectString(fixture.include_reply_count, map.get("include_reply_count").?); - try expectString(fixture.tweet_mode, map.get("tweet_mode").?); - try expectString(fixture.dm_users, map.get("dm_users").?); - try expectString(fixture.include_groups, map.get("include_groups").?); - try expectString(fixture.include_inbox_timelines, map.get("include_inbox_timelines").?); - try expectString(fixture.include_ext_media_color, map.get("include_ext_media_color").?); - try expectString(fixture.supports_reactions, map.get("supports_reactions").?); - try expectString(fixture.muting_enabled, map.get("muting_enabled").?); - try expectString(fixture.nsfw_filtering_enabled, map.get("nsfw_filtering_enabled").?); - try expectString(fixture.cursor, map.get("cursor").?); - try expectString(fixture.filter_low_quality, map.get("filter_low_quality").?); - try expectString(fixture.include_quality, map.get("include_quality").?); - try expectString(fixture.ext[0], map.get("ext").?); - - var target: [fixture.ext.len]string = undefined; - try expect((map.getAll("ext", &target)) == fixture.ext.len); - - for (target, 0..) |item, i| { - try expectString( - fixture.ext[i], - item, - ); - } -} - -test "QueryStringMap not encoded" { - const url = "?hey=1&wow=true"; - const fixture = .{ - .hey = "1", - .wow = "true", - }; - const url_slice = bun.asByteSlice(url); - var map = (try QueryStringMap.init(std.testing.allocator, url_slice)) orelse return try std.testing.expect(false); - try expect(map.buffer.len == 0); - try expect(url_slice.ptr == map.slice.ptr); - defer map.deinit(); - try expectString(fixture.hey, map.get("hey").?); - try expectString(fixture.wow, map.get("wow").?); -} const expectEqual = std.testing.expectEqual; -test "QueryStringMap Iterator" { - // This is copy pasted from a random twitter thread on Chrome - // The only difference from the one above is "ext" is moved before the last one - // This is to test order of iteration - const url = "?cards_platform=Web-12&include_cards=1&include_ext_alt_text=true&include_quote_count=true&include_reply_count=1&tweet_mode=extended&dm_users=false&include_groups=true&include_inbox_timelines=true&include_ext_media_color=true&supports_reactions=true&muting_enabled=false&nsfw_filtering_enabled=false&cursor=GRwmkMCq6fLUnMAnFpDAquny1JzAJyUAAAA&filter_low_quality=true&ext=voiceInfo&include_quality=all&ext=mediaColor&ext=altText&ext=mediaStats&ext=highlightedLabel"; - // from chrome's devtools - const fixture = .{ - .cards_platform = "Web-12", - .include_cards = "1", - .include_ext_alt_text = "true", - .include_quote_count = "true", - .include_reply_count = "1", - .tweet_mode = "extended", - .dm_users = "false", - .include_groups = "true", - .include_inbox_timelines = "true", - .include_ext_media_color = "true", - .supports_reactions = "true", - .muting_enabled = "false", - .nsfw_filtering_enabled = "false", - .cursor = "GRwmkMCq6fLUnMAnFpDAquny1JzAJyUAAAA", - .filter_low_quality = "true", - .include_quality = "all", - .ext = &[_]string{ - "voiceInfo", - "mediaColor", - "altText", - "mediaStats", - "highlightedLabel", - }, - }; - - var map = (try QueryStringMap.init(std.testing.allocator, url)) orelse return try std.testing.expect(false); - defer map.deinit(); - var buf_: [48]string = undefined; - const buf = buf_[0..48]; - var iter = map.iter(); - - var result: QueryStringMap.Iterator.Result = iter.next(buf) orelse return try expect(false); - try expectString("cards_platform", result.name); - try expectString(fixture.cards_platform, result.values[0]); - try expectEqual(result.values.len, 1); - - result = iter.next(buf) orelse return try expect(false); - try expectString("include_cards", result.name); - try expectString(fixture.include_cards, result.values[0]); - try expectEqual(result.values.len, 1); - - result = iter.next(buf) orelse return try expect(false); - try expectString("include_ext_alt_text", result.name); - try expectString(fixture.include_ext_alt_text, result.values[0]); - try expectEqual(result.values.len, 1); - - result = iter.next(buf) orelse return try expect(false); - try expectString("include_quote_count", result.name); - try expectString(fixture.include_quote_count, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("include_reply_count", result.name); - try expectString(fixture.include_reply_count, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("tweet_mode", result.name); - try expectString(fixture.tweet_mode, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("dm_users", result.name); - try expectString(fixture.dm_users, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("include_groups", result.name); - try expectString(fixture.include_groups, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("include_inbox_timelines", result.name); - try expectString(fixture.include_inbox_timelines, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("include_ext_media_color", result.name); - try expectString(fixture.include_ext_media_color, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("supports_reactions", result.name); - try expectString(fixture.supports_reactions, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("muting_enabled", result.name); - try expectString(fixture.muting_enabled, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("nsfw_filtering_enabled", result.name); - try expectString(fixture.nsfw_filtering_enabled, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("cursor", result.name); - try expectString(fixture.cursor, result.values[0]); - try expectEqual(result.values.len, 1); - result = iter.next(buf) orelse return try expect(false); - try expectString("filter_low_quality", result.name); - try expectString(fixture.filter_low_quality, result.values[0]); - try expectEqual(result.values.len, 1); - - result = iter.next(buf) orelse return try expect(false); - try expectString("ext", result.name); - try expectEqual(result.values.len, fixture.ext.len); - for (fixture.ext, 0..) |ext, i| { - try expectString(ext, result.values[i]); - } - - result = iter.next(buf) orelse return try expect(false); - try expectString("include_quality", result.name); - try expectString(fixture.include_quality, result.values[0]); - try expectEqual(result.values.len, 1); - - try expect(iter.next(buf) == null); -} - -test "URL - parse" { - var url: URL = undefined; - - url = URL.parse("https://url.spec.whatwg.org/foo#include-credentials"); - try expectString("https", url.protocol); - try expectString("url.spec.whatwg.org", url.host); - try expectString("/foo", url.pathname); - try expectString("#include-credentials", url.hash); - - url = URL.parse("https://url.spec.whatwg.org/#include-credentials"); - try expectString("https", url.protocol); - try expectString("url.spec.whatwg.org", url.host); - try expectString("/", url.pathname); - try expectString("#include-credentials", url.hash); - - url = URL.parse("://url.spec.whatwg.org/#include-credentials"); - try expectString("", url.protocol); - try expectString("url.spec.whatwg.org", url.host); - try expectString("/", url.pathname); - try expectString("#include-credentials", url.hash); - - url = URL.parse("/#include-credentials"); - try expectString("", url.protocol); - try expectString("", url.host); - try expectString("/", url.pathname); - try expectString("#include-credentials", url.hash); - - url = URL.parse("https://username:password@url.spec.whatwg.org/#include-credentials"); - try expectString("https", url.protocol); - try expectString("username", url.username); - try expectString("password", url.password); - try expectString("url.spec.whatwg.org", url.host); - try expectString("/", url.pathname); - try expectString("#include-credentials", url.hash); - - url = URL.parse("https://username:password@url.spec.whatwg.org:3000/#include-credentials"); - try expectString("https", url.protocol); - try expectString("username", url.username); - try expectString("password", url.password); - try expectString("url.spec.whatwg.org:3000", url.host); - try expectString("3000", url.port); - try expectString("/", url.pathname); - try expectString("#include-credentials", url.hash); - - url = URL.parse("example.com/#include-credentials"); - try expectString("", url.protocol); - try expectString("", url.username); - try expectString("", url.password); - try expectString("example.com", url.host); - try expectString("/", url.pathname); - try expectString("#include-credentials", url.hash); - - url = URL.parse("example.com:8080/#include-credentials"); - try expectString("", url.protocol); - try expectString("", url.username); - try expectString("", url.password); - try expectString("example.com:8080", url.host); - try expectString("example.com", url.hostname); - try expectString("8080", url.port); - try expectString("/", url.pathname); - try expectString("#include-credentials", url.hash); - - url = URL.parse("/src/index"); - try expectString("", url.protocol); - try expectString("", url.username); - try expectString("", url.password); - try expectString("", url.host); - try expectString("", url.hostname); - try expectString("", url.port); - try expectString("/src/index", url.path); - try expectString("/src/index", url.pathname); - - try expectString("", url.hash); - try expectString("", url.search); - - url = URL.parse("http://localhost:3000/"); - try expectString("http", url.protocol); - try expectString("", url.username); - try expectString("", url.password); - try expectString("localhost:3000", url.host); - try expectString("localhost", url.hostname); - try expectString("3000", url.port); - try expectString("/", url.path); - try expectString("/", url.pathname); - - url = URL.parse("https://covid19.who.int/WHO-COVID-19-global-data.csv"); - try expectString("https", url.protocol); - try expectString("", url.username); - try expectString("", url.password); - try expectString("covid19.who.int", url.host); - try expectString("covid19.who.int", url.hostname); - // try expectString("443", url.port); - try expectString("/WHO-COVID-19-global-data.csv", url.path); - try expectString("/WHO-COVID-19-global-data.csv", url.pathname); - - url = URL.parse("http://localhost:3000/@/example"); - try expectString("http", url.protocol); - try expectString("", url.username); - try expectString("", url.password); - try expectString("localhost:3000", url.host); - try expectString("localhost", url.hostname); - try expectString("3000", url.port); - try expectString("/@/example", url.path); - try expectString("/@/example", url.pathname); - - url = URL.parse("http://admin:password@localhost:3000/@/example"); - try expectString("http", url.protocol); - try expectString("admin", url.username); - try expectString("password", url.password); - try expectString("localhost:3000", url.host); - try expectString("localhost", url.hostname); - try expectString("3000", url.port); - try expectString("/@/example", url.path); - try expectString("/@/example", url.pathname); - - url = URL.parse("http://0.0.0.0:3000/@/example"); - try expectString("http", url.protocol); - try expectString("", url.username); - try expectString("", url.password); - try expectString("0.0.0.0:3000", url.host); - try expectString("0.0.0.0", url.hostname); - try expectString("3000", url.port); - try expectString("/@/example", url.path); - try expectString("/@/example", url.pathname); - - url = URL.parse("http://admin:password@0.0.0.0:3000/@/example"); - try expectString("http", url.protocol); - try expectString("admin", url.username); - try expectString("password", url.password); - try expectString("0.0.0.0:3000", url.host); - try expectString("0.0.0.0", url.hostname); - try expectString("3000", url.port); - try expectString("/@/example", url.path); - try expectString("/@/example", url.pathname); - - url = URL.parse("http://admin:password@0.0.0.0:3000"); - try expectString("http", url.protocol); - try expectString("admin", url.username); - try expectString("password", url.password); - try expectString("0.0.0.0:3000", url.host); - try expectString("0.0.0.0", url.hostname); - try expectString("3000", url.port); - - url = URL.parse("http://admin:password@0.0.0.0:3000/"); - try expectString("http", url.protocol); - try expectString("admin", url.username); - try expectString("password", url.password); - try expectString("0.0.0.0:3000", url.host); - try expectString("0.0.0.0", url.hostname); - try expectString("3000", url.port); - - url = URL.parse("http://admin:password@0.0.0.0:3000/@bacon"); - try expectString("http", url.protocol); - try expectString("admin", url.username); - try expectString("password", url.password); - try expectString("0.0.0.0:3000", url.host); - try expectString("0.0.0.0", url.hostname); - try expectString("3000", url.port); - try expectString("/@bacon", url.pathname); -} - -test "URL - joinAlloc" { - var url = URL.parse("http://localhost:3000"); - - var absolute_url = try url.joinAlloc(default_allocator, "/_next/", "src/components", "button", ".js", ""); - try expectString( - "http://localhost:3000/_next/src/components/button.js", - absolute_url, - ); - - absolute_url = try url.joinAlloc(default_allocator, "compiled-", "src/components", "button", ".js", ""); - try expectString( - "http://localhost:3000/compiled-src/components/button.js", - absolute_url, - ); - - absolute_url = try url.joinAlloc(default_allocator, "compiled-", "", "button", ".js", ""); - try expectString("http://localhost:3000/compiled-button.js", absolute_url); -} diff --git a/src/util.zig b/src/util.zig index da52409d56..30a42a3b3f 100644 --- a/src/util.zig +++ b/src/util.zig @@ -280,54 +280,6 @@ pub fn Batcher(comptime Type: type) type { }; } -test "fromEntries" { - const values = try from(std.AutoHashMap(u32, u32), std.heap.page_allocator, .{ - .{ 123, 456 }, - .{ 789, 101112 }, - }); - const mapToMap = try from(std.AutoHashMap(u32, u32), std.heap.page_allocator, values); - try std.testing.expectEqual(values.get(123).?, 456); - try std.testing.expectEqual(values.get(789).?, 101112); - try std.testing.expectEqual(mapToMap.get(123).?, 456); - try std.testing.expectEqual(mapToMap.get(789).?, 101112); -} - -test "from" { - const values = try from( - []const u32, - std.heap.page_allocator, - &.{ 1, 2, 3, 4, 5, 6 }, - ); - try std.testing.expectEqualSlices(u32, &.{ 1, 2, 3, 4, 5, 6 }, values); -} - -test "from arraylist" { - const values = try from( - std.ArrayList(u32), - std.heap.page_allocator, - &.{ 1, 2, 3, 4, 5, 6 }, - ); - try std.testing.expectEqualSlices(u32, &.{ 1, 2, 3, 4, 5, 6 }, values.items); - - const cloned = try from( - std.ArrayListUnmanaged(u32), - std.heap.page_allocator, - values, - ); - - try std.testing.expectEqualSlices(u32, &.{ 1, 2, 3, 4, 5, 6 }, cloned.items); -} - -test "from arraylist with struct" { - const Entry = std.meta.Tuple(&.{ u32, u32 }); - const values = try from( - std.ArrayList(Entry), - std.heap.page_allocator, - &.{ Entry{ 123, 456 }, Entry{ 123, 456 }, Entry{ 123, 456 }, Entry{ 123, 456 } }, - ); - try std.testing.expectEqualSlices(Entry, &[_]Entry{ .{ 123, 456 }, .{ 123, 456 }, .{ 123, 456 }, .{ 123, 456 } }, values.items); -} - fn needsAllocator(comptime Fn: anytype) bool { return std.meta.fields(std.meta.ArgsTuple(@TypeOf(Fn))).len > 2; } diff --git a/src/which.zig b/src/which.zig index 5aaaa8cd0f..98da0828e0 100644 --- a/src/which.zig +++ b/src/which.zig @@ -168,14 +168,3 @@ pub fn whichWin(buf: *bun.WPathBuffer, path: []const u8, cwd: []const u8, bin: [ return null; } - -test "which" { - var buf: bun.fs.PathBuffer = undefined; - const realpath = bun.getenvZ("PATH") orelse unreachable; - const whichbin = which(&buf, realpath, try bun.getcwdAlloc(std.heap.c_allocator), "which"); - try std.testing.expectEqualStrings(whichbin orelse return bun.assert(false), "/usr/bin/which"); - try std.testing.expect(null == which(&buf, realpath, try bun.getcwdAlloc(std.heap.c_allocator), "baconnnnnn")); - try std.testing.expect(null != which(&buf, realpath, try bun.getcwdAlloc(std.heap.c_allocator), "zig")); - try std.testing.expect(null == which(&buf, realpath, try bun.getcwdAlloc(std.heap.c_allocator), "bin")); - try std.testing.expect(null == which(&buf, realpath, try bun.getcwdAlloc(std.heap.c_allocator), "usr")); -} diff --git a/src/zlib.zig b/src/zlib.zig index 4a871ab72a..05a42be769 100644 --- a/src/zlib.zig +++ b/src/zlib.zig @@ -7,34 +7,6 @@ const mimalloc = @import("./allocators/mimalloc.zig"); pub const MAX_WBITS = 15; -test "Zlib Read" { - const expected_text = @embedFile("./zlib.test.txt"); - const input = bun.asByteSlice(@embedFile("./zlib.test.gz")); - std.debug.print("zStream Size: {d}", .{@sizeOf(zStream_struct)}); - var output = std.ArrayList(u8).init(std.heap.c_allocator); - var writer = output.writer(); - const ZlibReader = NewZlibReader(@TypeOf(&writer), 4096); - - var reader = try ZlibReader.init(&writer, input, std.heap.c_allocator); - defer reader.deinit(); - try reader.readAll(); - - try std.testing.expectEqualStrings(expected_text, output.items); -} - -test "ZlibArrayList Read" { - const expected_text = @embedFile("./zlib.test.txt"); - const input = bun.asByteSlice(@embedFile("./zlib.test.gz")); - std.debug.print("zStream Size: {d}", .{@sizeOf(zStream_struct)}); - var list = std.ArrayListUnmanaged(u8){}; - try list.ensureUnusedCapacity(std.heap.c_allocator, 4096); - var reader = try ZlibReaderArrayList.init(input, &list, std.heap.c_allocator); - defer reader.deinit(); - try reader.readAll(); - - try std.testing.expectEqualStrings(expected_text, list.items); -} - pub extern fn zlibVersion() [*c]const u8; pub extern fn compress(dest: [*]Bytef, destLen: *uLongf, source: [*]const Bytef, sourceLen: uLong) c_int;