Skip to content

tests: add edge-case tests for str_count()#609

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

tests: add edge-case tests for str_count()#609
LeonidasZhak wants to merge 1 commit into
tidyverse:mainfrom
LeonidasZhak:tests/str-count-edge-cases

Conversation

@LeonidasZhak

Copy link
Copy Markdown

Summary

Adds edge-case tests for str_count() covering data cleaning scenarios that were previously untested.

Tests Added

  1. NA input handlingstr_count(NA, "a") returns NA_integer_; vector with mixed NA propagates correctly
  2. Empty string inputstr_count("", "a") returns 0L; empty character vector returns integer()
  3. NA pattern errorsstr_count("abc", NA_character_) errors with informative message
  4. Non-overlapping regex matches — Verifies correct counting of non-overlapping regex matches (e.g., "aaa" with "aa" counts 1, "aaaa" counts 2)
  5. Multibyte characters — Counting accented characters and CJK characters works correctly

Validation

  • All 22 tests pass (was 12 before): devtools::load_all(); test_file('tests/testthat/test-count.R')
  • No regressions in existing tests
  • No snapshot files needed (uses expect_error() instead of expect_snapshot() for error test)

Files Changed

  • tests/testthat/test-count.R — Added 25 lines (5 test blocks)

- NA input returns NA_integer_
- Empty string returns 0L
- Empty character vector returns integer()
- NA pattern errors with informative message
- Non-overlapping regex match counting
- Multibyte character counting
@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