krishnax12/watchy-eink-smartwatch

Unfinished prototype (not production-ready): 4 native DRC errors, 2 display-flex intersections, and missing antenna radiator copper remain

Version
1.2.7
License
MIT
Stars
1

scripts/passive-pin-warnings.test.ts

import { expect, test } from "bun:test";
import {
	checkNoGroundPinDefined,
	checkNoPowerPinDefined,
} from "@tscircuit/checks";
import type { AnyCircuitElement, SourcePort } from "circuit-json";

function makeCircuit(attributes: Partial<SourcePort>[]): AnyCircuitElement[] {
	return [
		{
			type: "source_component",
			source_component_id: "sc1",
			ftype: "simple_chip",
			name: "U1",
		},
		...attributes.map(
			(attributes, index): SourcePort => ({
				type: "source_port",
				source_port_id: `sp${index}`,
				source_component_id: "sc1",
				name: `pin${index + 1}`,
				pin_number: index + 1,
				...attributes,
			}),
		),
	];
}

test("unpatched checker reports a power-pin warning for a passive antenna", () => {
	const circuit = makeCircuit([
		{ requires_power: false },
		{ requires_power: false, requires_ground: true },
	]);
	expect(checkNoPowerPinDefined(circuit)).toHaveLength(1);
	expect(checkNoGroundPinDefined(circuit)).toHaveLength(0);
});

test("unpatched checker reports a ground-pin warning for a switched motor", () => {
	const circuit = makeCircuit([
		{ requires_ground: false, requires_power: true },
		{ requires_ground: false },
	]);
	expect(checkNoPowerPinDefined(circuit)).toHaveLength(0);
	expect(checkNoGroundPinDefined(circuit)).toHaveLength(1);
});

test("unknown and partially specified chips still need power and ground", () => {
	for (const attributes of [
		[{}, {}],
		[{ requires_power: false }, {}],
		[{ requires_ground: false }, {}],
	]) {
		const circuit = makeCircuit(attributes);
		expect(checkNoPowerPinDefined(circuit)).toHaveLength(1);
		expect(checkNoGroundPinDefined(circuit)).toHaveLength(1);
	}
});

test("an NC pin cannot exempt an active IC", () => {
	const circuit = makeCircuit([
		{},
		{},
		{ requires_power: false, requires_ground: false, do_not_connect: true },
	]);
	expect(checkNoPowerPinDefined(circuit)).toHaveLength(1);
	expect(checkNoGroundPinDefined(circuit)).toHaveLength(1);
});

test("properly specified active IC remains valid", () => {
	const circuit = makeCircuit([
		{ requires_power: true },
		{ requires_ground: true },
	]);
	expect(checkNoPowerPinDefined(circuit)).toHaveLength(0);
	expect(checkNoGroundPinDefined(circuit)).toHaveLength(0);
});