Skip to content

tests: add edge-case tests for str_pad()#611

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

tests: add edge-case tests for str_pad()#611
LeonidasZhak wants to merge 1 commit into
tidyverse:mainfrom
LeonidasZhak:tests/str-pad-edge-cases

Conversation

@LeonidasZhak

Copy link
Copy Markdown

Summary

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

Rationale

str_pad() is a key text formatting function used in data cleaning pipelines (e.g., padding IDs to fixed width, formatting numeric codes, aligning text for display). The existing test file (45 lines, 9 expectations) only covered:

  1. Long strings unchanged (random test)
  2. Directions (left/right/both) with simple case
  3. Chinese character width
  4. Recycling rules
  5. Names preservation (left side only)

Missing coverage for common data cleaning scenarios:

  1. NA value handling — No tests for NA preservation through padding
  2. Empty input — Empty string and empty character vector untested
  3. Custom pad characters — Only default space tested
  4. Width of 0 — Behavior with zero width untested
  5. Boundary widths — Width equal to or less than string width untested
  6. Vectorised width — Element-wise width processing untested
  7. Vectorised pad — Element-wise pad character processing untested
  8. Names preservation — Only left side tested; right and both untested

Tests Added (12 test blocks, 33 new expectations)

  1. str_pad() handles NA values — Single NA, mixed NA/vector, NA with right/both sides
  2. str_pad() handles empty strings — Empty string with all sides, width 0, width 1
  3. str_pad() handles empty character(0) — Empty vector with left and right sides
  4. str_pad() respects custom pad character — 0, -, ., * with all sides
  5. str_pad() handles width of 0 — No padding applied
  6. str_pad() does not pad when width equals string width — All sides
  7. str_pad() does not pad when width is less than string width — Width 3, 1, 0
  8. str_pad() vectorises width — Left and right sides
  9. str_pad() vectorises pad — Left and right sides
  10. str_pad() preserves names for all sides — Left, right, both
  11. str_pad() validates inputs — Invalid side, invalid use_width type

Validation

  • Rscript -e 'devtools::test(filter = "pad")' — 0 failures, 42 passes (9 existing + 33 new)
  • Full test suite: 2 pre-existing snapshot mismatches in test-sub.R (unrelated), all other tests pass
  • No regressions in existing tests

Add 12 new test blocks covering common data cleaning scenarios:

- NA handling (single NA, mixed vector, all sides)
- Empty string and empty character(0) input
- Custom pad characters (0, -, ., *)
- Width of 0 (no padding)
- Width equal to string width (no padding needed)
- Width less than string width (unchanged)
- Vectorised width parameter
- Vectorised pad parameter
- Names preservation for all sides (left, right, both)
- Input validation (invalid side, invalid use_width type)

Total: 33 new test expectations (9 existing + 33 new = 42 total).
@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