test: add unit tests for clocks and digitalclock modules - #2127
Open
Seanstoppable wants to merge 3 commits into
Open
test: add unit tests for clocks and digitalclock modules#2127Seanstoppable wants to merge 3 commits into
Seanstoppable wants to merge 3 commits into
Conversation
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
force-pushed
the
seanstoppable-test-coverage-analysis
branch
from
July 23, 2026 02:58
771014f to
94b2a07
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds unit test coverage for the
clocksanddigitalclockmodules (both previously at 0%), and fixes a font rendering alignment bug in the digital clock.Changes
sanitizeLocation,BuildClock,NewClock,ToLocal,Date/Timeformatting, and allClockCollectionsort modes (alphabetical, chronological, reverse chronological, natural).labelWidth()andformatClocks()as standalone functions (previously inlined in a widget method) so the display string-building logic is testable withouttview.intStrConv,getColon,getHourMinute,getDate,getUTC,getEpoch, font selection/completeness,fontsJoin,mergeLines,renderClock, andrenderWidget.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):
▄█(3)▄█(4)█▀█(3)█▀█(4)█▀█(5)█▀█(4)█▀▀(3)█▀▀(4)▀▀▀█(4)▀▀▀█(4) ✓Also fixed bigfont and boldfont where "1" was narrower than other digits.
Coverage
clocksdigitalclockRemaining uncovered code is the thin widget layer (
NewWidget,Refresh,display) which depends ontviewapplication context.