Skip to content

Commit

Permalink
Implemented handling of intentionally unconnected PCB ports in `check…
Browse files Browse the repository at this point in the history
…EachPcbPortConnected` function.
  • Loading branch information
Your Name (aider) committed Jul 26, 2024
1 parent 962093f commit 6b95974
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/check-each-pcb-port-connected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ function checkEachPcbPortConnected(soup: AnySoupElement[]): PCBTraceError[] {
),
)

if (connectedTraces.length === 0) {
const sourceTrace = sourceTraces.find((trace) =>
trace.connected_source_port_ids.includes(port.source_port_id),
)
const sourceTrace = sourceTraces.find((trace) =>
trace.connected_source_port_ids?.includes(port.source_port_id),
)

// Check if the port is supposed to be connected
const isSupposedToBeConnected = sourceTrace && sourceTrace.connected_source_port_ids?.length > 0

if (connectedTraces.length === 0 && isSupposedToBeConnected) {
errors.push({
type: "pcb_error",
message: `pcb_trace_error: PCB port ${port.pcb_port_id} is not connected by a PCB trace`,
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/check-each-pcb-port-connected.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,36 @@ describe("checkEachPcbPortConnected", () => {
expect(checkEachPcbPortConnected([])).toEqual([])
})

test("should not return errors for intentionally unconnected ports", () => {
const soup: AnySoupElement[] = [
{
type: "pcb_port",
pcb_port_id: "port1",
source_port_id: "source1",
x: 0,
y: 0,
pcb_component_id: "comp1",
layers: ["top"],
},
{
type: "pcb_port",
pcb_port_id: "port2",
source_port_id: "source2",
x: 1,
y: 1,
pcb_component_id: "comp2",
layers: ["top"],
},
{
type: "source_trace",
source_trace_id: "trace1",
connected_source_port_ids: [], // Intentionally empty
},
]
const errors = checkEachPcbPortConnected(soup)
expect(errors).toHaveLength(0)
})

test("should automatically add start_pcb_port_id and end_pcb_port_id", () => {
const soup: AnySoupElement[] = [
{
Expand Down

0 comments on commit 6b95974

Please sign in to comment.