|
1 |
| -import {makeQueryTemplate, __table} from "../src/table.js"; |
| 1 | +import {getTypeValidator, makeQueryTemplate, __table} from "../src/table.js"; |
2 | 2 | import assert from "assert";
|
3 | 3 |
|
4 | 4 | export const EMPTY_TABLE_DATA = {
|
@@ -542,3 +542,85 @@ describe("__table", () => {
|
542 | 542 | );
|
543 | 543 | });
|
544 | 544 | });
|
| 545 | + |
| 546 | +describe("getTypeValidator filters accurately", () => { |
| 547 | + let source = [ |
| 548 | + {label: "string", value: "string"}, |
| 549 | + {label: "object", value: {}}, |
| 550 | + {label: "buffer", value: new ArrayBuffer()}, |
| 551 | + {label: "boolean", value: true}, |
| 552 | + {label: "array", value: [1, 2, 3]}, |
| 553 | + {label: "number", value: 10}, |
| 554 | + {label: "date", value: new Date(1)}, |
| 555 | + // eslint-disable-next-line no-undef |
| 556 | + {label: "bigint", value: BigInt(10)}, |
| 557 | + {label: "null", value: null}, |
| 558 | + {label: "NaN", value: NaN}, |
| 559 | + {label: "undefined"} |
| 560 | + ]; |
| 561 | + |
| 562 | + it("filters strings", () => { |
| 563 | + const isValid = getTypeValidator("string"); |
| 564 | + assert.deepStrictEqual(source.filter(d => isValid(d.value)), [{label: "string", value: "string"}]); |
| 565 | + }); |
| 566 | + |
| 567 | + it("filters buffers", () => { |
| 568 | + const isValid = getTypeValidator("buffer"); |
| 569 | + assert.deepStrictEqual(source.filter(d => isValid(d.value)), [{label: "buffer", value: new ArrayBuffer()}]); |
| 570 | + }); |
| 571 | + |
| 572 | + it("filters numbers", () => { |
| 573 | + const isValid = getTypeValidator("number"); |
| 574 | + assert.deepStrictEqual(source.filter(d => isValid(d.value)), [{label: "number", value: 10}]); |
| 575 | + }); |
| 576 | + |
| 577 | + it("filters booleans", () => { |
| 578 | + const isValid = getTypeValidator("boolean"); |
| 579 | + assert.deepStrictEqual(source.filter(d => isValid(d.value)), [{label: "boolean", value: true}]); |
| 580 | + }); |
| 581 | + |
| 582 | + it("filters arrays", () => { |
| 583 | + const isValid = getTypeValidator("array"); |
| 584 | + assert.deepStrictEqual(source.filter(d => isValid(d.value)), [{label: "array", value: [1, 2, 3]}]); |
| 585 | + }); |
| 586 | + |
| 587 | + it("filters dates", () => { |
| 588 | + const isValid = getTypeValidator("date"); |
| 589 | + assert.deepStrictEqual(source.filter(d => isValid(d.value)), [{label: "date", value: new Date(1)}]); |
| 590 | + }); |
| 591 | + |
| 592 | + it("filters BigInts", () => { |
| 593 | + const isValid = getTypeValidator("bigint"); |
| 594 | + // eslint-disable-next-line no-undef |
| 595 | + assert.deepStrictEqual(source.filter(d => isValid(d.value)), [{label: "bigint", value: BigInt(10)}]); |
| 596 | + }); |
| 597 | + |
| 598 | + it("filters objects", () => { |
| 599 | + const isValid = getTypeValidator("object"); |
| 600 | + assert.deepStrictEqual(source.filter(d => isValid(d.value)), |
| 601 | + [ |
| 602 | + {label: "object", value: {}}, |
| 603 | + {label: "buffer", value: new ArrayBuffer()}, |
| 604 | + {label: "array", value: [1, 2, 3]}, |
| 605 | + {label: "date", value: new Date(1)}] |
| 606 | + ); |
| 607 | + }); |
| 608 | + |
| 609 | + it("filters other", () => { |
| 610 | + const isValid = getTypeValidator("other"); |
| 611 | + assert.deepStrictEqual(source.filter(d => isValid(d.value)), |
| 612 | + [ |
| 613 | + {label: "string", value: "string"}, |
| 614 | + {label: "object", value: {}}, |
| 615 | + {label: "buffer", value: new ArrayBuffer()}, |
| 616 | + {label: "boolean", value: true}, |
| 617 | + {label: "array", value: [1, 2, 3]}, |
| 618 | + {label: "number", value: 10}, |
| 619 | + {label: "date", value: new Date(1)}, |
| 620 | + // eslint-disable-next-line no-undef |
| 621 | + {label: "bigint", value: BigInt(10)}, |
| 622 | + {label: "NaN", value: NaN} |
| 623 | + ] |
| 624 | + ); |
| 625 | + }); |
| 626 | +}); |
0 commit comments