| ... | ... | @@ -83,8 +83,12 @@ const HeaderEntry = struct { |
| 83 | 83 | } |
| 84 | 84 | }; |
| 85 | 85 | |
| 86 | var test_memory: [32 * 1024]u8 = undefined; |
| 87 | var test_fba_state = std.heap.FixedBufferAllocator.init(&test_memory); |
| 88 | const test_allocator = &test_fba_state.allocator; |
| 89 | |
| 86 | 90 | test "HeaderEntry" { |
| 87 | | var e = try HeaderEntry.init(debug.global_allocator, "foo", "bar", null); |
| 91 | var e = try HeaderEntry.init(test_allocator, "foo", "bar", null); |
| 88 | 92 | defer e.deinit(); |
| 89 | 93 | testing.expectEqualSlices(u8, "foo", e.name); |
| 90 | 94 | testing.expectEqualSlices(u8, "bar", e.value); |
| ... | ... | @@ -376,7 +380,7 @@ pub const Headers = struct { |
| 376 | 380 | }; |
| 377 | 381 | |
| 378 | 382 | test "Headers.iterator" { |
| 379 | | var h = Headers.init(debug.global_allocator); |
| 383 | var h = Headers.init(test_allocator); |
| 380 | 384 | defer h.deinit(); |
| 381 | 385 | try h.append("foo", "bar", null); |
| 382 | 386 | try h.append("cookie", "somevalue", null); |
| ... | ... | @@ -399,7 +403,7 @@ test "Headers.iterator" { |
| 399 | 403 | } |
| 400 | 404 | |
| 401 | 405 | test "Headers.contains" { |
| 402 | | var h = Headers.init(debug.global_allocator); |
| 406 | var h = Headers.init(test_allocator); |
| 403 | 407 | defer h.deinit(); |
| 404 | 408 | try h.append("foo", "bar", null); |
| 405 | 409 | try h.append("cookie", "somevalue", null); |
| ... | ... | @@ -409,7 +413,7 @@ test "Headers.contains" { |
| 409 | 413 | } |
| 410 | 414 | |
| 411 | 415 | test "Headers.delete" { |
| 412 | | var h = Headers.init(debug.global_allocator); |
| 416 | var h = Headers.init(test_allocator); |
| 413 | 417 | defer h.deinit(); |
| 414 | 418 | try h.append("foo", "bar", null); |
| 415 | 419 | try h.append("baz", "qux", null); |
| ... | ... | @@ -437,7 +441,7 @@ test "Headers.delete" { |
| 437 | 441 | } |
| 438 | 442 | |
| 439 | 443 | test "Headers.orderedRemove" { |
| 440 | | var h = Headers.init(debug.global_allocator); |
| 444 | var h = Headers.init(test_allocator); |
| 441 | 445 | defer h.deinit(); |
| 442 | 446 | try h.append("foo", "bar", null); |
| 443 | 447 | try h.append("baz", "qux", null); |
| ... | ... | @@ -460,7 +464,7 @@ test "Headers.orderedRemove" { |
| 460 | 464 | } |
| 461 | 465 | |
| 462 | 466 | test "Headers.swapRemove" { |
| 463 | | var h = Headers.init(debug.global_allocator); |
| 467 | var h = Headers.init(test_allocator); |
| 464 | 468 | defer h.deinit(); |
| 465 | 469 | try h.append("foo", "bar", null); |
| 466 | 470 | try h.append("baz", "qux", null); |
| ... | ... | @@ -483,7 +487,7 @@ test "Headers.swapRemove" { |
| 483 | 487 | } |
| 484 | 488 | |
| 485 | 489 | test "Headers.at" { |
| 486 | | var h = Headers.init(debug.global_allocator); |
| 490 | var h = Headers.init(test_allocator); |
| 487 | 491 | defer h.deinit(); |
| 488 | 492 | try h.append("foo", "bar", null); |
| 489 | 493 | try h.append("cookie", "somevalue", null); |
| ... | ... | @@ -503,7 +507,7 @@ test "Headers.at" { |
| 503 | 507 | } |
| 504 | 508 | |
| 505 | 509 | test "Headers.getIndices" { |
| 506 | | var h = Headers.init(debug.global_allocator); |
| 510 | var h = Headers.init(test_allocator); |
| 507 | 511 | defer h.deinit(); |
| 508 | 512 | try h.append("foo", "bar", null); |
| 509 | 513 | try h.append("set-cookie", "x=1", null); |
| ... | ... | @@ -515,27 +519,27 @@ test "Headers.getIndices" { |
| 515 | 519 | } |
| 516 | 520 | |
| 517 | 521 | test "Headers.get" { |
| 518 | | var h = Headers.init(debug.global_allocator); |
| 522 | var h = Headers.init(test_allocator); |
| 519 | 523 | defer h.deinit(); |
| 520 | 524 | try h.append("foo", "bar", null); |
| 521 | 525 | try h.append("set-cookie", "x=1", null); |
| 522 | 526 | try h.append("set-cookie", "y=2", null); |
| 523 | 527 | |
| 524 | 528 | { |
| 525 | | const v = try h.get(debug.global_allocator, "not-present"); |
| 529 | const v = try h.get(test_allocator, "not-present"); |
| 526 | 530 | testing.expect(null == v); |
| 527 | 531 | } |
| 528 | 532 | { |
| 529 | | const v = (try h.get(debug.global_allocator, "foo")).?; |
| 530 | | defer debug.global_allocator.free(v); |
| 533 | const v = (try h.get(test_allocator, "foo")).?; |
| 534 | defer test_allocator.free(v); |
| 531 | 535 | const e = v[0]; |
| 532 | 536 | testing.expectEqualSlices(u8, "foo", e.name); |
| 533 | 537 | testing.expectEqualSlices(u8, "bar", e.value); |
| 534 | 538 | testing.expectEqual(false, e.never_index); |
| 535 | 539 | } |
| 536 | 540 | { |
| 537 | | const v = (try h.get(debug.global_allocator, "set-cookie")).?; |
| 538 | | defer debug.global_allocator.free(v); |
| 541 | const v = (try h.get(test_allocator, "set-cookie")).?; |
| 542 | defer test_allocator.free(v); |
| 539 | 543 | { |
| 540 | 544 | const e = v[0]; |
| 541 | 545 | testing.expectEqualSlices(u8, "set-cookie", e.name); |
| ... | ... | @@ -552,30 +556,30 @@ test "Headers.get" { |
| 552 | 556 | } |
| 553 | 557 | |
| 554 | 558 | test "Headers.getCommaSeparated" { |
| 555 | | var h = Headers.init(debug.global_allocator); |
| 559 | var h = Headers.init(test_allocator); |
| 556 | 560 | defer h.deinit(); |
| 557 | 561 | try h.append("foo", "bar", null); |
| 558 | 562 | try h.append("set-cookie", "x=1", null); |
| 559 | 563 | try h.append("set-cookie", "y=2", null); |
| 560 | 564 | |
| 561 | 565 | { |
| 562 | | const v = try h.getCommaSeparated(debug.global_allocator, "not-present"); |
| 566 | const v = try h.getCommaSeparated(test_allocator, "not-present"); |
| 563 | 567 | testing.expect(null == v); |
| 564 | 568 | } |
| 565 | 569 | { |
| 566 | | const v = (try h.getCommaSeparated(debug.global_allocator, "foo")).?; |
| 567 | | defer debug.global_allocator.free(v); |
| 570 | const v = (try h.getCommaSeparated(test_allocator, "foo")).?; |
| 571 | defer test_allocator.free(v); |
| 568 | 572 | testing.expectEqualSlices(u8, "bar", v); |
| 569 | 573 | } |
| 570 | 574 | { |
| 571 | | const v = (try h.getCommaSeparated(debug.global_allocator, "set-cookie")).?; |
| 572 | | defer debug.global_allocator.free(v); |
| 575 | const v = (try h.getCommaSeparated(test_allocator, "set-cookie")).?; |
| 576 | defer test_allocator.free(v); |
| 573 | 577 | testing.expectEqualSlices(u8, "x=1,y=2", v); |
| 574 | 578 | } |
| 575 | 579 | } |
| 576 | 580 | |
| 577 | 581 | test "Headers.sort" { |
| 578 | | var h = Headers.init(debug.global_allocator); |
| 582 | var h = Headers.init(test_allocator); |
| 579 | 583 | defer h.deinit(); |
| 580 | 584 | try h.append("foo", "bar", null); |
| 581 | 585 | try h.append("cookie", "somevalue", null); |
| ... | ... | @@ -596,7 +600,7 @@ test "Headers.sort" { |
| 596 | 600 | } |
| 597 | 601 | |
| 598 | 602 | test "Headers.format" { |
| 599 | | var h = Headers.init(debug.global_allocator); |
| 603 | var h = Headers.init(test_allocator); |
| 600 | 604 | defer h.deinit(); |
| 601 | 605 | try h.append("foo", "bar", null); |
| 602 | 606 | try h.append("cookie", "somevalue", null); |