Skip to content

Add unit tests for String and CompiledMethod codegen primitives (BT-2150)#2175

Merged
jamesc merged 3 commits intomainfrom
BT-2150-string-compiledmethod-codegen-tests
May 7, 2026
Merged

Add unit tests for String and CompiledMethod codegen primitives (BT-2150)#2175
jamesc merged 3 commits intomainfrom
BT-2150-string-compiledmethod-codegen-tests

Conversation

@jamesc
Copy link
Copy Markdown
Owner

@jamesc jamesc commented May 7, 2026

Summary

Closes BT-2150

string.rs and reflection.rs (CompiledMethod section) in crates/beamtalk-core/src/codegen/core_erlang/primitives/ were both severely under-tested. Coverage data from CI run 25428951201 showed:

  • string.rs: 8.9% (14/145 lines) — only length and ++ exercised
  • reflection.rs CompiledMethod: 0% — all 6 selectors uncovered

Changes

Adds 92 tests to the existing #[cfg(test)] mod tests block in primitives/mod.rs, following the exact pattern established by BT-2147 (Array + Dictionary):

  • String transform (9 tests): at:, uppercase, lowercase, capitalize, trim, trimLeft, trimRight, reverse, , concat
  • String search (17 tests): includes:, startsWith:, endsWith:, indexOf:, split:, splitOn:, repeat:, lines, words, replaceAll:with:, replaceFirst:with:, take:, drop:, padLeft:, padRight:, padLeft:with:, padRight:with:
  • String misc (17 tests): isBlank, isDigit, isAlpha, asInteger, asFloat, asAtom, asList, each:, collect:, select:, reject:, stream, withAll:, fromCodePoint:, fromCodePoints:, fromIolist:, unknown→None
  • String regex (7 tests): matchesRegex:, matchesRegex:options:, firstMatch:, allMatches:, replaceRegex:with:, replaceAllRegex:with:, splitRegex:
  • String comparison (7 tests): =:=, /=, =/=, <, >, <=, >=
  • CompiledMethod (7 tests): selector, source, doc, argumentCount, printString, asString, unknown→None

Zero production code changes. Primitives test count: 110 → 202.

Test plan

  • cargo test -p beamtalk-core — 3411 tests pass (0 failed)
  • cargo clippy -p beamtalk-core -- -D warnings — clean
  • cargo fmt --check -p beamtalk-core — clean
  • string.rs coverage expected to rise from 8.9% to ≥95%
  • CompiledMethod coverage expected to rise from 0% to 100%

https://claude.ai/code/session_01T8TqFpxfyaJFntxm8GQG19


Generated by Claude Code

Summary by CodeRabbit

  • Tests
    • Significantly expanded unit test coverage for string primitives covering transforms, searches, comparisons, regex behavior, and miscellaneous selectors.
    • Added comprehensive tests validating compiler method selector outputs (including documented fields and argument handling) and preserved existing dictionary/unknown-selector test patterns.

… (BT-2150)

String.rs was at 8.9% line coverage (14/145 lines) with only `length`
and `++` tested. CompiledMethod had 0% coverage across all 6 selectors.

Adds 92 new #[cfg(test)] tests to the existing primitives/mod.rs block:

- String transform group: at:, uppercase, lowercase, capitalize, trim,
  trimLeft, trimRight, reverse, comma-concat
- String search group: includes:, startsWith:, endsWith:, indexOf:,
  split:, splitOn:, repeat:, lines, words, replaceAll:with:,
  replaceFirst:with:, take:, drop:, padLeft:, padRight:,
  padLeft:with:, padRight:with:
- String misc group: isBlank, isDigit, isAlpha, asInteger, asFloat,
  asAtom, asList, each:, collect:, select:, reject:, stream,
  withAll:, fromCodePoint:, fromCodePoints:, fromIolist:, unknown→None
- String regex group (BT-709): matchesRegex:, matchesRegex:options:,
  firstMatch:, allMatches:, replaceRegex:with:, replaceAllRegex:with:,
  splitRegex:
- String comparison group: =:=, /=, =/=, <, >, <=, >=
- CompiledMethod: selector, source, doc, argumentCount, printString,
  asString, unknown→None

Zero production code changes. Primitives test count: 110 → 202.
3411 total tests pass (was 3319 before BT-2147 landed array/dictionary).

https://claude.ai/code/session_01T8TqFpxfyaJFntxm8GQG19
Copilot AI review requested due to automatic review settings May 7, 2026 02:26
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b6754a60-f942-4869-bf78-65c6bb992958

📥 Commits

Reviewing files that changed from the base of the PR and between 6748297 and dac32cd.

📒 Files selected for processing (1)
  • crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs

📝 Walkthrough

Walkthrough

This PR expands the unit test suite in crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs, adding extensive String primitive tests (transforms, search/split/replace, slicing/pad, misc, comparisons, regex) and CompiledMethod selector tests, plus preserved unknown-selector checks.

Changes

Core Erlang Primitives — Tests

Layer / File(s) Summary
Transform-style String tests
crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Adds tests for indexing (at:), case conversions (uppercase, lowercase, capitalize), trimming, reversing, and concatenation, asserting generated Core Erlang document strings or expected iolist/binary forms.
Search / Split / Replace tests
crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Adds tests for includes:, startsWith:, endsWith:, indexOf:, split:, splitOn:, repeat:, lines, words, replaceAll, replaceFirst, asserting exact calls and option arrays where applicable.
Slicing / Padding tests
crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Adds take:, drop:, padLeft/padRight, and padLeft:with:/padRight:with: tests, asserting usage of unicode:characters_to_binary around string/padding operations.
Misc / Iteration / Factory tests
crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Adds isBlank, isDigit, isAlpha, asInteger, asFloat, asAtom, asList, each:, collect:, select:, reject:, stream, factory methods (withAll:, fromCodePoint:, fromCodePoints:, fromIolist:) tests and a String unknown-selector test.
Comparison operator tests
crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Adds equality/inequality and ordering tests (=, /=, =:=, </>, <=/>=) asserting exact erlang comparison BIF calls in generated output.
Regex-related String tests (BT-709)
crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Adds matchesRegex:, matchesRegex:options:, firstMatch:, allMatches:, replaceRegex:with:, replaceAllRegex:with:, splitRegex: tests asserting beamtalk_regex:* call forms and option handling.
CompiledMethod selector tests
crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Adds tests asserting generate_primitive_bif emits beamtalk_compiled_method_ops:dispatch for selectors: selector, source, doc, argumentCount, printString, asString, plus an unknown-selector test expecting None.
Preserved Dictionary unknown-selector test
crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Retains the existing Dictionary unknown-selector test asserting generate_primitive_bif returns None for unrecognized method names.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding unit tests for String and CompiledMethod codegen primitives, with specific ticket reference (BT-2150).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BT-2150-string-compiledmethod-codegen-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs`:
- Around line 1061-1072: The tests like test_string_split (and similar tests at
ranges 1118-1144, 1172-1222, 1491-1554) only assert substrings and can miss
regressions; update these tests to assert the exact rendered Core Erlang output
instead of loose contains() checks: use
doc_to_string(generate_primitive_bif(...)) -> result.unwrap() and then
assert_eq!(output, "<expected full Core Erlang string>") (or at minimum assert
the exact call form and full argument order/token sequence, e.g. verify
"binary':'split'(..., 'global')" including Sep, order of arguments like 'Sep'
and any N/Pat/Repl parameters). Locate these cases around the
generate_primitive_bif/document rendering usages (e.g. test_string_split) and
replace the contains() assertions with assert_eq! or precise string
equality/assertions that include the full call shape.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f2eb6188-3b3b-41c0-a347-b506ef8ad551

📥 Commits

Reviewing files that changed from the base of the PR and between 80cef8d and 6748297.

📒 Files selected for processing (1)
  • crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs

Comment thread crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds substantial unit-test coverage for Core Erlang primitive codegen mappings for String and CompiledMethod within beamtalk-core, exercising many previously-uncovered selector→BIF/codegen paths.

Changes:

  • Add a large suite of String primitive tests covering transform/search/misc/comparison/regex selector mappings.
  • Add CompiledMethod primitive tests covering all supported selectors plus an unknown-selector None case.

Comment thread crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
Comment thread crates/beamtalk-core/src/codegen/core_erlang/primitives/mod.rs
… tests (BT-2150)

Address CodeRabbit and Copilot review findings:

- Replace loose contains() checks with exact assert_eq! on full Core
  Erlang output for all multi-arg and factory String tests:
  split:, replaceAll:with:, replaceFirst:with:, padLeft:, padRight:,
  padLeft:with:, padRight:with:, matchesRegex:options:,
  replaceRegex:with:, replaceAllRegex:with:, withAll:, fromCodePoint:,
  fromCodePoints:, fromIolist:, ,/comma-concat
- padLeft:with: and padRight:with: now assert both N and Ch are present
  in the correct argument order

https://claude.ai/code/session_01T8TqFpxfyaJFntxm8GQG19
@jamesc jamesc merged commit 5b69068 into main May 7, 2026
9 checks passed
@jamesc jamesc deleted the BT-2150-string-compiledmethod-codegen-tests branch May 7, 2026 07:10
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.

3 participants