Skip to content

test: add unit tests for clocks and digitalclock modules - #2127

Open
Seanstoppable wants to merge 3 commits into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-test-coverage-analysis
Open

test: add unit tests for clocks and digitalclock modules#2127
Seanstoppable wants to merge 3 commits into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-test-coverage-analysis

Conversation

@Seanstoppable

@Seanstoppable Seanstoppable commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds unit test coverage for the clocks and digitalclock modules (both previously at 0%), and fixes a font rendering alignment bug in the digital clock.

Changes

  • modules/clocks: Added tests for sanitizeLocation, BuildClock, NewClock, ToLocal, Date/Time formatting, and all ClockCollection sort modes (alphabetical, chronological, reverse chronological, natural).
  • modules/clocks/display.go: Extracted labelWidth() and formatClocks() as standalone functions (previously inlined in a widget method) so the display string-building logic is testable without tview.
  • modules/digitalclock: Added tests for intStrConv, getColon, getHourMinute, getDate, getUTC, getEpoch, font selection/completeness, fontsJoin, mergeLines, renderClock, and renderWidget.
  • modules/digitalclock/fonts.go: Normalized all digit glyphs to uniform width within each font. Added regression tests (TestFontDigitWidthsUniform, TestFontGlyphRowsSelfConsistent).

Font Alignment Fix

Digit glyphs had inconsistent widths, causing misalignment when rendering times like "8:13".

Before — rendering "8:13" with digitalfont:

 ▄▀▀▄ █ ▄█  █▀▀█
 ▄▀▀▄   █    ▀▄
 ▀▄▄▀ █ ▄█▄ █▄▄█

Notice how the columns are jagged — "8" is 4 chars wide, "1" is 3 chars wide, "3" is 4 chars wide. The "1" being narrower shifts everything after it left, and digits don't line up vertically.

After — rendering "8:13" with digitalfont:

 ▄▀▀▄ █ ▄█   █▀▀█
 ▄▀▀▄    █     ▀▄
 ▀▄▄▀ █ ▄█▄  █▄▄█

All digits are now uniformly 4 characters wide. Columns align cleanly regardless of which digits are displayed, so "8:13", "12:00", "4:57" etc. all render with consistent spacing.

Glyphs that were fixed (digitalfont):

Digit Before (width) After (width)
1 ▄█ (3) ▄█ (4)
2 █▀█ (3) █▀█ (4)
4 █▀█ (5) █▀█ (4)
5 █▀▀ (3) █▀▀ (4)
7 ▀▀▀█ (4) ▀▀▀█ (4) ✓

Also fixed bigfont and boldfont where "1" was narrower than other digits.

Coverage

Module Before After
clocks 0.0% 55.3%
digitalclock 0.0% 79.5%

Remaining uncovered code is the thin widget layer (NewWidget, Refresh, display) which depends on tview application context.

Add test coverage for both clock modules, taking them from 0% to 55.3%
and 79.5% respectively.

Refactored display logic in clocks module to extract pure functions
(labelWidth, formatClocks) that can be tested without tview widget mocking.

clocks tests cover:
- sanitizeLocation, BuildClock, NewClock, ToLocal, Date/Time formatting
- ClockCollection sorting (alphabetical, chronological, reverse, natural)
- labelWidth calculation and formatClocks string building

digitalclock tests cover:
- intStrConv, getColon, getHourMinute, getDate, getUTC, getEpoch
- Font selection and completeness (digital, big, bold)
- fontsJoin, mergeLines, renderClock, renderWidget
@Seanstoppable
Seanstoppable force-pushed the seanstoppable-test-coverage-analysis branch from 771014f to 94b2a07 Compare July 23, 2026 02:58
Seanstoppable and others added 2 commits July 22, 2026 20:30
Digits 1, 2, and 5 were 3 characters wide while 3, 6, 7, 8, 9, 0 were
4 wide, and 4 was 5 wide. Since fontsJoin concatenates glyph rows
without padding, this caused visible misalignment in rendered clock
times (e.g. columns shifting for '1' and '3' in '8:13'). All digit
glyphs are now a uniform 4 characters wide; '4' was redesigned to fit
without changing its recognizable shape.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…on tests

Found while adding tests: bigfont's '1' was 4 wide vs 5 for other
digits, and boldfont's '1' was 2 wide vs 6 for other digits - same
misalignment bug as digitalfont's original '1'/'2'/'5'/'4'. Padded
both to match their font's uniform digit width.

Added fonts_test.go:
- TestFontDigitWidthsUniform: all digit glyphs (0-9) in a font share
  one width, per row.
- TestFontGlyphRowsSelfConsistent: every row within a single glyph is
  the same width.

These guard against this exact regression going forward.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant