r

    robstoll

    1 year ago
    The name of the function is not the best as you proved. In case someone has a better name then please share your idea
    j

    jdornieden

    1 year ago
    If I understand this function correctly, it’s only needed to handle nulls when using assertion creator lambdas. Instead of renaming: What do you think about adding a “toBeNull()” and extend “expectLambda()” to accept Expect<T?>. Null wouldn’t be a special case anymore and you could just use:
    _expect_("calling myNullableFun with ...") *{*
    *   *_mapOf_(
         
    Int.MIN_VALUE _to expectLambda_<String> *{* _contains_("min") *}*,
         
    -1 _to expectLambda_ *{* toBeNull() *}*,
         
    0 _to expectLambda_ *{* toBeNull() *}*,
         
    1 _to expectLambda_ *{* _toBe_("1") *}*,
         
    2 _to expectLambda_ *{* _endsWith_("2") *}*,
         
    Int.MAX_VALUE _to expectLambda_ *{* _toBe_("max") *}*
    *   *)._forEach_ *{* (arg, assertionCreatorOrNull) *->*
    *     *_feature_ *{* f(::myNullableFun, arg) *}*
       
    }
    }
    r

    robstoll

    1 year ago
    As info, you can already use
    toBe(null)
    How are you going to use the assertionCreatorOrNull in your example, you missed to show it? Actually,
    expectLambda
    should already accept
    T
    without any upper bound which is the same as
    T: Any?
    If that's not the case, then we should fix it
    j

    jdornieden

    1 year ago
    Yeah, you’re right. That was a copy & paste error:
    expect("calling myNullableFun with ...") {
       mapOf(
         Int.MIN_VALUE to expectLambda<String> { contains("min") },
         -1 to expectLambda { toBeNull() },
         0 to expectLambda { toBeNull() },
         1 to expectLambda { toBe("1") },
         2 to expectLambda { endsWith("2") },
         Int.MAX_VALUE to expectLambda { toBe("max") }
       ).forEach { (arg, assertionCreator) ->
         feature( { f(::myNullableFun, arg) }, assertionCreator)
       }
    }
    Basically I wondered if it is necessary to have a special treatment for null or if it was possible to combine the two Data Driven Testing examples (Readme) into one simpler example.
    The current signature of expectLambda is “fun <T> expectLambda(noinline assertionCreator: Expect<T>.() -> Unit)“, so it’s not possible to use it with nullable types at the moment. I think the same applies to toBe.
    r

    robstoll

    1 year ago
    It is,
    T
    means
    T: Any?
    , you should be able to write:
    expectLambda<Int?> { toBe(null) }
    No?
    j

    jdornieden

    1 year ago
    Yes, you are right. I forget to change the type to String? in the example...🙄 Here is the already working example:
    expect("calling myNullableFun with ...") {
       mapOf(
         Int.MIN_VALUE to expectLambda<String?> { notToBeNull().contains("min") },
         -1 to expectLambda { toBe(null) },
         0 to expectLambda { toBe(null) },
         1 to expectLambda { toBe("1") },
         2 to expectLambda { notToBeNull().endsWith("2") },
         Int.MAX_VALUE to expectLambda { toBe("max") }
       ).forEach { (arg, assertionCreator) ->
         feature( { f(::myNullableFun, arg) }, assertionCreator)
       }
    }