Add buses configuration to chip props - #840
Open
seveibar wants to merge 2 commits into
Open
Conversation
Comment on lines
+1
to
+60
| import { expect, test } from "bun:test" | ||
| import { busProps, chipProps, type ChipProps } from "lib" | ||
|
|
||
| test("chip bus declarations use standalone bus parsing", () => { | ||
| const props: ChipProps = { | ||
| name: "U1", | ||
| buses: [ | ||
| { | ||
| name: "DATA", | ||
| connections: [".U1 > .D0", ".U1 > .D1"], | ||
| maxLengthSkew: "500um", | ||
| targetImpedance: "50ohm", | ||
| pcbTraceWidth: "0.2mm", | ||
| pcbAllowedLayers: ["top", "bottom"], | ||
| preferredLayer: "top", | ||
| preferredLayers: ["top", "bottom"], | ||
| routingPhaseIndex: 1, | ||
| }, | ||
| { connections: ["RESET"], routingPhaseIndex: null }, | ||
| ], | ||
| } | ||
| const parsed = chipProps.parse(props) | ||
| expect(parsed.buses).toEqual(props.buses!.map((bus) => busProps.parse(bus))) | ||
| expect(parsed.buses?.[0]?.maxLengthSkew).toBe(0.5) | ||
| expect(parsed.buses?.[0]?.targetImpedance).toBe(50) | ||
| expect(parsed.buses?.[0]?.pcbTraceWidth).toBe(0.2) | ||
| }) | ||
|
|
||
| test("chip buses are optional and may be empty", () => { | ||
| expect(chipProps.parse({ name: "U1" }).buses).toBeUndefined() | ||
| expect(chipProps.parse({ name: "U1", buses: [] }).buses).toEqual([]) | ||
| }) | ||
|
|
||
| test("chip rejects invalid nested bus declarations", () => { | ||
| for (const bus of [ | ||
| {}, | ||
| { connections: [] }, | ||
| { connections: [1] }, | ||
| { connections: ["DATA"], maxLengthSkew: "-1mm" }, | ||
| { connections: ["DATA"], targetImpedance: 0 }, | ||
| { connections: ["DATA"], pcbTraceWidth: 0 }, | ||
| { connections: ["DATA"], pcbAllowedLayers: [] }, | ||
| { connections: ["DATA"], preferredLayers: [] }, | ||
| ]) { | ||
| const result = chipProps.safeParse({ name: "U1", buses: [bus] }) | ||
| expect(result.success).toBe(false) | ||
| if (!result.success) { | ||
| expect(result.error.issues[0]?.path.slice(0, 2)).toEqual(["buses", 0]) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| test("chip buses require connections at compile time", () => { | ||
| const props: ChipProps = { | ||
| name: "U1", | ||
| // @ts-expect-error Each bus requires connections. | ||
| buses: [{ name: "DATA" }], | ||
| } | ||
| void props | ||
| }) |
Contributor
There was a problem hiding this comment.
This file contains 4 test(...) calls (at lines 4, 29, 34, and 53), but the rule states that a *.test.ts file may have AT MOST one test(...). The file should be split into multiple numbered files, e.g., chip-buses1.test.ts, chip-buses2.test.ts, chip-buses3.test.ts, and chip-buses4.test.ts, each containing exactly one test(...) call.
Spotted by Graphite (based on custom rule: Custom rule)
Is this helpful? React 👍 or 👎 to let us know.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allow chips to declare routing buses with
buses?: ChipBusProps<PinLabel>[]. Each declaration uses localpinNames; core can resolve those pins to connections when creating a<bus />element.Derive the chip bus schema from
busProps, replacingconnectionswith a nonemptypinNamesarray. Reuse all routing options, validation, and unit conversion. Pin names use schematic pin label validation and are constrained to known pins when using typed ChipProps. Standalone bus props retainconnections.Omission and an empty buses array declare no buses; no aliases or implicit merges are added. This PR supplies the props contract; resolving local pins and creating bus elements remains a core implementation step.
Validation: 513 tests pass, including nested parsing, unit conversion, invalid declarations, optional/empty buses, required pinNames, and compile-time pin-name validation. Type checking, formatting, build, and all required generation scripts pass.