Maintenance: LenFunctionHandler - Fix VimBlob handling and improve test coverage#1412
Maintenance: LenFunctionHandler - Fix VimBlob handling and improve test coverage#1412claude[bot] wants to merge 2 commits intomasterfrom
Conversation
…() function The len() function had a TODO() placeholder for VimBlob handling. Since VimBlob is not yet fully implemented in IdeaVim, this commit replaces the TODO with a meaningful exception message that directs users to request support in YouTrack, consistent with the pattern used in other function handlers (e.g., GetFunctionHandler). This prevents unexpected crashes when users encounter blobs in their VimScript code and provides clear guidance on the current limitation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…len() Added two new test cases: 1. Test that len() with VimBlob throws an appropriate error 2. Test multibyte character handling to document current behavior The multibyte test includes a comment explaining that IdeaVim currently returns character count rather than byte count (as Vim does). This documents the known limitation and provides a baseline for future improvements if byte-level compatibility is implemented. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
| @Test | ||
| fun `test len with blob causes error`() { | ||
| enterCommand("echo len(0z)") | ||
| assertPluginError(true) |
There was a problem hiding this comment.
The test assertion could be more specific. Instead of using assertPluginError(true), consider using assertPluginErrorMessage() to verify the exact error message, similar to line 81's test for float errors. This would:
- Make the test more robust (it currently passes for ANY error, not just the blob-related one)
- Document the expected error message for future maintainers
- Follow the pattern established by other error tests in this file
Suggested change:
| assertPluginError(true) | |
| fun `test len with blob causes error`() { | |
| enterCommand("echo len(0z)") | |
| assertPluginError(true) | |
| assertPluginErrorMessage("Blobs are not supported as an argument for len(). If you need it, request support in YouTrack") | |
| } |
| } | ||
|
|
||
| @Test | ||
| fun `test len with multibyte characters`() { |
There was a problem hiding this comment.
Consider adding the @TestWithoutNeovim annotation here since this test documents behavior that differs from real Vim. Looking at other test files in the codebase (e.g., FunctionTest.kt:40-46), tests that exhibit different behavior from Vim/Neovim are typically annotated with:
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
fun `test len with multibyte characters`() {This makes it clear to maintainers that this is a known difference and helps with test infrastructure that compares against Neovim.
Code Review SummaryThank you for this maintenance PR! The changes are well-structured and improve code quality by addressing technical debt. Here's my detailed review: ✅ Strengths
🔍 Suggestions for ImprovementI've left two inline comments with specific suggestions:
📋 Code Quality Assessment
🎯 Overall AssessmentThis is a solid maintenance PR that improves code quality. The core changes are good - the suggestions above are minor improvements that would make the tests more robust and maintainable. The ExException message is user-friendly and follows the codebase convention. Recommendation: Approve with minor suggested improvements. |
Summary
This maintenance PR improves the
len()function implementation by addressing a TODO and enhancing test coverage:TODO()placeholder with a proper exception messageWhat area was inspected
Randomly selected
LenFunctionTest.ktfor inspection, which led to investigating:vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/functions/handlers/LenFunctionHandler.ktIssues found
len()function had aTODO()for VimBlob handling, which would cause crashes if encounteredChanges made
Implementation (LenFunctionHandler.kt)
ExExceptionis VimBlob -> TODO()with meaningful exception message directing users to YouTrackGetFunctionHandlerandEmptyFunctionHandlerTests (LenFunctionTest.kt)
Why these changes improve the code
Testing
The changes have been verified for correctness. Two focused commits keep the fix and tests logically separated for easier review.
🤖 Generated with Claude Code