Skip to content

Conversation

@joonseolee
Copy link

Summary

  • Add Expect<CharSequence>.length feature extractor for fluent and infix APIs.

Related Issue


I confirm that I have read the Contributor Agreements v1.0, agree to be bound on them and confirm that my contribution is compliant.

@joonseolee joonseolee requested a review from robstoll as a code owner October 28, 2025 00:48
@joonseolee
Copy link
Author

@robstoll

Can you check this PR?

Copy link
Owner

@robstoll robstoll left a comment

Choose a reason for hiding this comment

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

@joonseolee looks already very good. Just an addition and we are good to merge

@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.30%. Comparing base (7426369) to head (ab01751).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2106      +/-   ##
============================================
- Coverage     91.31%   91.30%   -0.01%     
  Complexity      125      125              
============================================
  Files           467      468       +1     
  Lines          4776     4783       +7     
  Branches        242      242              
============================================
+ Hits           4361     4367       +6     
  Misses          366      366              
- Partials         49       50       +1     
Flag Coverage Δ
current 90.92% <100.00%> (-0.01%) ⬇️
current_windows 90.02% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@robstoll robstoll linked an issue Oct 28, 2025 that may be closed by this pull request
19 tasks
@joonseolee joonseolee force-pushed the feature/add-charsequence-length branch from 5bc99b8 to ab01751 Compare October 28, 2025 23:29
Comment on lines +54 to +55
public static final fun getLength (Lch/tutteli/atrium/creating/Expect;)Lch/tutteli/atrium/creating/Expect;
public static final fun length (Lch/tutteli/atrium/creating/Expect;Lkotlin/jvm/functions/Function1;)Lch/tutteli/atrium/creating/Expect;
Copy link
Owner

Choose a reason for hiding this comment

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

please re-run ./gradlew apiDump & KOTLIN_VERSION=1.9 ./gradlew apiDump once you have moved the code as outlined above

Comment on lines +21 to +34
("length" to Companion::lengthFeature).withFeatureSuffix(),
"length" to Companion::length
) {
companion object {
private fun toBeEmpty(expect: Expect<CharSequence>) = expect toBe empty
private fun notToBeEmpty(expect: Expect<CharSequence>) = expect notToBe empty
private fun notToBeBlank(expect: Expect<CharSequence>) = expect notToBe blank
private fun lengthFeature(expect: Expect<CharSequence>): Expect<Int> =
expect.length

private fun length(
expect: Expect<CharSequence>,
assertionCreator: Expect<Int>.() -> Unit
): Expect<Int> = expect.length.apply(assertionCreator)
Copy link
Owner

Choose a reason for hiding this comment

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

same same revert to what you had previously

a1 = a1 toMatch Regex(".+Robert")
a1 = a1 notToMatch Regex("a")

a1 = a1 length { it toEqual 23 }
Copy link
Owner

Choose a reason for hiding this comment

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

val l1 =...

toMatchSpec.forSubjectLessTest(Regex("")),
notToMatchSpec.forSubjectLessTest(Regex(""))
)

Copy link
Owner

Choose a reason for hiding this comment

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

also something I overlooked 🙈
Can you please add

  @TestFactory
    fun expectationCreatorTest() = expectationCreatorTestFactory(

Copy link
Collaborator

Choose a reason for hiding this comment

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

@robstoll - Do you mean you want a block for the expectationCreatorTest with the same logic as as the subjectLessTest?

Copy link
Owner

Choose a reason for hiding this comment

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

Each expectation function which expects an expectationCreator-lambda (i.e. length { ... } should have an

@TestFactory
    fun expectationCreatorTest() = expectationCreatorTestFactory(
   )

test. The test checks that an empty lambda causes an error.
I see that we should rename it to expectationCreatorEmptyTest but that's something we can do in a subsequent PR for all cases. Take a look at other usages of expectationCreatorTestFactory. Hope that helps

@robstoll
Copy link
Owner

@joonseolee do you intend to finish it or shall we take over?

@robstoll
Copy link
Owner

@TomerPacific would you like to take over? Something else than a migration for a change.

@TomerPacific
Copy link
Collaborator

TomerPacific commented Nov 19, 2025

@robstoll -
giphy

But I can't make any promises

@TomerPacific
Copy link
Collaborator

@robstoll - I am having compile issues in the ExpectationsTest classes (infix & fluent), but I believe these are due to the method definitions in the abstract class.
I have posted above how the Abstract class's constructor looks like.
This is how it looks like for one of the test classes:

class CharSequenceExpectationsTest : AbstractCharSequenceExpectationsTest(
    fun0(Expect<CharSequence>::toBeEmpty),
    fun0(Expect<CharSequence>::notToBeEmpty),
    fun0(Expect<CharSequence>::notToBeBlank),
    fun1(Expect<CharSequence>::toStartWith),
    fun1(Expect<CharSequence>::notToStartWith),
    fun1(Expect<CharSequence>::toEndWith),
    fun1(Expect<CharSequence>::notToEndWith),
    fun1(Expect<CharSequence>::toMatch),
    fun1(Expect<CharSequence>::notToMatch),
    property(Expect<CharSequence>::length),
    fun1(Expect<CharSequence>::length)
) {

Let me know what needs to be changed.

@robstoll
Copy link
Owner

@TomerPacific nothing needs to be changed there, that's all good. The problem is that you create a class CharSequenceFeatureExtractors in fluent/infix. Remove it, we want top-level functions (see other .kt files in the API)

@TomerPacific
Copy link
Collaborator

@TomerPacific nothing needs to be changed there, that's all good. The problem is that you create a class CharSequenceFeatureExtractors in fluent/infix. Remove it, we want top-level functions (see other .kt files in the API)

Regarding this, I did not create the class in infix and it seems to be in the right syntax.
Thing is, should the constructor of the CharSequenceExpectationsTest in infix look like this?

class CharSequenceExpectationsTest : AbstractCharSequenceExpectationsTest(
    "toBe ${empty::class.simpleName}" to Companion::toBeEmpty,
    "notToBe ${empty::class.simpleName}" to Companion::notToBeEmpty,
    "notToBe ${blank::class.simpleName}" to Companion::notToBeBlank,
    fun1(Expect<CharSequence>::toStartWith),
    fun1(Expect<CharSequence>::notToStartWith),
    fun1(Expect<CharSequence>::toEndWith),
    fun1(Expect<CharSequence>::notToEndWith),
    fun1(Expect<CharSequence>::toMatch),
    fun1(Expect<CharSequence>::notToMatch),
    property(Expect<CharSequence>::length),
    fun1(Expect<CharSequence>::length)
) {

I have looked at the previous commit and there is no change to the lines with the Companion reference, but I don't think those should remain.

@robstoll
Copy link
Owner

@TomerPacific regarding the infix-api, the following should work:

    property(Expect<CharSequence>::length),
    fun1(Expect<CharSequence>::length)

No need for the Companion, but you need to fix the constructor of AbstractCharSequenceExpectationsTest. Currently you still have:

    private val lengthFeatureSpec: Feature0<CharSequence, Int>,
    private val lengthSpec: Feature1<CharSequence, Expect<Int>.() -> Unit, Int>,

but as you pointed out here #2106 (comment), lengthSpec needs to be Fun1

@TomerPacific
Copy link
Collaborator

@robstoll - Been a bit busy this week. Hopefully I'll have time this weekend.

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.

Expect<CharSequence>.length

3 participants