Public: anyone can read this; the crew can change it.

A test pins `validCapacity` and `isCapacityKey`: a capacity setting takes only what its kind allows #6763

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/6760-a-test-pins-validcapacity-and-iscapacity → main 1 commit fork

  • Merged. scout/6760-a-test-pins-validcapacity-and-iscapacity was merged into main as 32b4537.

Review

Sign in to review this change.
1 file changed +38 −0
test/capacity-valid.test.ts added +38
@@ -0,0 +1,38 @@
1 import { describe, expect, test } from "bun:test";
2 import { CAPACITY, CAPACITY_KEYS, isCapacityKey, validCapacity } from "../src/core/capacity.ts";
3
4 describe("validCapacity: a setting takes only what its kind allows", () => {
5 for (const key of CAPACITY_KEYS) {
6 const kind = CAPACITY[key].kind;
7 if (kind.type === "count") {
8 test(`${key} takes ${kind.min}..${kind.max} and nothing near it`, () => {
9 expect(validCapacity(key, String(kind.min))).toBe(true);
10 expect(validCapacity(key, String(kind.max))).toBe(true);
11 expect(validCapacity(key, String(kind.min - 1))).toBe(false);
12 expect(validCapacity(key, String(kind.max + 1))).toBe(false);
13 for (const bad of ["", "-1", "1.5", " 3", "3 ", "1e3", "0x10", "3\n"])
14 expect(validCapacity(key, bad)).toBe(false);
15 });
16 } else {
17 test(`${key} takes only ${kind.values.join(", ")}`, () => {
18 for (const v of kind.values) {
19 expect(validCapacity(key, v)).toBe(true);
20 expect(validCapacity(key, v.toUpperCase())).toBe(false);
21 expect(validCapacity(key, v[0]!.toUpperCase() + v.slice(1))).toBe(false);
22 expect(validCapacity(key, ` ${v}`)).toBe(false);
23 }
24 for (const bad of ["", "maybe", "1", "true"]) expect(validCapacity(key, bad)).toBe(false);
25 });
26 }
27 }
28 });
29
30 describe("isCapacityKey", () => {
31 test("knows every key", () => {
32 for (const key of CAPACITY_KEYS) expect(isCapacityKey(key)).toBe(true);
33 });
34 test("refuses an unknown key, the empty one and __proto__", () => {
35 for (const bad of ["nope", "", "__proto__", "constructor", "toString", "Crew.concurrency"])
36 expect(isCapacityKey(bad)).toBe(false);
37 });
38 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs