31 lines
1.6 KiB
TypeScript
31 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { compile } from '../app/lib/logic/compile'
|
|
import { shapeOf } from '../app/lib/logic/geometry'
|
|
import { createProject, lookup } from '../app/lib/logic/ops'
|
|
import { toProject } from '../app/lib/logic/project'
|
|
import { scopeLayout } from '../app/lib/logic/scopeLayout'
|
|
import type { CircuitNode } from '../app/lib/logic/types'
|
|
|
|
/** A channel as it comes back from loading a project. */
|
|
function clean(col: unknown) {
|
|
const p = createProject({ examples: false })
|
|
p.components[0]!.nodes.push({ id: 's', kind: 'scope', x: 0, y: 0, scope: { cols: [col as never] } })
|
|
return toProject(JSON.parse(JSON.stringify(p))).components[0]!.nodes.find(n => n.id === 's')!.scope!.cols[0]
|
|
}
|
|
|
|
describe('logic analyzer part', () => {
|
|
it('a pin per bit down the left, a lane per channel beside its pins', () => {
|
|
const p = createProject({ examples: false })
|
|
const n: CircuitNode = { id: 's', kind: 'scope', x: 0, y: 0, scope: { cols: [{ id: 'a', name: 'CLK', bits: 1 }, { id: 'b', name: 'D', bits: 4 }] } }
|
|
const shape = shapeOf(n, lookup(p))
|
|
expect(shape.inputs.map(i => [i.label, i.dy])).toEqual([['CLK', 1], ['D0', 2], ['D1', 3], ['D2', 4], ['D3', 5]])
|
|
expect(scopeLayout(n).lanes.map(l => [l.row, l.bits])).toEqual([[1, 1], [2, 4]])
|
|
p.components[0]!.nodes.push(n)
|
|
expect(compile(lookup(p), p.components[0]!.id).errors).toEqual([])
|
|
})
|
|
|
|
it('its channels are saved and cleaned on loading', () => {
|
|
expect(clean({ id: 'a', name: 'X'.repeat(50), bits: 99 })).toEqual({ id: 'a', name: 'X'.repeat(40), bits: 1 })
|
|
})
|
|
})
|