refactor: extract shortView into node-views.js

This commit is contained in:
c0dev0id
2026-07-06 21:10:28 +02:00
parent 9a2e76ba4f
commit e823608325
3 changed files with 55 additions and 40 deletions

View File

@@ -6,6 +6,7 @@ import { readFileSync } from 'fs';
import { parseAstLog, buildModel } from './static/ast-parser.js';
import { exportInstrument, patchScore } from './static/exporter.js';
import { stressorToString } from './static/util.js';
import { shortView } from './static/node-views.js';
const FIXTURE = new URL('./fixtures/ast.log', import.meta.url);
const text = readFileSync(FIXTURE, 'utf8');
@@ -667,6 +668,21 @@ ok('adjacent: null when absent', adjOffset.stemNotes[0].adjacent === null);
ok('adjacent: false when False', adjOffset.stemNotes[1].adjacent === false);
ok('adjacent: true when True', adjOffset.stemNotes[2].adjacent === true);
section('shortView');
ok('shortView null → ?', shortView(null).typeTag === '?');
ok('shortView score', shortView(model).typeTag === 'score');
ok('shortView score label', shortView(model).label === model.info?.title);
ok('shortView score meta', shortView(model).meta.some(m => m.key === 'composer'));
ok('shortView instrument', shortView(model.instruments[0]).typeTag === 'instrument');
ok('shortView instrument label',shortView(model.instruments[0]).label === model.instruments[0].name);
ok('shortView bar', shortView(model.bars[0]).typeTag === 'bar');
ok('shortView bar label', shortView(model.bars[0]).label === model.bars[0].id);
ok('shortView article', shortView(model.articles[0]).typeTag === 'article');
const svV = model.instruments[0]?.variations[0];
if (svV) {
ok('shortView variation root', shortView(svV).label === '(root variation)' || shortView(svV).label.startsWith('ATTR'));
}
section('unknownSlots graceful degradation');
const UNK_FIXTURE = `00 instrument 'test'
01 character.FUTURE_SLOT foo='bar'