|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { describe, it } from "node:test"; |
| 3 | + |
| 4 | +import { ParameterType } from "../../src/config.js"; |
| 5 | +import { |
| 6 | + isValidParamNameCasing, |
| 7 | + isParameterValueValid, |
| 8 | +} from "../../src/internal/parameters.js"; |
| 9 | + |
| 10 | +describe("Parameters", () => { |
| 11 | + describe("isValidParamNameCasing", () => { |
| 12 | + it("should return true for valid parameter names", () => { |
| 13 | + assert.equal(isValidParamNameCasing("a"), true); |
| 14 | + assert.equal(isValidParamNameCasing("aa"), true); |
| 15 | + assert.equal(isValidParamNameCasing("aA"), true); |
| 16 | + assert.equal(isValidParamNameCasing("a1"), true); |
| 17 | + assert.equal(isValidParamNameCasing("foo"), true); |
| 18 | + assert.equal(isValidParamNameCasing("fooBar"), true); |
| 19 | + assert.equal(isValidParamNameCasing("foo123"), true); |
| 20 | + }); |
| 21 | + |
| 22 | + it("should return false for invalid parameter names", () => { |
| 23 | + assert.equal(isValidParamNameCasing("A"), false); |
| 24 | + assert.equal(isValidParamNameCasing("1"), false); |
| 25 | + assert.equal(isValidParamNameCasing("-"), false); |
| 26 | + assert.equal(isValidParamNameCasing("Foo"), false); |
| 27 | + assert.equal(isValidParamNameCasing("123Foo"), false); |
| 28 | + assert.equal(isValidParamNameCasing("foo-bar"), false); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe("isParameterValueValid", () => { |
| 33 | + it("should validate string parameters", () => { |
| 34 | + assert.equal(isParameterValueValid(ParameterType.STRING, "foo"), true); |
| 35 | + assert.equal(isParameterValueValid(ParameterType.STRING, 123), false); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should validate boolean parameters", () => { |
| 39 | + assert.equal(isParameterValueValid(ParameterType.BOOLEAN, true), true); |
| 40 | + assert.equal(isParameterValueValid(ParameterType.BOOLEAN, "true"), false); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should validate int parameters", () => { |
| 44 | + assert.equal(isParameterValueValid(ParameterType.INT, 123), true); |
| 45 | + assert.equal(isParameterValueValid(ParameterType.INT, 123.45), false); |
| 46 | + assert.equal(isParameterValueValid(ParameterType.INT, 123n), false); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should validate bigint parameters", () => { |
| 50 | + assert.equal( |
| 51 | + isParameterValueValid(ParameterType.BIGINT, BigInt(123)), |
| 52 | + true, |
| 53 | + ); |
| 54 | + assert.equal(isParameterValueValid(ParameterType.BIGINT, 123n), true); |
| 55 | + assert.equal(isParameterValueValid(ParameterType.BIGINT, 123), false); |
| 56 | + }); |
| 57 | + |
| 58 | + it("should validate float parameters", () => { |
| 59 | + assert.equal(isParameterValueValid(ParameterType.FLOAT, 123), true); |
| 60 | + assert.equal(isParameterValueValid(ParameterType.FLOAT, 123.45), true); |
| 61 | + assert.equal(isParameterValueValid(ParameterType.FLOAT, 123n), false); |
| 62 | + }); |
| 63 | + |
| 64 | + it("should validate file parameters", () => { |
| 65 | + assert.equal(isParameterValueValid(ParameterType.FILE, "foo.txt"), true); |
| 66 | + assert.equal( |
| 67 | + isParameterValueValid(ParameterType.FILE, "random string"), |
| 68 | + true, |
| 69 | + ); |
| 70 | + assert.equal(isParameterValueValid(ParameterType.FILE, 123), false); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should validate variadic parameters", () => { |
| 74 | + assert.equal( |
| 75 | + isParameterValueValid(ParameterType.STRING, ["foo", "bar"], true), |
| 76 | + true, |
| 77 | + ); |
| 78 | + assert.equal( |
| 79 | + isParameterValueValid(ParameterType.BIGINT, [123n, BigInt(123)], true), |
| 80 | + true, |
| 81 | + ); |
| 82 | + assert.equal( |
| 83 | + isParameterValueValid(ParameterType.STRING, [], true), |
| 84 | + false, |
| 85 | + ); |
| 86 | + assert.equal( |
| 87 | + isParameterValueValid(ParameterType.STRING, ["foo", 123], true), |
| 88 | + false, |
| 89 | + ); |
| 90 | + }); |
| 91 | + }); |
| 92 | +}); |
0 commit comments