Skip to content

feat(assert): add contains assertion#10

Merged
KyleKincer merged 1 commit intomainfrom
codex/identify-and-implement-unit-testing-improvement
Aug 23, 2025
Merged

feat(assert): add contains assertion#10
KyleKincer merged 1 commit intomainfrom
codex/identify-and-implement-unit-testing-improvement

Conversation

@KyleKincer
Copy link
Copy Markdown
Owner

@KyleKincer KyleKincer commented Aug 23, 2025

Summary

  • add assert.contains to validate substring or collection membership
  • document new assertion
  • cover new assertion with unit tests

Testing

  • make test

https://chatgpt.com/codex/tasks/task_e_68aa359daad88324bd505a329da70ae8

Summary by CodeRabbit

  • New Features
    • Added a contains assertion to the assertion library to verify that text or collections include a given value, with clear failure messages for non-containment or unsupported types.
  • Documentation
    • Updated the guide to document the new contains assertion and its usage.
  • Tests
    • Added test coverage for contains across text and collection scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 23, 2025

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/identify-and-implement-unit-testing-improvement

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (4)
docs/guide.md (1)

138-139: Document behavior details for assert.contains (types, case-sensitivity, defaults).

The new bullet is good. Please add concise notes so users know exactly how it behaves: supported container types (Text, Collection), case-sensitivity for Text, value coercion to Text in the Text branch, and default failure messages when message is omitted. Also add a short usage snippet.

Apply this inline clarification under the new bullet:

- - `$t.assert.contains($t; $container; $value; $message)` - Text or collection must contain value
+ - `$t.assert.contains($t; $container; $value; $message)` - Text or collection must contain value
+   - Supported containers: Text, Collection
+   - Text containment is case-sensitive; `$value` is coerced with `String($value)`
+   - Unsupported container types fail the assertion
+   - When `$message` is omitted, a default failure message is used

And add a compact example to the Usage Example section:

@@
     $t.assert.isNotNull($t; $result; "Function should return a result")
+    
+    // Contains examples
+    $t.assert.contains($t; "hello world"; "world"; "Substring should be present")
+    var $letters : Collection
+    $letters:=["a"; "b"; "c"]
+    $t.assert.contains($t; $letters; "b"; "Collection should contain element")
testing/Project/Sources/Classes/Assert.4dm (1)

56-83: Confirm intended semantics (case-sensitivity, empty Text, and default messages) and consider small polish.

Current implementation is correct: Text uses Position(String($value); $container)>0 and Collection uses indexOf($value)#-1, with sensible defaults/messages for unsupported types and non-membership.

Two follow-ups to lock behavior down and improve debuggability:

  • Decide and document explicit behavior for empty substrings (String(Null) -> "" and String("") cases). Many frameworks treat empty substring as contained; if you prefer fail, guard for it and test it.
  • Consider richer default failure messages that include the searched value to aid debugging.

Optional polish to include the searched value in the default non-membership message:

-                        This.fail($t; "Assertion failed: container does not contain value")
+                        This.fail($t; "Assertion failed: container does not contain value '" + String:C10($value) + "'")

If you want empty-text to explicitly fail (rather than whatever Position does for ""), add this guard in the Text branch:

                 : ($type=Is text:K8:3)
-                        $found:=(Position:C15(String:C10($value); $container)>0)
+                        If (String:C10($value)="")
+                                $found:=False  // decide: treat empty needle as not contained
+                        Else
+                                $found:=(Position:C15(String:C10($value); $container)>0)
+                        End if
testing/Project/Sources/Classes/_AssertTest.4dm (2)

172-184: Good coverage for Text containment; add edge-case tests (case and default message).

These tests validate pass/fail paths. Please add:

  • Case-sensitivity check ("Hello" vs "hello").
  • Default message path (omit $message) to lock contract.

Suggested additions (can be placed after this block):

Function test_contains_text_case_sensitivity($t : cs:C1710.Testing)
    var $mockTest : cs:C1710.Testing
    $mockTest:=cs:C1710.Testing.new()

    // Expect fail if comparison is case-sensitive
    $t.assert.contains($mockTest; "Hello"; "hello")
    $t.assert.isTrue($t; $mockTest.failed; "Case-sensitive mismatch should fail")

Function test_contains_text_default_message($t : cs:C1710.Testing)
    var $mockTest : cs:C1710.Testing
    $mockTest:=cs:C1710.Testing.new()

    // Omit message to exercise default message
    $t.assert.contains($mockTest; "abc"; "z")
    $t.assert.isTrue($t; $mockTest.failed; "Missing value should fail")
    $t.assert.areEqual($t; "Assertion failed: container does not contain value"; $mockTest.logMessages[0]; "Should use default message")

185-199: Solid Collection tests; add unsupported-type and default-message coverage.

Please add a test ensuring unsupported containers fail with the expected default message.

Suggested addition:

Function test_contains_unsupported_type_defaults($t : cs:C1710.Testing)
    var $mockTest : cs:C1710.Testing
    $mockTest:=cs:C1710.Testing.new()

    var $obj : Object
    $obj:=New object()

    // Unsupported container type should fail with default message
    $t.assert.contains($mockTest; $obj; "x")
    $t.assert.isTrue($t; $mockTest.failed; "Unsupported type should fail")
    $t.assert.areEqual($t; "Assertion failed: unsupported type for contains"; $mockTest.logMessages[0]; "Should use default unsupported-type message")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a6f4c6f and 45dc7d8.

📒 Files selected for processing (3)
  • docs/guide.md (1 hunks)
  • testing/Project/Sources/Classes/Assert.4dm (1 hunks)
  • testing/Project/Sources/Classes/_AssertTest.4dm (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
testing/Project/Sources/Classes/*Test.4dm

📄 CodeRabbit inference engine (CLAUDE.md)

testing/Project/Sources/Classes/*Test.4dm: Name test classes with the suffix "Test" so they are auto-discovered
Define test methods with the prefix "test_" within test classes to be executed by the runner
Use comment-based tagging in tests with the exact format: // #tags: tag1, tag2
Disable automatic transactions for a specific test by adding the comment: // #transaction: false; omit the comment to keep the default rollback behavior
When manual transaction control is needed (with automatic transactions disabled), use the Testing context methods: startTransaction, inTransaction, validateTransaction, cancelTransaction, or wrappers withTransaction/withTransactionValidate

Files:

  • testing/Project/Sources/Classes/_AssertTest.4dm
🔇 Additional comments (2)
testing/Project/Sources/Classes/Assert.4dm (1)

48-55: Indent-only tweak in isNotNull — OK.

No behavioral change; reads fine.

testing/Project/Sources/Classes/_AssertTest.4dm (1)

160-171: Indentation-only changes — OK.

No logic change; test intent preserved.

@KyleKincer KyleKincer merged commit 01d883f into main Aug 23, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant