Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion generated/COMPONENT_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3411,7 +3411,10 @@ export interface PinHeaderProps extends CommonComponentProps {
* Schematic height
*/
export const pinHeaderProps = commonComponentProps.extend({
pinCount: z.number(),
pinCount: z
.number()
.int("pinCount must be a whole number of pins")
.positive("pinCount must be greater than zero"),
pitch: distance.optional(),
schFacingDirection: z.enum(["up", "down", "left", "right"]).optional(),
gender: z.enum(["male", "female", "unpopulated"]).optional().default("male"),
Expand Down
5 changes: 4 additions & 1 deletion lib/components/pin-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ export interface PinHeaderProps extends CommonComponentProps {
}

export const pinHeaderProps = commonComponentProps.extend({
pinCount: z.number(),
pinCount: z
.number()
.int("pinCount must be a whole number of pins")
.positive("pinCount must be greater than zero"),
pitch: distance.optional(),
schFacingDirection: z.enum(["up", "down", "left", "right"]).optional(),
gender: z.enum(["male", "female", "unpopulated"]).optional().default("male"),
Expand Down
31 changes: 31 additions & 0 deletions tests/pin-header.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ test("should parse pinLabels as record", () => {
expect(parsed.pinLabels).toEqual({ 1: "A", 2: "B" })
})

test("should reject a fractional pinCount", () => {
const parsed = pinHeaderProps.safeParse({ name: "header", pinCount: 2.5 })

expect(parsed.success).toBe(false)
})

test("should reject a zero or negative pinCount", () => {
expect(
pinHeaderProps.safeParse({ name: "header", pinCount: 0 }).success,
).toBe(false)
expect(
pinHeaderProps.safeParse({ name: "header", pinCount: -4 }).success,
).toBe(false)
})

test("should reject a non-finite pinCount", () => {
expect(
pinHeaderProps.safeParse({
name: "header",
pinCount: Number.POSITIVE_INFINITY,
}).success,
).toBe(false)
})

test("should parse whole pinCount values unchanged", () => {
for (const pinCount of [1, 2, 8, 40]) {
const parsed = pinHeaderProps.parse({ name: "header", pinCount })
expect(parsed.pinCount).toBe(pinCount)
}
})

test("should snapshot schematic props for pin header", () => {
const rawProps: PinHeaderProps = {
name: "header",
Expand Down
Loading