Skip to content

tests: add edge-case tests for str_wrap()#610

Closed
LeonidasZhak wants to merge 1 commit into
tidyverse:mainfrom
LeonidasZhak:tests/str-wrap-edge-cases
Closed

tests: add edge-case tests for str_wrap()#610
LeonidasZhak wants to merge 1 commit into
tidyverse:mainfrom
LeonidasZhak:tests/str-wrap-edge-cases

Conversation

@LeonidasZhak

Copy link
Copy Markdown

Summary

Adds edge-case tests for str_wrap() covering common data cleaning scenarios that had limited test coverage.

Changes

File: tests/testthat/test-wrap.R (+51 lines)

Tests Added (8 test blocks)

  1. str_wrap() handles NA values — Verifies NA preservation for single NA, mixed NA/vector, and NA in middle of vector
  2. str_wrap() handles empty input — Empty string and empty character vector
  3. str_wrap() works with vector input — Element-wise processing of character vectors
  4. str_wrap() respects indent parameter — First line indentation
  5. str_wrap() respects exdent parameter — Subsequent line indentation
  6. str_wrap() handles single word longer than width — Word longer than target width is not broken
  7. str_wrap() collapses multiple whitespace — Leading/trailing/internal whitespace normalization
  8. str_wrap() validates its inputs — Error on invalid width, indent, exdent, whitespace_only

Motivation

str_wrap() is a key text formatting function used in data cleaning pipelines (e.g., formatting labels, wrapping long strings). The existing tests (23 lines) only covered basic wrapping, whitespace-only mode, and name preservation. These additions cover common edge cases encountered when processing real-world text data.

Testing

  • devtools::test(filter = "wrap"): 0 failures, 20 passes (4 existing + 16 new)
  • No regressions in existing tests

Add tests covering:
- NA value preservation (single NA, mixed NA/vector, NA in middle)
- Empty string and empty character vector handling
- Vector input processing
- indent parameter (first line indentation)
- exdent parameter (subsequent line indentation)
- Single word longer than width (no wrapping)
- Multiple whitespace collapsing
- Input validation (width, indent, exdent, whitespace_only)
@LeonidasZhak

Copy link
Copy Markdown
Author

Withdrawing this small automated PR while I consolidate an oversized batch of contributions and reduce maintainer review burden. Sorry for the noise, and thank you for maintaining the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant