Skip to content

Commit

Permalink
robstoll#482 accept date as string for chronozoneddatetime (robstoll#625
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Valefant committed Oct 15, 2020
1 parent dc2f223 commit 1a10575
Show file tree
Hide file tree
Showing 10 changed files with 769 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,173 @@ fun <T : ChronoZonedDateTime<out ChronoLocalDate>> Expect<T>.isAfterOrEqual(
fun <T : ChronoZonedDateTime<out ChronoLocalDate>> Expect<T>.isEqual(
expected: ChronoZonedDateTime<*>
): Expect<T> = _logicAppend { isEqual(expected) }

/**
* Expects that the subject of the assertion (a [ChronoZonedDateTime])
* is before the [expected] [ChronoZonedDateTime] given as [String].
*
* The format is composed of {DateTime}{ZoneDesignator}.
*
* DateTime:
* - yyyy-mm-ddThh:mm:ss.SSS (up to 9 digits for nanoseconds)
* - yyyy-mm-ddThh:mm:ss
* - yyyy-mm-ddThh:mm
* - yyyy-mm-dd
*
* And for ZoneDesignator:
* - Z
* - +hh
* - +hh:mm
* - -hh
* - -hh:mm
*
* Here are some examples on how it can look combined
* - 2020-01-02T03:04:05Z
* - 2020-01-02T03:04Z
* - 2020-01-02Z
* - 2020-01-02+01:30
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.14.0
*/
fun <T : ChronoZonedDateTime<out ChronoLocalDate>> Expect<T>.isBefore(
expected: String
): Expect<T> = _logicAppend { isBefore(expected) }

/**
* Expects that the subject of the assertion (a [ChronoZonedDateTime])
* is before or equals the [expected] [ChronoZonedDateTime] given as [String].
*
* The format is composed of {DateTime}{ZoneDesignator}.
*
* DateTime:
* - yyyy-mm-ddThh:mm:ss.SSS (up to 9 digits for nanoseconds)
* - yyyy-mm-ddThh:mm:ss
* - yyyy-mm-ddThh:mm
* - yyyy-mm-dd
*
* And for ZoneDesignator:
* - Z
* - +hh
* - +hh:mm
* - -hh
* - -hh:mm
*
* Here are some examples on how it can look combined
* - 2020-01-02T03:04:05Z
* - 2020-01-02T03:04Z
* - 2020-01-02Z
* - 2020-01-02+01:30
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.14.0
*/
fun <T : ChronoZonedDateTime<out ChronoLocalDate>> Expect<T>.isBeforeOrEqual(
expected: String
): Expect<T> = _logicAppend { isBeforeOrEqual(expected) }

/**
* Expects that the subject of the assertion (a [ChronoZonedDateTime])
* is after the [expected] [ChronoZonedDateTime] given as [String].
*
* The format is composed of {DateTime}{ZoneDesignator}.
*
* DateTime:
* - yyyy-mm-ddThh:mm:ss.SSS (up to 9 digits for nanoseconds)
* - yyyy-mm-ddThh:mm:ss
* - yyyy-mm-ddThh:mm
* - yyyy-mm-dd
*
* And for ZoneDesignator:
* - Z
* - +hh
* - +hh:mm
* - -hh
* - -hh:mm
*
* Here are some examples on how it can look combined
* - 2020-01-02T03:04:05Z
* - 2020-01-02T03:04Z
* - 2020-01-02Z
* - 2020-01-02+01:30
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.14.0
*/
fun <T : ChronoZonedDateTime<out ChronoLocalDate>> Expect<T>.isAfter(
expected: String
): Expect<T> = _logicAppend { isAfter(expected) }

/**
* Expects that the subject of the assertion (a [ChronoZonedDateTime])
* is after or equal the [expected] [ChronoZonedDateTime] given as [String].
*
* The format is composed of {DateTime}{ZoneDesignator}.
*
* DateTime:
* - yyyy-mm-ddThh:mm:ss.SSS (up to 9 digits for nanoseconds)
* - yyyy-mm-ddThh:mm:ss
* - yyyy-mm-ddThh:mm
* - yyyy-mm-dd
*
* And for ZoneDesignator:
* - Z
* - +hh
* - +hh:mm
* - -hh
* - -hh:mm
*
* Here are some examples on how it can look combined
* - 2020-01-02T03:04:05Z
* - 2020-01-02T03:04Z
* - 2020-01-02Z
* - 2020-01-02+01:30
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.14.0
*/
fun <T : ChronoZonedDateTime<out ChronoLocalDate>> Expect<T>.isAfterOrEqual(
expected: String
): Expect<T> = _logicAppend { isAfterOrEqual(expected) }

/**
* Expects that the subject of the assertion (a [ChronoZonedDateTime])
* is equal to the [expected] [ChronoZonedDateTime] given as [String].
*
* The format is composed of {DateTime}{ZoneDesignator}.
*
* DateTime:
* - yyyy-mm-ddThh:mm:ss.SSS (up to 9 digits for nanoseconds)
* - yyyy-mm-ddThh:mm:ss
* - yyyy-mm-ddThh:mm
* - yyyy-mm-dd
*
* And for ZoneDesignator:
* - Z
* - +hh
* - +hh:mm
* - -hh
* - -hh:mm
*
* Here are some examples on how it can look combined
* - 2020-01-02T03:04:05Z
* - 2020-01-02T03:04Z
* - 2020-01-02Z
* - 2020-01-02+01:30
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.14.0
*/
fun <T : ChronoZonedDateTime<out ChronoLocalDate>> Expect<T>.isEqual(
expected: String
): Expect<T> = _logicAppend { isEqual(expected) }
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ class ChronoZonedDateTimeAssertionSpec : Spek({
include(ChronoLocalDateTimeAssertionSpec.ChronoLocalDateTimeSpec)
}) {
object ChronoZonedDateTimeSpec : ch.tutteli.atrium.specs.integration.ChronoZonedDateTimeAssertionSpec(
fun1(Expect<ChronoZonedDateTime<*>>::isBefore),
fun1(Expect<ChronoZonedDateTime<*>>::isBeforeOrEqual),
fun1(Expect<ChronoZonedDateTime<*>>::isAfter),
fun1(Expect<ChronoZonedDateTime<*>>::isAfterOrEqual),
fun1(Expect<ChronoZonedDateTime<*>>::isEqual)
fun1<ChronoZonedDateTime<*>, ChronoZonedDateTime<*>>(Expect<ChronoZonedDateTime<*>>::isBefore),
fun1<ChronoZonedDateTime<*>, ChronoZonedDateTime<*>>(Expect<ChronoZonedDateTime<*>>::isBeforeOrEqual),
fun1<ChronoZonedDateTime<*>, ChronoZonedDateTime<*>>(Expect<ChronoZonedDateTime<*>>::isAfter),
fun1<ChronoZonedDateTime<*>, ChronoZonedDateTime<*>>(Expect<ChronoZonedDateTime<*>>::isAfterOrEqual),
fun1<ChronoZonedDateTime<*>, ChronoZonedDateTime<*>>(Expect<ChronoZonedDateTime<*>>::isEqual)
)

companion object {
fun isBefore(
expect: Expect<ChronoZonedDateTime<*>>,
expected: ChronoZonedDateTime<*>
): Expect<ChronoZonedDateTime<*>> =
//TODO #482 turn into string in ISO format
expect.isBefore(expected)
}
object ChronoZonedDateTimeAsStringSpec : ch.tutteli.atrium.specs.integration.ChronoZonedDateTimeAsStringAssertionSpec(
fun1<ChronoZonedDateTime<*>, String>(Expect<ChronoZonedDateTime<*>>::isBefore),
fun1<ChronoZonedDateTime<*>, String>(Expect<ChronoZonedDateTime<*>>::isBeforeOrEqual),
fun1<ChronoZonedDateTime<*>, String>(Expect<ChronoZonedDateTime<*>>::isAfter),
fun1<ChronoZonedDateTime<*>, String>(Expect<ChronoZonedDateTime<*>>::isAfterOrEqual),
fun1<ChronoZonedDateTime<*>, String>(Expect<ChronoZonedDateTime<*>>::isEqual)
)

@Suppress("unused", "UNUSED_VALUE")
private fun ambiguityTest() {
Expand Down Expand Up @@ -86,5 +85,29 @@ class ChronoZonedDateTimeAssertionSpec : Spek({
a4 = a4.isAfter(chronoZonedDateTime)
a4 = a4.isAfterOrEqual(chronoZonedDateTime)
a4 = a4.isEqual(chronoZonedDateTime)

a1 = a1.isBefore("also not ambiguous if string is passed")
a1 = a1.isBeforeOrEqual("also not ambiguous if string is passed")
a1 = a1.isAfter("also not ambiguous if string is passed")
a1 = a1.isAfterOrEqual("also not ambiguous if string is passed")
a1 = a1.isEqual("also not ambiguous if string is passed")

a2 = a2.isBefore("also not ambiguous if string is passed")
a2 = a2.isBeforeOrEqual("also not ambiguous if string is passed")
a2 = a2.isAfter("also not ambiguous if string is passed")
a2 = a2.isAfterOrEqual("also not ambiguous if string is passed")
a2 = a2.isEqual("also not ambiguous if string is passed")

a3 = a3.isBefore("also not ambiguous if string is passed")
a3 = a3.isBeforeOrEqual("also not ambiguous if string is passed")
a3 = a3.isAfter("also not ambiguous if string is passed")
a3 = a3.isAfterOrEqual("also not ambiguous if string is passed")
a3 = a3.isEqual("also not ambiguous if string is passed")

a4 = a4.isBefore("also not ambiguous if string is passed")
a4 = a4.isBeforeOrEqual("also not ambiguous if string is passed")
a4 = a4.isAfter("also not ambiguous if string is passed")
a4 = a4.isAfterOrEqual("also not ambiguous if string is passed")
a4 = a4.isEqual("also not ambiguous if string is passed")
}
}
Loading

0 comments on commit 1a10575

Please sign in to comment.