[PR #6585] test: adding tests for util/color.ts #11985

Open
opened 2026-02-16 18:16:55 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6585

State: open
Merged: No


Hi,

Generated extensive unit tests for util/color.ts

They all run successfuly

 bun test --coverage packages/opencode/test/util/color.test.ts
bun test v1.3.5 (1e86cebd)

packages/opencode/test/util/color.test.ts:
✓ Color > isValidHex > valid hex colors > should return true for valid 6-digit hex color with lowercase [1.42ms]
✓ Color > isValidHex > valid hex colors > should return true for valid 6-digit hex color with uppercase [0.02ms]
✓ Color > isValidHex > valid hex colors > should return true for valid 6-digit hex color with mixed case
✓ Color > isValidHex > valid hex colors > should return true for black color
✓ Color > isValidHex > valid hex colors > should return true for red color
✓ Color > isValidHex > valid hex colors > should return true for green color
✓ Color > isValidHex > valid hex colors > should return true for blue color
✓ Color > isValidHex > valid hex colors > should return true for hex with numbers and letters
✓ Color > isValidHex > valid hex colors > should return true for hex with all numbers
✓ Color > isValidHex > valid hex colors > should return true for hex with all letters
✓ Color > isValidHex > valid hex colors > should return true for hex with uppercase letters
✓ Color > isValidHex > invalid hex colors > should return false for undefined
✓ Color > isValidHex > invalid hex colors > should return false for empty string
✓ Color > isValidHex > invalid hex colors > should return false for hex without hash
✓ Color > isValidHex > invalid hex colors > should return false for 3-digit hex color
✓ Color > isValidHex > invalid hex colors > should return false for 8-digit hex color (with alpha)
✓ Color > isValidHex > invalid hex colors > should return false for 5-digit hex
✓ Color > isValidHex > invalid hex colors > should return false for 7-digit hex
✓ Color > isValidHex > invalid hex colors > should return false for hex with invalid characters
✓ Color > isValidHex > invalid hex colors > should return false for hex with spaces
✓ Color > isValidHex > invalid hex colors > should return false for hex with special characters
✓ Color > isValidHex > invalid hex colors > should return false for just hash
✓ Color > isValidHex > invalid hex colors > should return false for multiple hashes [0.01ms]
✓ Color > isValidHex > invalid hex colors > should return false for hash at the end
✓ Color > isValidHex > invalid hex colors > should return false for rgb string
✓ Color > isValidHex > invalid hex colors > should return false for color names
✓ Color > isValidHex > invalid hex colors > should return false for null (cast to string)
✓ Color > isValidHex > invalid hex colors > should return false for numbers
✓ Color > isValidHex > edge cases > should return false for whitespace
✓ Color > isValidHex > edge cases > should return false for hex with leading whitespace
✓ Color > isValidHex > edge cases > should return false for hex with trailing whitespace
✓ Color > isValidHex > edge cases > should return false for hex with newline
✓ Color > isValidHex > edge cases > should return false for hex with tab
✓ Color > hexToRgb > basic color conversions > should convert white to RGB [0.49ms]
✓ Color > hexToRgb > basic color conversions > should convert black to RGB [0.02ms]
✓ Color > hexToRgb > basic color conversions > should convert red to RGB
✓ Color > hexToRgb > basic color conversions > should convert green to RGB
✓ Color > hexToRgb > basic color conversions > should convert blue to RGB
✓ Color > hexToRgb > basic color conversions > should convert yellow to RGB
✓ Color > hexToRgb > basic color conversions > should convert cyan to RGB
✓ Color > hexToRgb > basic color conversions > should convert magenta to RGB
✓ Color > hexToRgb > case insensitivity > should convert lowercase hex to RGB
✓ Color > hexToRgb > case insensitivity > should convert uppercase hex to RGB
✓ Color > hexToRgb > case insensitivity > should convert mixed case hex to RGB
✓ Color > hexToRgb > numeric conversions > should convert hex with all numbers
✓ Color > hexToRgb > numeric conversions > should convert hex with leading zeros
✓ Color > hexToRgb > numeric conversions > should convert hex with mid-range values
✓ Color > hexToRgb > numeric conversions > should convert hex to maximum values
✓ Color > hexToRgb > numeric conversions > should convert hex to minimum values
✓ Color > hexToRgb > specific color values > should convert orange-like color
✓ Color > hexToRgb > specific color values > should convert purple-like color
✓ Color > hexToRgb > specific color values > should convert pink-like color
✓ Color > hexToRgb > specific color values > should convert brown-like color
✓ Color > hexToRgb > edge cases > should handle hex with maximum F values
✓ Color > hexToRgb > edge cases > should handle alternating values
✓ Color > hexToRgb > edge cases > should handle sequential values
✓ Color > hexToAnsiBold > valid conversions > should convert valid white hex to ANSI bold [0.51ms]
✓ Color > hexToAnsiBold > valid conversions > should convert valid black hex to ANSI bold
✓ Color > hexToAnsiBold > valid conversions > should convert valid red hex to ANSI bold [0.01ms]
✓ Color > hexToAnsiBold > valid conversions > should convert valid green hex to ANSI bold
✓ Color > hexToAnsiBold > valid conversions > should convert valid blue hex to ANSI bold
✓ Color > hexToAnsiBold > valid conversions > should convert valid mixed hex to ANSI bold
✓ Color > hexToAnsiBold > valid conversions > should handle lowercase hex
✓ Color > hexToAnsiBold > valid conversions > should handle uppercase hex
✓ Color > hexToAnsiBold > valid conversions > should handle mixed case hex
✓ Color > hexToAnsiBold > invalid conversions > should return undefined for undefined input [0.15ms]
✓ Color > hexToAnsiBold > invalid conversions > should return undefined for empty string [0.02ms]
✓ Color > hexToAnsiBold > invalid conversions > should return undefined for invalid hex without hash
✓ Color > hexToAnsiBold > invalid conversions > should return undefined for 3-digit hex
✓ Color > hexToAnsiBold > invalid conversions > should return undefined for 8-digit hex
✓ Color > hexToAnsiBold > invalid conversions > should return undefined for hex with invalid characters
✓ Color > hexToAnsiBold > invalid conversions > should return undefined for just hash [0.03ms]
✓ Color > hexToAnsiBold > invalid conversions > should return undefined for color names
✓ Color > hexToAnsiBold > invalid conversions > should return undefined for rgb string
✓ Color > hexToAnsiBold > ANSI format verification > should start with ANSI escape sequence [0.11ms]
✓ Color > hexToAnsiBold > ANSI format verification > should end with bold modifier
✓ Color > hexToAnsiBold > ANSI format verification > should contain semicolon-separated RGB values
✓ Color > hexToAnsiBold > ANSI format verification > should produce correct format for zero values
✓ Color > hexToAnsiBold > ANSI format verification > should produce correct format for max values
✓ Color > hexToAnsiBold > ANSI format verification > should produce correct format for mixed values
✓ Color > hexToAnsiBold > edge cases > should handle hex with leading zeros in RGB conversion
✓ Color > hexToAnsiBold > edge cases > should handle mid-range gray values
✓ Color > hexToAnsiBold > edge cases > should return undefined for whitespace
✓ Color > hexToAnsiBold > edge cases > should return undefined for hex with spaces [0.11ms]
✓ Color > integration tests > should work with isValidHex and hexToRgb together
✓ Color > integration tests > should work with all three functions together [0.02ms]
✓ Color > integration tests > should handle invalid hex consistently across functions
✓ Color > integration tests > should validate before converting in hexToAnsiBold [0.23ms]
✓ Color > integration tests > should produce consistent RGB values for same color [0.02ms]
✓ Color > integration tests > should produce consistent ANSI codes for same color regardless of case
-------------------------------------|---------|---------|-------------------
File                                 | % Funcs | % Lines | Uncovered Line #s
-------------------------------------|---------|---------|-------------------
All files                            |  100.00 |  100.00 |
 packages/opencode/src/util/color.ts |  100.00 |  100.00 | 
-------------------------------------|---------|---------|-------------------

 90 pass
 0 fail
 105 expect() calls
Ran 90 tests across 1 file. [122.00ms]
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6585 **State:** open **Merged:** No --- Hi, Generated extensive unit tests for util/color.ts They all run successfuly ``` bun test --coverage packages/opencode/test/util/color.test.ts bun test v1.3.5 (1e86cebd) packages/opencode/test/util/color.test.ts: ✓ Color > isValidHex > valid hex colors > should return true for valid 6-digit hex color with lowercase [1.42ms] ✓ Color > isValidHex > valid hex colors > should return true for valid 6-digit hex color with uppercase [0.02ms] ✓ Color > isValidHex > valid hex colors > should return true for valid 6-digit hex color with mixed case ✓ Color > isValidHex > valid hex colors > should return true for black color ✓ Color > isValidHex > valid hex colors > should return true for red color ✓ Color > isValidHex > valid hex colors > should return true for green color ✓ Color > isValidHex > valid hex colors > should return true for blue color ✓ Color > isValidHex > valid hex colors > should return true for hex with numbers and letters ✓ Color > isValidHex > valid hex colors > should return true for hex with all numbers ✓ Color > isValidHex > valid hex colors > should return true for hex with all letters ✓ Color > isValidHex > valid hex colors > should return true for hex with uppercase letters ✓ Color > isValidHex > invalid hex colors > should return false for undefined ✓ Color > isValidHex > invalid hex colors > should return false for empty string ✓ Color > isValidHex > invalid hex colors > should return false for hex without hash ✓ Color > isValidHex > invalid hex colors > should return false for 3-digit hex color ✓ Color > isValidHex > invalid hex colors > should return false for 8-digit hex color (with alpha) ✓ Color > isValidHex > invalid hex colors > should return false for 5-digit hex ✓ Color > isValidHex > invalid hex colors > should return false for 7-digit hex ✓ Color > isValidHex > invalid hex colors > should return false for hex with invalid characters ✓ Color > isValidHex > invalid hex colors > should return false for hex with spaces ✓ Color > isValidHex > invalid hex colors > should return false for hex with special characters ✓ Color > isValidHex > invalid hex colors > should return false for just hash ✓ Color > isValidHex > invalid hex colors > should return false for multiple hashes [0.01ms] ✓ Color > isValidHex > invalid hex colors > should return false for hash at the end ✓ Color > isValidHex > invalid hex colors > should return false for rgb string ✓ Color > isValidHex > invalid hex colors > should return false for color names ✓ Color > isValidHex > invalid hex colors > should return false for null (cast to string) ✓ Color > isValidHex > invalid hex colors > should return false for numbers ✓ Color > isValidHex > edge cases > should return false for whitespace ✓ Color > isValidHex > edge cases > should return false for hex with leading whitespace ✓ Color > isValidHex > edge cases > should return false for hex with trailing whitespace ✓ Color > isValidHex > edge cases > should return false for hex with newline ✓ Color > isValidHex > edge cases > should return false for hex with tab ✓ Color > hexToRgb > basic color conversions > should convert white to RGB [0.49ms] ✓ Color > hexToRgb > basic color conversions > should convert black to RGB [0.02ms] ✓ Color > hexToRgb > basic color conversions > should convert red to RGB ✓ Color > hexToRgb > basic color conversions > should convert green to RGB ✓ Color > hexToRgb > basic color conversions > should convert blue to RGB ✓ Color > hexToRgb > basic color conversions > should convert yellow to RGB ✓ Color > hexToRgb > basic color conversions > should convert cyan to RGB ✓ Color > hexToRgb > basic color conversions > should convert magenta to RGB ✓ Color > hexToRgb > case insensitivity > should convert lowercase hex to RGB ✓ Color > hexToRgb > case insensitivity > should convert uppercase hex to RGB ✓ Color > hexToRgb > case insensitivity > should convert mixed case hex to RGB ✓ Color > hexToRgb > numeric conversions > should convert hex with all numbers ✓ Color > hexToRgb > numeric conversions > should convert hex with leading zeros ✓ Color > hexToRgb > numeric conversions > should convert hex with mid-range values ✓ Color > hexToRgb > numeric conversions > should convert hex to maximum values ✓ Color > hexToRgb > numeric conversions > should convert hex to minimum values ✓ Color > hexToRgb > specific color values > should convert orange-like color ✓ Color > hexToRgb > specific color values > should convert purple-like color ✓ Color > hexToRgb > specific color values > should convert pink-like color ✓ Color > hexToRgb > specific color values > should convert brown-like color ✓ Color > hexToRgb > edge cases > should handle hex with maximum F values ✓ Color > hexToRgb > edge cases > should handle alternating values ✓ Color > hexToRgb > edge cases > should handle sequential values ✓ Color > hexToAnsiBold > valid conversions > should convert valid white hex to ANSI bold [0.51ms] ✓ Color > hexToAnsiBold > valid conversions > should convert valid black hex to ANSI bold ✓ Color > hexToAnsiBold > valid conversions > should convert valid red hex to ANSI bold [0.01ms] ✓ Color > hexToAnsiBold > valid conversions > should convert valid green hex to ANSI bold ✓ Color > hexToAnsiBold > valid conversions > should convert valid blue hex to ANSI bold ✓ Color > hexToAnsiBold > valid conversions > should convert valid mixed hex to ANSI bold ✓ Color > hexToAnsiBold > valid conversions > should handle lowercase hex ✓ Color > hexToAnsiBold > valid conversions > should handle uppercase hex ✓ Color > hexToAnsiBold > valid conversions > should handle mixed case hex ✓ Color > hexToAnsiBold > invalid conversions > should return undefined for undefined input [0.15ms] ✓ Color > hexToAnsiBold > invalid conversions > should return undefined for empty string [0.02ms] ✓ Color > hexToAnsiBold > invalid conversions > should return undefined for invalid hex without hash ✓ Color > hexToAnsiBold > invalid conversions > should return undefined for 3-digit hex ✓ Color > hexToAnsiBold > invalid conversions > should return undefined for 8-digit hex ✓ Color > hexToAnsiBold > invalid conversions > should return undefined for hex with invalid characters ✓ Color > hexToAnsiBold > invalid conversions > should return undefined for just hash [0.03ms] ✓ Color > hexToAnsiBold > invalid conversions > should return undefined for color names ✓ Color > hexToAnsiBold > invalid conversions > should return undefined for rgb string ✓ Color > hexToAnsiBold > ANSI format verification > should start with ANSI escape sequence [0.11ms] ✓ Color > hexToAnsiBold > ANSI format verification > should end with bold modifier ✓ Color > hexToAnsiBold > ANSI format verification > should contain semicolon-separated RGB values ✓ Color > hexToAnsiBold > ANSI format verification > should produce correct format for zero values ✓ Color > hexToAnsiBold > ANSI format verification > should produce correct format for max values ✓ Color > hexToAnsiBold > ANSI format verification > should produce correct format for mixed values ✓ Color > hexToAnsiBold > edge cases > should handle hex with leading zeros in RGB conversion ✓ Color > hexToAnsiBold > edge cases > should handle mid-range gray values ✓ Color > hexToAnsiBold > edge cases > should return undefined for whitespace ✓ Color > hexToAnsiBold > edge cases > should return undefined for hex with spaces [0.11ms] ✓ Color > integration tests > should work with isValidHex and hexToRgb together ✓ Color > integration tests > should work with all three functions together [0.02ms] ✓ Color > integration tests > should handle invalid hex consistently across functions ✓ Color > integration tests > should validate before converting in hexToAnsiBold [0.23ms] ✓ Color > integration tests > should produce consistent RGB values for same color [0.02ms] ✓ Color > integration tests > should produce consistent ANSI codes for same color regardless of case -------------------------------------|---------|---------|------------------- File | % Funcs | % Lines | Uncovered Line #s -------------------------------------|---------|---------|------------------- All files | 100.00 | 100.00 | packages/opencode/src/util/color.ts | 100.00 | 100.00 | -------------------------------------|---------|---------|------------------- 90 pass 0 fail 105 expect() calls Ran 90 tests across 1 file. [122.00ms] ```
yindo added the pull-request label 2026-02-16 18:16:55 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11985