|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | +// Copyright (c) 2026, The OpenROAD Authors |
| 3 | + |
| 4 | +import { describe, it } from 'node:test'; |
| 5 | +import assert from 'node:assert/strict'; |
| 6 | +import { updateDocumentTitle } from '../../src/title.js'; |
| 7 | + |
| 8 | +describe('updateDocumentTitle', () => { |
| 9 | + it('uses bare "OpenROAD" when no block name given', () => { |
| 10 | + const doc = { title: '' }; |
| 11 | + const out = updateDocumentTitle('', doc); |
| 12 | + assert.equal(out, 'OpenROAD'); |
| 13 | + assert.equal(doc.title, 'OpenROAD'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('uses bare "OpenROAD" when block name is null', () => { |
| 17 | + const doc = { title: '' }; |
| 18 | + const out = updateDocumentTitle(null, doc); |
| 19 | + assert.equal(out, 'OpenROAD'); |
| 20 | + assert.equal(doc.title, 'OpenROAD'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('uses bare "OpenROAD" when block name is undefined', () => { |
| 24 | + const doc = { title: '' }; |
| 25 | + const out = updateDocumentTitle(undefined, doc); |
| 26 | + assert.equal(out, 'OpenROAD'); |
| 27 | + assert.equal(doc.title, 'OpenROAD'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('mirrors GUI format with " - " separator when block name present', () => { |
| 31 | + // GUI uses "{window_title} - {block_name}" (mainWindow.cpp:540). |
| 32 | + const doc = { title: '' }; |
| 33 | + const out = updateDocumentTitle('gcd', doc); |
| 34 | + assert.equal(out, 'OpenROAD - gcd'); |
| 35 | + assert.equal(doc.title, 'OpenROAD - gcd'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('handles block names with special characters verbatim', () => { |
| 39 | + const doc = { title: '' }; |
| 40 | + const out = updateDocumentTitle('top_module/foo', doc); |
| 41 | + assert.equal(out, 'OpenROAD - top_module/foo'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('overwrites a previously set title', () => { |
| 45 | + const doc = { title: 'old' }; |
| 46 | + updateDocumentTitle('design1', doc); |
| 47 | + assert.equal(doc.title, 'OpenROAD - design1'); |
| 48 | + updateDocumentTitle('', doc); |
| 49 | + assert.equal(doc.title, 'OpenROAD'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('returns the formatted title without a doc', () => { |
| 53 | + // Useful for callers that only need the string. |
| 54 | + const out = updateDocumentTitle('myblock', null); |
| 55 | + assert.equal(out, 'OpenROAD - myblock'); |
| 56 | + }); |
| 57 | +}); |
0 commit comments