Skip to content

Commit 7bf8441

Browse files
committed
add test for sheet_instances
1 parent 6486394 commit 7bf8441

File tree

1 file changed

+228
-0
lines changed

1 file changed

+228
-0
lines changed

tests/sexpr/classes/KicadSch.test.ts

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,231 @@ test("KicadSch parse", () => {
9393
)"
9494
`)
9595
})
96+
97+
test("KicadSch parse with lib_symbols, instances and sheet_instances", () => {
98+
const input = `(kicad_sch
99+
(version 20250114)
100+
(generator "eeschema")
101+
(generator_version "9.0")
102+
(uuid "7581b6ee-fd20-4dd8-85dd-91c70d13dcc0")
103+
(paper "A4")
104+
(lib_symbols
105+
(symbol "Device:R"
106+
(pin_numbers
107+
(hide yes)
108+
)
109+
(pin_names
110+
(offset 0)
111+
)
112+
(exclude_from_sim no)
113+
(in_bom yes)
114+
(on_board yes)
115+
(property "Reference" "R"
116+
(at 2.032 0 90)
117+
(effects
118+
(font
119+
(size 1.27 1.27)
120+
)
121+
)
122+
)
123+
(property "Value" "R"
124+
(at 0 0 90)
125+
(effects
126+
(font
127+
(size 1.27 1.27)
128+
)
129+
)
130+
)
131+
(property "Footprint" ""
132+
(at -1.778 0 90)
133+
(effects
134+
(font
135+
(size 1.27 1.27)
136+
)
137+
(hide yes)
138+
)
139+
)
140+
(property "Datasheet" "~"
141+
(at 0 0 0)
142+
(effects
143+
(font
144+
(size 1.27 1.27)
145+
)
146+
(hide yes)
147+
)
148+
)
149+
(property "Description" "Resistor"
150+
(at 0 0 0)
151+
(effects
152+
(font
153+
(size 1.27 1.27)
154+
)
155+
(hide yes)
156+
)
157+
)
158+
(property "ki_keywords" "R res resistor"
159+
(at 0 0 0)
160+
(effects
161+
(font
162+
(size 1.27 1.27)
163+
)
164+
(hide yes)
165+
)
166+
)
167+
(property "ki_fp_filters" "R_*"
168+
(at 0 0 0)
169+
(effects
170+
(font
171+
(size 1.27 1.27)
172+
)
173+
(hide yes)
174+
)
175+
)
176+
(symbol "R_0_1"
177+
(rectangle
178+
(start -1.016 -2.54)
179+
(end 1.016 2.54)
180+
(stroke
181+
(width 0.254)
182+
(type default)
183+
)
184+
(fill
185+
(type none)
186+
)
187+
)
188+
)
189+
(symbol "R_1_1"
190+
(pin passive line
191+
(at 0 3.81 270)
192+
(length 1.27)
193+
(name "~"
194+
(effects
195+
(font
196+
(size 1.27 1.27)
197+
)
198+
)
199+
)
200+
(number "1"
201+
(effects
202+
(font
203+
(size 1.27 1.27)
204+
)
205+
)
206+
)
207+
)
208+
(pin passive line
209+
(at 0 -3.81 90)
210+
(length 1.27)
211+
(name "~"
212+
(effects
213+
(font
214+
(size 1.27 1.27)
215+
)
216+
)
217+
)
218+
(number "2"
219+
(effects
220+
(font
221+
(size 1.27 1.27)
222+
)
223+
)
224+
)
225+
)
226+
)
227+
(embedded_fonts no)
228+
)
229+
)
230+
(symbol
231+
(lib_id "Device:R")
232+
(at 95.25 73.66 0)
233+
(unit 1)
234+
(exclude_from_sim no)
235+
(in_bom yes)
236+
(on_board yes)
237+
(dnp no)
238+
(fields_autoplaced yes)
239+
(uuid "3bb4d371-5882-4297-84fd-b4e30f862291")
240+
(property "Reference" "R?"
241+
(at 97.79 72.3899 0)
242+
(effects
243+
(font
244+
(size 1.27 1.27)
245+
)
246+
(justify left)
247+
)
248+
)
249+
(property "Value" "R"
250+
(at 97.79 74.9299 0)
251+
(effects
252+
(font
253+
(size 1.27 1.27)
254+
)
255+
(justify left)
256+
)
257+
)
258+
(property "Footprint" ""
259+
(at 93.472 73.66 90)
260+
(effects
261+
(font
262+
(size 1.27 1.27)
263+
)
264+
(hide yes)
265+
)
266+
)
267+
(property "Datasheet" "~"
268+
(at 95.25 73.66 0)
269+
(effects
270+
(font
271+
(size 1.27 1.27)
272+
)
273+
(hide yes)
274+
)
275+
)
276+
(property "Description" "Resistor"
277+
(at 95.25 73.66 0)
278+
(effects
279+
(font
280+
(size 1.27 1.27)
281+
)
282+
(hide yes)
283+
)
284+
)
285+
(pin "1"
286+
(uuid "8d57597d-9144-40ce-9745-fa1d610e7ae0")
287+
)
288+
(pin "2"
289+
(uuid "b70facae-ae80-40c4-97af-f37b215a794c")
290+
)
291+
(instances
292+
(project ""
293+
(path "/7581b6ee-fd20-4dd8-85dd-91c70d13dcc0"
294+
(reference "R?")
295+
(unit 1)
296+
)
297+
)
298+
)
299+
)
300+
(sheet_instances
301+
(path "/"
302+
(page "1")
303+
)
304+
)
305+
(embedded_fonts no)
306+
)`
307+
308+
const [parsed] = SxClass.parse(input)
309+
expect(parsed).toBeInstanceOf(KicadSch)
310+
311+
const schematic = parsed as KicadSch
312+
const output = schematic.getString()
313+
314+
// Parse the output again to ensure it's valid
315+
const [reparsed] = SxClass.parse(output)
316+
expect(reparsed).toBeInstanceOf(KicadSch)
317+
318+
// Basic structure checks
319+
expect(schematic.version).toBe(20250114)
320+
expect(schematic.generator).toBe("eeschema")
321+
expect(schematic.symbols).toHaveLength(1)
322+
expect(schematic.symbols[0]?.libraryId).toBe("Device:R")
323+
})

0 commit comments

Comments
 (0)