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
9 changes: 3 additions & 6 deletions lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,13 +860,10 @@ function processNet(nodes: ASTNode[]): Net {

function processClass(nodes: ASTNode[]): Class {
const classObj: Partial<Class> = {}
if (
nodes[1].type === "Atom" &&
typeof nodes[1].value === "string" &&
nodes[2].type === "Atom" &&
typeof nodes[2].value === "string"
) {
if (nodes[1].type === "Atom" && typeof nodes[1].value === "string") {
classObj.name = nodes[1].value
}
if (nodes[2]?.type === "Atom" && typeof nodes[2].value === "string") {
classObj.description = nodes[2].value
}

Expand Down
43 changes: 43 additions & 0 deletions tests/repros/repro22-class-name-without-description.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect, test } from "bun:test"
import { parseDsnToDsnJson } from "lib"

/**
* Part of https://github.com/tscircuit/dsn-converter/issues/54
*
* processClass only set `classObj.name` when nodes[1] AND nodes[2] were both
* string atoms, treating nodes[2] as a required "description". But a class
* with no description (nodes[2] is the first nested list, e.g.
* `(clearance_class ...)`, not a string) is valid DSN -- see the `default`
* class in tests/assets/testkicadproject/freeroutingTraceAdded.dsn. The
* class's name was silently dropped whenever it had no description.
*/
test("a class with no description still gets its name parsed", () => {
const dsn = `(pcb "test.dsn"
(parser
(string_quote ")
(space_in_quoted_tokens on)
(host_cad "test")
(host_version "1")
)
(resolution um 10)
(unit um)
(structure
(layer Top (type signal) (property (index 0)))
(boundary (path pcb 0 0 0 0 100 0 100 100 0 100 0 0))
(via "")
(rule (width 200))
)
(placement)
(library)
(network
(class default
(clearance_class default)
(rule (width 200))
)
)
(wiring)
)`

const dsnJson = parseDsnToDsnJson(dsn) as any
expect(dsnJson.network.classes[0].name).toBe("default")
})
Loading