Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Nov 19, 2023
1 parent 6b971d5 commit 03e6d9a
Show file tree
Hide file tree
Showing 75 changed files with 4,240 additions and 4,098 deletions.
51 changes: 25 additions & 26 deletions site/src/orchid/kotlin/strikt/docs/StriktModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,29 @@ class StriktModule : OrchidModule() {
}

class StriktTheme
@Inject
constructor(context: OrchidContext) : Theme(context, "StriktTheme", DEFAULT_PRIORITY + 1) {

private val delegateTheme = CopperTheme(context)

@Option
lateinit var social: Social

override fun loadAssets(delegate: AssetManagerDelegate) {
delegate.addCss("assets/css/bulma.min.css")
delegate.addCss("assets/css/bulma-tooltip.css")
delegate.addCss("assets/css/bulma-accordion.min.css")

delegate.addJs("https://use.fontawesome.com/releases/v5.4.0/js/all.js").apply { defer = true }
delegate.addJs("assets/js/bulma.js")
delegate.addJs("assets/js/bulma-accordion.min.js")
delegate.addJs("assets/js/bulma-tabs.js")
@Inject
constructor(context: OrchidContext) : Theme(context, "StriktTheme", DEFAULT_PRIORITY + 1) {
private val delegateTheme = CopperTheme(context)

@Option
lateinit var social: Social

override fun loadAssets(delegate: AssetManagerDelegate) {
delegate.addCss("assets/css/bulma.min.css")
delegate.addCss("assets/css/bulma-tooltip.css")
delegate.addCss("assets/css/bulma-accordion.min.css")

delegate.addJs("https://use.fontawesome.com/releases/v5.4.0/js/all.js").apply { defer = true }
delegate.addJs("assets/js/bulma.js")
delegate.addJs("assets/js/bulma-accordion.min.js")
delegate.addJs("assets/js/bulma-tabs.js")
}

override fun getResourceSource(): OrchidResourceSource =
DelegatingResourceSource(
listOfNotNull(super.getResourceSource(), delegateTheme.resourceSource),
emptyList(),
priority,
ThemeResourceSource
)
}

override fun getResourceSource(): OrchidResourceSource =
DelegatingResourceSource(
listOfNotNull(super.getResourceSource(), delegateTheme.resourceSource),
emptyList(),
priority,
ThemeResourceSource
)
}
1 change: 1 addition & 0 deletions strikt-arrow/src/main/kotlin/strikt/arrow/Option.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:Suppress("DEPRECATION")

package strikt.arrow

import arrow.core.None
Expand Down
96 changes: 48 additions & 48 deletions strikt-arrow/src/test/kotlin/strikt/arrow/EitherAssertions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,70 @@ import strikt.assertions.isNotNull

@DisplayName("assertions on Either")
object EitherAssertions : JUnit5Minutests {
fun tests() =
rootContext {
derivedContext<Assertion.Builder<Either<String, *>>>("leftEither") {
fixture {
expectThat(Either.Left("left"))
}

fun tests() = rootContext {
derivedContext<Assertion.Builder<Either<String, *>>>("leftEither") {
fixture {
expectThat(Either.Left("left"))
}

test("can assert on type") {
isLeft()
}
test("can assert on type") {
isLeft()
}

test("can assert on type and value equality") {
isLeft("left")
}
test("can assert on type and value equality") {
isLeft("left")
}

test("can assert on type and traverse unwrapped value") {
isLeft().value isEqualTo "left"
test("can assert on type and traverse unwrapped value") {
isLeft().value isEqualTo "left"
}
}
}

derivedContext<Assertion.Builder<Either<MyTuple, *>>>("leftEither") {
fixture {
expectThat(Either.Left(MyTuple("myName", 1, "uuid")))
}
derivedContext<Assertion.Builder<Either<MyTuple, *>>>("leftEither") {
fixture {
expectThat(Either.Left(MyTuple("myName", 1, "uuid")))
}

test("can have nested assertions on unwrapped value") {
isLeft().value.and {
get { name } isEqualTo "myName"
get { id }.isNotNull() isGreaterThan 0L
get { uuid }.isNotNull().isNotBlank()
test("can have nested assertions on unwrapped value") {
isLeft().value.and {
get { name } isEqualTo "myName"
get { id }.isNotNull() isGreaterThan 0L
get { uuid }.isNotNull().isNotBlank()
}
}
}
}

derivedContext<Assertion.Builder<Either<*, String>>>("rightEither") {
fixture {
expectThat(Either.Right("right"))
}
derivedContext<Assertion.Builder<Either<*, String>>>("rightEither") {
fixture {
expectThat(Either.Right("right"))
}

test("can assert on type") {
isRight()
}
test("can assert on type") {
isRight()
}

test("can assert on type and value equality") {
isRight("right")
}
test("can assert on type and value equality") {
isRight("right")
}

test("can assert on type and traverse unwrapped value") {
isRight().value.isEqualTo("right")
test("can assert on type and traverse unwrapped value") {
isRight().value.isEqualTo("right")
}
}
}

derivedContext<Assertion.Builder<Either<*, MyTuple>>>("rightEither") {
fixture {
expectThat(Either.Right(MyTuple("myName", 1, "uuid")))
}
derivedContext<Assertion.Builder<Either<*, MyTuple>>>("rightEither") {
fixture {
expectThat(Either.Right(MyTuple("myName", 1, "uuid")))
}

test("can have nested assertions on unwrapped value") {
isRight().value and {
get { name } isEqualTo "myName"
get { id }.isNotNull() isGreaterThan 0L
get { uuid }.isNotNull().isNotBlank()
test("can have nested assertions on unwrapped value") {
isRight().value and {
get { name } isEqualTo "myName"
get { id }.isNotNull() isGreaterThan 0L
get { uuid }.isNotNull().isNotBlank()
}
}
}
}
}
}
56 changes: 28 additions & 28 deletions strikt-arrow/src/test/kotlin/strikt/arrow/OptionAssertions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,42 @@ import strikt.assertions.isEqualTo

@DisplayName("assertions on Option")
object OptionAssertions : JUnit5Minutests {
fun tests() =
rootContext<Assertion.Builder<Option<String>>> {
context("someOption") {
fixture {
expectThat(Some("aValue"))
}

fun tests() = rootContext<Assertion.Builder<Option<String>>> {
context("someOption") {
fixture {
expectThat(Some("aValue"))
}

test("can assert on type") {
isSome()
}
test("can assert on type") {
isSome()
}

test("can negate assertion") {
not().isNone()
}
test("can negate assertion") {
not().isNone()
}

test("can assert on type and value equality") {
isSome("aValue")
}
test("can assert on type and value equality") {
isSome("aValue")
}

test("can assert on type and traverse wrapped value") {
isSome().value.isEqualTo("aValue")
test("can assert on type and traverse wrapped value") {
isSome().value.isEqualTo("aValue")
}
}
}

context("noneOption") {
fixture {
expectThat(None)
}
context("noneOption") {
fixture {
expectThat(None)
}

test("can assert on type") {
isNone()
}
test("can assert on type") {
isNone()
}

test("can negate assertion") {
not().isSome()
test("can negate assertion") {
not().isSome()
}
}
}
}
}
42 changes: 20 additions & 22 deletions strikt-core/src/main/kotlin/strikt/api/Assertion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface Assertion {
* @see Assertion
*/
interface Builder<T> {

val subject: T

/**
Expand All @@ -59,8 +58,7 @@ interface Assertion {
fun assert(
description: String,
assert: AtomicAssertion.(T) -> Unit
): Builder<T> =
assert(description, null, assert)
): Builder<T> = assert(description, null, assert)

/**
* Evaluates a condition that may pass or fail.
Expand Down Expand Up @@ -123,8 +121,7 @@ interface Assertion {
fun compose(
description: String,
assertions: Builder<T>.(T) -> Unit
): CompoundAssertions<T> =
compose(description, null, assertions)
): CompoundAssertions<T> = compose(description, null, assertions)

/**
* Evaluates a boolean condition.
Expand All @@ -140,8 +137,10 @@ interface Assertion {
"Use assertThat instead",
replaceWith = ReplaceWith("assertThat(description, assert)")
)
fun passesIf(description: String, assert: (T) -> Boolean): Builder<T> =
assertThat(description, assert)
fun passesIf(
description: String,
assert: (T) -> Boolean
): Builder<T> = assertThat(description, assert)

/**
* Evaluates a boolean condition.
Expand All @@ -153,7 +152,10 @@ interface Assertion {
* `false` (the assertion fails).
* @return the chained assertion builder, in order to facilitate a fluent API.
*/
fun assertThat(description: String, assert: (T) -> Boolean): Builder<T> =
fun assertThat(
description: String,
assert: (T) -> Boolean
): Builder<T> =
assert(description) {
if (assert(it)) pass() else fail()
}
Expand All @@ -177,8 +179,7 @@ interface Assertion {
description: String,
expected: Any?,
assert: (T) -> Boolean
): Builder<T> =
assertThat(description, expected, assert)
): Builder<T> = assertThat(description, expected, assert)

/**
* Evaluates a boolean condition.
Expand Down Expand Up @@ -216,8 +217,7 @@ interface Assertion {
* @return an assertion builder whose subject is the value returned by
* [function].
*/
fun <R> get(function: T.() -> R): DescribeableBuilder<R> =
get(function.describe(), function)
fun <R> get(function: T.() -> R): DescribeableBuilder<R> = get(function.describe(), function)

/**
* Runs a group of assertions on the subject returned by [function].
Expand Down Expand Up @@ -273,8 +273,7 @@ interface Assertion {
"Use get instead",
replaceWith = ReplaceWith("get(function)")
)
fun <R> chain(function: (T) -> R): DescribeableBuilder<R> =
get(function)
fun <R> chain(function: (T) -> R): DescribeableBuilder<R> = get(function)

/**
* Deprecated form of [with]`(String, (T) -> R)`.
Expand Down Expand Up @@ -316,9 +315,7 @@ interface Assertion {
* This method may be used as an infix function which tends to enhance
* readability when it directly follows a lambda.
*/
infix fun and(
assertions: Builder<T>.() -> Unit
): Builder<T>
infix fun and(assertions: Builder<T>.() -> Unit): Builder<T>
}
}

Expand All @@ -340,9 +337,10 @@ private fun <Receiver, Result> (Receiver.() -> Result).describe(): String =
}

private val CallableReference.propertyName: String
get() = "^get(.+)$".toRegex().find(name).let { match ->
return when (match) {
null -> name
else -> match.groupValues[1].replaceFirstChar { it.lowercase(Locale.getDefault()) }
get() =
"^get(.+)$".toRegex().find(name).let { match ->
return when (match) {
null -> name
else -> match.groupValues[1].replaceFirstChar { it.lowercase(Locale.getDefault()) }
}
}
}
8 changes: 2 additions & 6 deletions strikt-core/src/main/kotlin/strikt/api/Expect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ fun expect(block: suspend ExpectationBuilder.() -> Unit) {
* @param subject the subject of the chain of assertions.
* @return an assertion for [subject].
*/
fun <T> expectThat(subject: T): DescribeableBuilder<T> =
AssertionBuilder(AssertionSubject(subject), Throwing)
fun <T> expectThat(subject: T): DescribeableBuilder<T> = AssertionBuilder(AssertionSubject(subject), Throwing)

/**
* Evaluate a block of assertions over [subject].
Expand All @@ -63,10 +62,7 @@ fun <T> expectThat(
* @return an assertion over the thrown exception, allowing further assertions
* about messages, root causes, etc.
*/
inline fun <reified E : Throwable> expectThrows(
noinline action: suspend () -> Any?
): Builder<E> =
expectCatching(action).failedWith()
inline fun <reified E : Throwable> expectThrows(noinline action: suspend () -> Any?): Builder<E> = expectCatching(action).failedWith()

/**
* Start a chain of assertions over the result of [action] which may either be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package strikt.api
* create assertion chains or blocks.
*/
interface ExpectationBuilder {

/**
* Start a chain of assertions over [subject].
*
Expand Down
Loading

0 comments on commit 03e6d9a

Please sign in to comment.