Module
x/value_schema/test/adjusters/ipv6.test.es
simple, easy-to-use, and declarative input validator; supports Node.js, TypeScript, and Deno
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136import adjuster from "index";
{ describe("default", testDefault); describe("acceptNull", testAcceptNull); describe("acceptEmptyString", testAcceptEmptyString); describe("trim", testTrim); describe("pattern", testPattern);}
/** * default value * @return {void} */function testDefault(){ it("should be adjusted", () => { expect(adjuster.ipv6().default("::1") .adjust(undefined)).toEqual("::1"); }); it("should cause error(s)", () => { expect(() => { adjuster.ipv6() .adjust(undefined); }).toThrow(adjuster.CAUSE.REQUIRED); });}
/** * null * @return {void} */function testAcceptNull(){ it("should be OK", () => { expect(adjuster.ipv6().acceptNull("::1") .adjust(null)).toEqual("::1"); }); it("should cause error(s)", () => { expect(() => { adjuster.ipv6() .adjust(null); }).toThrow(adjuster.CAUSE.NULL); });}
/** * empty string * @return {void} */function testAcceptEmptyString(){ it("should be OK", () => { expect(adjuster.ipv6().acceptEmptyString("::1") .adjust("")).toEqual("::1"); }); it("should cause error(s)", () => { expect(() => { adjuster.ipv6() .adjust(""); }).toThrow(adjuster.CAUSE.EMPTY); });}
/** * remove whitespace from both ends * @return {void} */function testTrim(){ it("should be adjusted", () => { expect(adjuster.ipv6().trim() .adjust("\r\n ::1 \t ")).toEqual("::1"); }); it("should cause error(s)", () => { expect(() => { adjuster.ipv6().trim() .adjust(" \t\r\n "); }).toThrow(adjuster.CAUSE.EMPTY); });}
/** * IPv6 pattern * @return {void} */function testPattern(){ it("should be OK", () => { const values = [ "0000:0000:0000:0000:0000:0000:0000:0000",
"::1", "::", "1::1",
// IPv4-mapped address "::ffff:192.0.2.1", ]; for(const value of values) { expect(adjuster.ipv6() .adjust(value)).toEqual(value); } }); it("should cause error(s)", () => { const values = [ "0000", "ffff:", "0000:0000:0000:0000:0000:0000:0000:0000:", ]; for(const value of values) { expect(() => { adjuster.ipv6() .adjust(value); }).toThrow(adjuster.CAUSE.PATTERN); } });}