diff --git a/README.md b/README.md index 9c5dcc4..9931247 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Since the `AString` represent any generic `CharSequence`, it might be useful to transform the value before its use. aString.format("arg", AppId) - aString.defaultIfNull("value") + aString.ifNull("value") aString.nullIfBlank() aString.mapToString() aString.trim() diff --git a/astring/src/androidTest/java/xyz/tynn/astring/AStringReducerAndroidTest.java b/astring/src/androidTest/java/xyz/tynn/astring/AStringReducerAndroidTest.java index fa8d115..3e99125 100644 --- a/astring/src/androidTest/java/xyz/tynn/astring/AStringReducerAndroidTest.java +++ b/astring/src/androidTest/java/xyz/tynn/astring/AStringReducerAndroidTest.java @@ -6,6 +6,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static xyz.tynn.astring.AStringFactory.createFromCharSequence; +import static xyz.tynn.astring.AStringFactory.getAppId; +import static xyz.tynn.astring.AStringFactory.getAppVersion; import static xyz.tynn.astring.test.AStringAssert.assertParcelableAStringInvocation; import androidx.annotation.NonNull; @@ -17,7 +19,7 @@ public class AStringReducerAndroidTest { - private final Iterable aStrings = List.of(AString.Null); + private final Iterable aStrings = List.of(getAppId(), getAppVersion()); @Test public void delegate_should_implement_parcelable() { diff --git a/astring/src/androidTest/java/xyz/tynn/astring/ParcelableAStringTest.java b/astring/src/androidTest/java/xyz/tynn/astring/ParcelableAStringTest.java index 8459d1e..e632e16 100644 --- a/astring/src/androidTest/java/xyz/tynn/astring/ParcelableAStringTest.java +++ b/astring/src/androidTest/java/xyz/tynn/astring/ParcelableAStringTest.java @@ -20,9 +20,6 @@ public class ParcelableAStringTest { - private static final Locale LOCALE = Locale.UK; - private static final int RES_ID = 123; - private static final int QUANTITY = 456; private static final AString FORMAT = new FormatAString(); private static final Object[] FORMAT_ARGS = {"arg1", 2, 3L, 4.5, 6F, new Date(), Wrapper.wrap("test-string")}; @@ -36,24 +33,24 @@ public void Wrapper_should_implement_parcelable() { @Test public void Format_should_implement_parcelable() { - assertParcelableAStringEquality(Format.wrap(FORMAT, LOCALE, FORMAT_ARGS)); - assertParcelableAStringInvocation(Format.wrap(FORMAT, LOCALE, FORMAT_ARGS)); + assertParcelableAStringEquality(Format.wrap(FORMAT, Locale.UK, FORMAT_ARGS)); + assertParcelableAStringInvocation(Format.wrap(FORMAT, Locale.UK, FORMAT_ARGS)); assertParcelableAStringEquality(Format.wrap(FORMAT, null, FORMAT_ARGS)); assertParcelableAStringInvocation(Format.wrap(FORMAT, null, FORMAT_ARGS)); - assertParcelableAStringEquality(Format.wrap(FORMAT, LOCALE, null)); - assertParcelableAStringInvocation(Format.wrap(FORMAT, LOCALE, null)); + assertParcelableAStringEquality(Format.wrap(FORMAT, Locale.UK, null)); + assertParcelableAStringInvocation(Format.wrap(FORMAT, Locale.UK, null)); assertParcelableAStringEquality(Format.wrap(FORMAT, null, null)); assertParcelableAStringInvocation(Format.wrap(FORMAT, null, null)); } @Test public void Resource_should_implement_parcelable() { - assertParcelableAStringEquality(Resource.wrap(RES_ID, null)); - assertParcelableAStringEquality(Resource.wrap(RES_ID, QUANTITY)); - assertParcelableAStringEquality(Resource.wrap(RES_ID, null, FORMAT_ARGS)); - assertParcelableAStringEquality(Resource.wrap(RES_ID, QUANTITY, FORMAT_ARGS)); - assertParcelableAStringEquality(Resource.wrap(RES_ID, null, null)); - assertParcelableAStringEquality(Resource.wrap(RES_ID, QUANTITY, null)); + assertParcelableAStringEquality(Resource.wrap(123, null)); + assertParcelableAStringEquality(Resource.wrap(123, 456)); + assertParcelableAStringEquality(Resource.wrap(123, null, FORMAT_ARGS)); + assertParcelableAStringEquality(Resource.wrap(123, 456, FORMAT_ARGS)); + assertParcelableAStringEquality(Resource.wrap(123, null, null)); + assertParcelableAStringEquality(Resource.wrap(123, 456, null)); } @Test @@ -65,18 +62,22 @@ public void Delegate_should_implement_parcelable() { assertParcelableAStringEquality(Delegate.wrap(Provider.AppVersion)); assertParcelableAStringInvocation(Delegate.wrap(Provider.AppVersion)); assertParcelableAStringInvocation(Delegate.wrap(Object::toString)); - assertParcelableAStringIdentity(Delegate.wrap((AString) null, null)); - assertParcelableAStringInvocation(Delegate.wrap((AString) null, null)); - assertParcelableAStringEquality(Delegate.wrap(FORMAT, Predicate.NonBlank)); - assertParcelableAStringInvocation(Delegate.wrap(FORMAT, Predicate.NonBlank)); - assertParcelableAStringEquality(Delegate.wrap(FORMAT, Predicate.NonEmpty)); - assertParcelableAStringInvocation(Delegate.wrap(FORMAT, Predicate.NonEmpty)); - assertParcelableAStringEquality(Delegate.wrap(FORMAT, Predicate.NonNull)); - assertParcelableAStringInvocation(Delegate.wrap(FORMAT, Predicate.NonNull)); - assertParcelableAStringEquality(Delegate.wrap(FORMAT, Transformer.ToString)); - assertParcelableAStringInvocation(Delegate.wrap(FORMAT, Transformer.ToString)); - assertParcelableAStringEquality(Delegate.wrap(FORMAT, Transformer.Trim)); - assertParcelableAStringInvocation(Delegate.wrap(FORMAT, Transformer.Trim)); + assertParcelableAStringIdentity(Delegate.wrap((AString.Transformer) null, null)); + assertParcelableAStringInvocation(Delegate.wrap((AString.Transformer) null, null)); + assertParcelableAStringEquality(Delegate.wrap(Transformer.ToString, FORMAT)); + assertParcelableAStringInvocation(Delegate.wrap(Transformer.ToString, FORMAT)); + assertParcelableAStringEquality(Delegate.wrap(Transformer.Trim, FORMAT)); + assertParcelableAStringInvocation(Delegate.wrap(Transformer.Trim, FORMAT)); + assertParcelableAStringIdentity(Delegate.wrap((AString.Reducer) null)); + assertParcelableAStringInvocation(Delegate.wrap((AString.Reducer) null)); + assertParcelableAStringEquality(Delegate.wrap(Predicate.AnyValue, FORMAT)); + assertParcelableAStringInvocation(Delegate.wrap(Predicate.AnyValue, FORMAT)); + assertParcelableAStringEquality(Delegate.wrap(Predicate.NonBlank, FORMAT)); + assertParcelableAStringInvocation(Delegate.wrap(Predicate.NonBlank, FORMAT)); + assertParcelableAStringEquality(Delegate.wrap(Predicate.NonEmpty, FORMAT)); + assertParcelableAStringInvocation(Delegate.wrap(Predicate.NonEmpty, FORMAT)); + assertParcelableAStringEquality(Delegate.wrap(Predicate.NonNull, FORMAT)); + assertParcelableAStringInvocation(Delegate.wrap(Predicate.NonNull, FORMAT)); } private static class FormatAString implements AString { diff --git a/astring/src/androidTest/kotlin/xyz/tynn/astring/AStringReducerKtAndroidTest.kt b/astring/src/androidTest/kotlin/xyz/tynn/astring/AStringReducerKtAndroidTest.kt index 0b320d3..907ddd0 100644 --- a/astring/src/androidTest/kotlin/xyz/tynn/astring/AStringReducerKtAndroidTest.kt +++ b/astring/src/androidTest/kotlin/xyz/tynn/astring/AStringReducerKtAndroidTest.kt @@ -12,15 +12,13 @@ import xyz.tynn.astring.test.AStringAssert.assertParcelableAStringInvocation @InefficientAStringApi internal class AStringReducerKtAndroidTest { - private val aString1 = AString.Null - private val aString2 = "+".asAString() - private val aStrings = listOf(aString1, aString2) - private val aStringIterable = sequenceOf(aString1, aString2).asIterable() + private val aStrings = listOf(AString.Null, AppId) + private val aStringIterable = sequenceOf(AString.Null, AppId).asIterable() @Test fun firstNonBlank_should_be_parcelable() { - assertParcelableAStringEquality(firstNonBlank(aString1, aString2)) - assertParcelableAStringInvocation(firstNonBlank(aString1, aString2)) + assertParcelableAStringEquality(firstNonBlank(AString.Null, AppId)) + assertParcelableAStringInvocation(firstNonBlank(AString.Null, AppId)) assertParcelableAStringEquality(aStrings.firstNonBlank()) assertParcelableAStringInvocation(aStrings.firstNonBlank()) assertParcelableAStringEquality(aStringIterable.firstNonBlank()) @@ -29,8 +27,8 @@ internal class AStringReducerKtAndroidTest { @Test fun firstNonEmpty_should_be_parcelable() { - assertParcelableAStringEquality(firstNonEmpty(aString1, aString2)) - assertParcelableAStringInvocation(firstNonEmpty(aString1, aString2)) + assertParcelableAStringEquality(firstNonEmpty(AString.Null, AppId)) + assertParcelableAStringInvocation(firstNonEmpty(AString.Null, AppId)) assertParcelableAStringEquality(aStrings.firstNonEmpty()) assertParcelableAStringInvocation(aStrings.firstNonEmpty()) assertParcelableAStringEquality(aStringIterable.firstNonEmpty()) @@ -39,8 +37,8 @@ internal class AStringReducerKtAndroidTest { @Test fun firstNonNull_should_be_parcelable() { - assertParcelableAStringEquality(firstNonNull(aString1, aString2)) - assertParcelableAStringInvocation(firstNonNull(aString1, aString2)) + assertParcelableAStringEquality(firstNonNull(AString.Null, AppId)) + assertParcelableAStringInvocation(firstNonNull(AString.Null, AppId)) assertParcelableAStringEquality(aStrings.firstNonNull()) assertParcelableAStringInvocation(aStrings.firstNonNull()) assertParcelableAStringEquality(aStringIterable.firstNonNull()) @@ -49,8 +47,8 @@ internal class AStringReducerKtAndroidTest { @Test fun join_should_be_parcelable() { - assertParcelableAStringEquality(join(aString1, aString2, separator = "-")) - assertParcelableAStringInvocation(join(aString1, aString2, separator = "-")) + assertParcelableAStringEquality(join(AString.Null, AppId, separator = "-")) + assertParcelableAStringInvocation(join(AString.Null, AppId, separator = "-")) assertParcelableAStringEquality(aStrings.join(separator = "-")) assertParcelableAStringInvocation(aStrings.join(separator = "-")) assertParcelableAStringEquality(aStringIterable.join(separator = "-")) @@ -59,8 +57,8 @@ internal class AStringReducerKtAndroidTest { @Test fun joinNonBlank_should_be_parcelable() { - assertParcelableAStringEquality(joinNonBlank(aString1, aString2, separator = "-")) - assertParcelableAStringInvocation(joinNonBlank(aString1, aString2, separator = "-")) + assertParcelableAStringEquality(joinNonBlank(AString.Null, AppId, separator = "-")) + assertParcelableAStringInvocation(joinNonBlank(AString.Null, AppId, separator = "-")) assertParcelableAStringEquality(aStrings.joinNonBlank(separator = "-")) assertParcelableAStringInvocation(aStrings.joinNonBlank(separator = "-")) assertParcelableAStringEquality(aStringIterable.joinNonBlank(separator = "-")) @@ -69,8 +67,8 @@ internal class AStringReducerKtAndroidTest { @Test fun joinNonEmpty_should_be_parcelable() { - assertParcelableAStringEquality(joinNonEmpty(aString1, aString2, separator = "-")) - assertParcelableAStringInvocation(joinNonEmpty(aString1, aString2, separator = "-")) + assertParcelableAStringEquality(joinNonEmpty(AString.Null, AppId, separator = "-")) + assertParcelableAStringInvocation(joinNonEmpty(AString.Null, AppId, separator = "-")) assertParcelableAStringEquality(aStrings.joinNonEmpty(separator = "-")) assertParcelableAStringInvocation(aStrings.joinNonEmpty(separator = "-")) assertParcelableAStringEquality(aStringIterable.joinNonEmpty(separator = "-")) @@ -79,8 +77,8 @@ internal class AStringReducerKtAndroidTest { @Test fun joinNonNull_should_be_parcelable() { - assertParcelableAStringEquality(joinNonNull(aString1, aString2, separator = "-")) - assertParcelableAStringInvocation(joinNonNull(aString1, aString2, separator = "-")) + assertParcelableAStringEquality(joinNonNull(AString.Null, AppId, separator = "-")) + assertParcelableAStringInvocation(joinNonNull(AString.Null, AppId, separator = "-")) assertParcelableAStringEquality(aStrings.joinNonNull(separator = "-")) assertParcelableAStringInvocation(aStrings.joinNonNull(separator = "-")) assertParcelableAStringEquality(aStringIterable.joinNonNull(separator = "-")) @@ -91,15 +89,15 @@ internal class AStringReducerKtAndroidTest { @Suppress("RedundantSamConstructor") fun interface_should_not_be_efficient() { assertNotEquals( - reduce(aString1, aString2, reducer = AString.Reducer { "" }), - reduce(aString1, aString2, reducer = AString.Reducer { "" }), + reduce(AString.Null, AppId, reducer = AString.Reducer { "" }), + reduce(AString.Null, AppId, reducer = AString.Reducer { "" }), ) assertNotEquals( - reduce(aString1, aString2, reducer = AString.Reducer { "" }), + reduce(AString.Null, AppId, reducer = AString.Reducer { "" }), aStrings.reduce(reducer = AString.Reducer { "" }), ) assertNotEquals( - reduce(aString1, aString2, reducer = AString.Reducer { "" }), + reduce(AString.Null, AppId, reducer = AString.Reducer { "" }), aStringIterable.reduce(reducer = AString.Reducer { "" }), ) } @@ -108,15 +106,15 @@ internal class AStringReducerKtAndroidTest { fun interface_val_should_be_efficient() { val function = AString.Reducer { "" } assertEquals( - reduce(aString1, aString2, reducer = function), - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), + reduce(AString.Null, AppId, reducer = function), ) assertEquals( - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), aStrings.reduce(reducer = function), ) assertEquals( - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), aStringIterable.reduce(reducer = function), ) } @@ -124,15 +122,15 @@ internal class AStringReducerKtAndroidTest { @Test fun instance_should_be_efficient() { assertEquals( - reduce(aString1, aString2, reducer = Reducer()), - reduce(aString1, aString2, reducer = Reducer()), + reduce(AString.Null, AppId, reducer = Reducer()), + reduce(AString.Null, AppId, reducer = Reducer()), ) assertEquals( - reduce(aString1, aString2, reducer = Reducer()), + reduce(AString.Null, AppId, reducer = Reducer()), aStrings.reduce(reducer = Reducer()), ) assertEquals( - reduce(aString1, aString2, reducer = Reducer()), + reduce(AString.Null, AppId, reducer = Reducer()), aStringIterable.reduce(reducer = Reducer()), ) } @@ -141,15 +139,15 @@ internal class AStringReducerKtAndroidTest { fun instance_val_should_be_efficient() { val function = Reducer() assertEquals( - reduce(aString1, aString2, reducer = function), - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), + reduce(AString.Null, AppId, reducer = function), ) assertEquals( - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), aStrings.reduce(reducer = function), ) assertEquals( - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), aStringIterable.reduce(reducer = function), ) } @@ -157,15 +155,15 @@ internal class AStringReducerKtAndroidTest { @Test fun function_reference_should_be_efficient() { assertEquals( - reduce(aString1, aString2, reducer = ::function), - reduce(aString1, aString2, reducer = ::function), + reduce(AString.Null, AppId, reducer = ::function), + reduce(AString.Null, AppId, reducer = ::function), ) assertEquals( - reduce(aString1, aString2, reducer = ::function), + reduce(AString.Null, AppId, reducer = ::function), aStrings.reduce(reducer = ::function), ) assertEquals( - reduce(aString1, aString2, reducer = ::function), + reduce(AString.Null, AppId, reducer = ::function), aStringIterable.reduce(reducer = ::function), ) } @@ -174,15 +172,15 @@ internal class AStringReducerKtAndroidTest { fun function_reference_val_should_be_efficient() { val function = ::function assertEquals( - reduce(aString1, aString2, reducer = function), - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), + reduce(AString.Null, AppId, reducer = function), ) assertEquals( - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), aStrings.reduce(reducer = function), ) assertEquals( - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), aStringIterable.reduce(reducer = function), ) } @@ -190,15 +188,15 @@ internal class AStringReducerKtAndroidTest { @Test fun lambda_should_not_be_efficient() { assertNotEquals( - reduce(aString1, aString2) { it.toString() }, - reduce(aString1, aString2) { it.toString() }, + reduce(AString.Null, AppId) { it.toString() }, + reduce(AString.Null, AppId) { it.toString() }, ) assertNotEquals( - reduce(aString1, aString2) { it.toString() }, + reduce(AString.Null, AppId) { it.toString() }, aStrings.reduce { it.toString() }, ) assertNotEquals( - reduce(aString1, aString2) { it.toString() }, + reduce(AString.Null, AppId) { it.toString() }, aStringIterable.reduce { it.toString() }, ) } @@ -207,15 +205,15 @@ internal class AStringReducerKtAndroidTest { fun lambda_val_should_be_efficient() { val function = { _: Iterable -> "" } assertEquals( - reduce(aString1, aString2, reducer = function), - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), + reduce(AString.Null, AppId, reducer = function), ) assertEquals( - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), aStrings.reduce(reducer = function), ) assertEquals( - reduce(aString1, aString2, reducer = function), + reduce(AString.Null, AppId, reducer = function), aStringIterable.reduce(reducer = function), ) } diff --git a/astring/src/main/java/xyz/tynn/astring/Delegate.java b/astring/src/main/java/xyz/tynn/astring/Delegate.java index 43d76a6..1f6ee1b 100644 --- a/astring/src/main/java/xyz/tynn/astring/Delegate.java +++ b/astring/src/main/java/xyz/tynn/astring/Delegate.java @@ -15,10 +15,10 @@ import androidx.annotation.Nullable; import java.io.Serializable; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; +import java.util.LinkedList; import java.util.Objects; final class Delegate implements AString { @@ -43,21 +43,22 @@ static AString wrap(AString.Provider provider) { @InefficientAStringApi static AString wrap(AString.Reducer reducer, AString... aStrings) { - if (reducer == null || aStrings == null || aStrings.length == 0) return Null; - return new Delegate(new Serializer.Reducer(reducer), aStrings); + if (reducer == null || aStrings == null) return Null; + AString aString = Wrapper.maybeReduce(reducer, aStrings); + return aString != null ? aString : new Delegate(new Serializer.Reducer(reducer), aStrings); } @InefficientAStringApi static AString wrap(AString.Reducer reducer, Iterable aStrings) { if (reducer == null || aStrings == null) return Null; Collection list = aStrings instanceof Collection - ? (Collection) aStrings : new ArrayList<>(); + ? (Collection) aStrings : new LinkedList<>(); if (list != aStrings) for (AString aString : aStrings) list.add(aString); return wrap(reducer, list.toArray(EMPTY)); } @InefficientAStringApi - static AString wrap(AString aString, Transformer transformer) { + static AString wrap(Transformer transformer, AString aString) { if (transformer == null) return Null; if (aString == null || aString == Null) return Wrapper.wrap(transformer.invoke(null)); if (aString instanceof Wrapper) return ((Wrapper) aString).map(transformer); diff --git a/astring/src/main/java/xyz/tynn/astring/Predicate.java b/astring/src/main/java/xyz/tynn/astring/Predicate.java index de7741d..0c716e4 100644 --- a/astring/src/main/java/xyz/tynn/astring/Predicate.java +++ b/astring/src/main/java/xyz/tynn/astring/Predicate.java @@ -12,9 +12,9 @@ import androidx.annotation.Nullable; @SuppressLint("UnsafeOptInUsageError") -enum Predicate implements AString.Reducer, AString.Transformer { +enum Predicate implements AString.Reducer { - AnyValue(null) { + AnyValue { @Override boolean test(CharSequence value) { return true; @@ -27,7 +27,7 @@ public String toString() { } }, - NonBlank(null) { + NonBlank { @Override boolean test(CharSequence value) { if (value != null) for (int i = 0, cp; i < value.length(); i += charCount(cp)) @@ -43,7 +43,7 @@ public String toString() { } }, - NonEmpty(null) { + NonEmpty { @Override boolean test(CharSequence value) { return value != null && value.length() > 0; @@ -56,7 +56,7 @@ public String toString() { } }, - NonNull("") { + NonNull { @Override boolean test(CharSequence value) { return value != null; @@ -71,20 +71,8 @@ public String toString() { ; - private final CharSequence defaultValue; - - Predicate(CharSequence defaultValue) { - this.defaultValue = defaultValue; - } - abstract boolean test(CharSequence value); - @Nullable - @Override - public CharSequence invoke(@Nullable CharSequence value) { - return test(value) ? value : defaultValue; - } - @Nullable @Override public CharSequence invoke(@androidx.annotation.NonNull Iterable values) { diff --git a/astring/src/main/java/xyz/tynn/astring/Wrapper.java b/astring/src/main/java/xyz/tynn/astring/Wrapper.java index c9f3f00..e3fea63 100644 --- a/astring/src/main/java/xyz/tynn/astring/Wrapper.java +++ b/astring/src/main/java/xyz/tynn/astring/Wrapper.java @@ -4,6 +4,7 @@ package xyz.tynn.astring; import static android.text.TextUtils.CHAR_SEQUENCE_CREATOR; +import static java.util.Collections.emptyList; import android.annotation.SuppressLint; import android.content.Context; @@ -13,6 +14,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.util.ArrayList; import java.util.Objects; /** @@ -71,6 +73,21 @@ Wrapper map(AString.Transformer transformer) { return value != null && value.equals(this.value) ? this : wrap(value); } + @SuppressLint("UnsafeOptInUsageError") + static AString maybeReduce(AString.Reducer reducer, AString[] aStrings) { + if (aStrings.length == 0) return wrap(reducer.invoke(emptyList())); + ArrayList values = new ArrayList<>(aStrings.length); + for (AString aString : aStrings) + if (aString == null || aString == NULL) + values.add(null); + else if (aString instanceof Wrapper) + values.add(((Wrapper) aString).value); + else return null; + CharSequence value = reducer.invoke(values); + return value != null && aStrings.length == 1 && value.equals(values.get(0)) + ? aStrings[0] : wrap(value); + } + public static final Creator CREATOR = new Creator<>() { @Override diff --git a/astring/src/main/kotlin/xyz/tynn/astring/AStringReducer.kt b/astring/src/main/kotlin/xyz/tynn/astring/AStringReducer.kt index 2293944..98d51b2 100644 --- a/astring/src/main/kotlin/xyz/tynn/astring/AStringReducer.kt +++ b/astring/src/main/kotlin/xyz/tynn/astring/AStringReducer.kt @@ -15,7 +15,7 @@ import xyz.tynn.astring.Predicate.NonNull */ @InefficientAStringApi public fun reduce( - vararg aStrings: AString, + vararg aStrings: AString?, reducer: AString.Reducer, ): AString = Delegate.wrap( reducer, @@ -26,7 +26,7 @@ public fun reduce( * Reduces an [Iterable] of [AString] to a single [CharSequence] */ @InefficientAStringApi -public fun Iterable.reduce( +public fun Iterable.reduce( reducer: AString.Reducer, ): AString = Delegate.wrap( reducer, @@ -38,7 +38,7 @@ public fun Iterable.reduce( */ @OptIn(InefficientAStringApi::class) public fun firstNonBlank( - vararg aStrings: AString, + vararg aStrings: AString?, ): AString = Delegate.wrap( NonBlank, *aStrings, @@ -48,7 +48,7 @@ public fun firstNonBlank( * Reduces all items by returning the first non-blank [CharSequence] value */ @OptIn(InefficientAStringApi::class) -public fun Iterable.firstNonBlank(): AString = Delegate.wrap( +public fun Iterable.firstNonBlank(): AString = Delegate.wrap( NonBlank, this, ) @@ -58,7 +58,7 @@ public fun Iterable.firstNonBlank(): AString = Delegate.wrap( */ @OptIn(InefficientAStringApi::class) public fun firstNonEmpty( - vararg aStrings: AString, + vararg aStrings: AString?, ): AString = Delegate.wrap( NonEmpty, *aStrings, @@ -68,7 +68,7 @@ public fun firstNonEmpty( * Reduces all items by returning the first non-empty [CharSequence] value */ @OptIn(InefficientAStringApi::class) -public fun Iterable.firstNonEmpty(): AString = Delegate.wrap( +public fun Iterable.firstNonEmpty(): AString = Delegate.wrap( NonEmpty, this, ) @@ -78,7 +78,7 @@ public fun Iterable.firstNonEmpty(): AString = Delegate.wrap( */ @OptIn(InefficientAStringApi::class) public fun firstNonNull( - vararg aStrings: AString, + vararg aStrings: AString?, ): AString = Delegate.wrap( NonNull, *aStrings, @@ -88,7 +88,7 @@ public fun firstNonNull( * Reduces all items by returning the first non-null [CharSequence] value */ @OptIn(InefficientAStringApi::class) -public fun Iterable.firstNonNull(): AString = Delegate.wrap( +public fun Iterable.firstNonNull(): AString = Delegate.wrap( NonNull, this, ) @@ -98,7 +98,7 @@ public fun Iterable.firstNonNull(): AString = Delegate.wrap( */ @OptIn(InefficientAStringApi::class) public fun join( - vararg aStrings: AString, + vararg aStrings: AString?, separator: String, ): AString = Delegate.wrap( Joiner( @@ -112,7 +112,7 @@ public fun join( * Reduces all items by joining all nullable [CharSequence] values */ @OptIn(InefficientAStringApi::class) -public fun Iterable.join( +public fun Iterable.join( separator: String, ): AString = Delegate.wrap( Joiner( @@ -127,7 +127,7 @@ public fun Iterable.join( */ @OptIn(InefficientAStringApi::class) public fun joinNonBlank( - vararg aStrings: AString, + vararg aStrings: AString?, separator: String, ): AString = Delegate.wrap( Joiner( @@ -141,7 +141,7 @@ public fun joinNonBlank( * Reduces all items by joining all non-null [CharSequence] values */ @OptIn(InefficientAStringApi::class) -public fun Iterable.joinNonBlank( +public fun Iterable.joinNonBlank( separator: String, ): AString = Delegate.wrap( Joiner( @@ -156,7 +156,7 @@ public fun Iterable.joinNonBlank( */ @OptIn(InefficientAStringApi::class) public fun joinNonEmpty( - vararg aStrings: AString, + vararg aStrings: AString?, separator: String, ): AString = Delegate.wrap( Joiner( @@ -170,7 +170,7 @@ public fun joinNonEmpty( * Reduces all items by joining all non-null [CharSequence] values */ @OptIn(InefficientAStringApi::class) -public fun Iterable.joinNonEmpty( +public fun Iterable.joinNonEmpty( separator: String, ): AString = Delegate.wrap( Joiner( @@ -185,7 +185,7 @@ public fun Iterable.joinNonEmpty( */ @OptIn(InefficientAStringApi::class) public fun joinNonNull( - vararg aStrings: AString, + vararg aStrings: AString?, separator: String, ): AString = Delegate.wrap( Joiner( @@ -199,7 +199,7 @@ public fun joinNonNull( * Reduces all items by joining all non-null [CharSequence] values */ @OptIn(InefficientAStringApi::class) -public fun Iterable.joinNonNull( +public fun Iterable.joinNonNull( separator: String, ): AString = Delegate.wrap( Joiner( diff --git a/astring/src/main/kotlin/xyz/tynn/astring/AStringTransformer.kt b/astring/src/main/kotlin/xyz/tynn/astring/AStringTransformer.kt index 55f2893..46ad9b1 100644 --- a/astring/src/main/kotlin/xyz/tynn/astring/AStringTransformer.kt +++ b/astring/src/main/kotlin/xyz/tynn/astring/AStringTransformer.kt @@ -16,11 +16,11 @@ import java.util.Locale * Maps the [AString] `CharSequence` to the result of [transformer] */ @[InefficientAStringApi JvmName("mapAString")] -public fun AString.map( +public fun AString?.map( transformer: AString.Transformer, ): AString = Delegate.wrap( - this, transformer, + this, ) /** @@ -63,59 +63,11 @@ public fun AString?.format( formatArgs, ) -/** - * Maps a blank `CharSequence` to [defaultValue] - */ -@[JvmName("mapBlankToDefault") OptIn(InefficientAStringApi::class)] -public fun AString?.defaultIfBlank( - defaultValue: CharSequence, -): AString = Delegate.wrap( - NonBlank, - this, - AString(defaultValue), -) - -/** - * Maps a blank `CharSequence` to [defaultValue] - */ -@[JvmName("mapBlankToDefault") OptIn(InefficientAStringApi::class)] -public fun AString?.defaultIfBlank( - defaultValue: AString, -): AString = Delegate.wrap( - NonBlank, - this, - defaultValue, -) - -/** - * Maps a empty `CharSequence` to [defaultValue] - */ -@[JvmName("mapEmptyToDefault") OptIn(InefficientAStringApi::class)] -public fun AString?.defaultIfEmpty( - defaultValue: CharSequence, -): AString = Delegate.wrap( - NonEmpty, - this, - AString(defaultValue), -) - -/** - * Maps a empty `CharSequence` to [defaultValue] - */ -@[JvmName("mapEmptyToDefault") OptIn(InefficientAStringApi::class)] -public fun AString?.defaultIfEmpty( - defaultValue: AString, -): AString = Delegate.wrap( - NonEmpty, - this, - defaultValue, -) - /** * Maps a null `CharSequence` to [defaultValue] */ @[JvmName("mapNullToDefault") OptIn(InefficientAStringApi::class)] -public fun AString?.defaultIfNull( +public fun AString?.ifNull( defaultValue: CharSequence, ): AString = Delegate.wrap( NonNull, @@ -127,7 +79,7 @@ public fun AString?.defaultIfNull( * Maps a null `CharSequence` to [defaultValue] */ @[JvmName("mapNullToDefault") OptIn(InefficientAStringApi::class)] -public fun AString?.defaultIfNull( +public fun AString?.ifNull( defaultValue: AString, ): AString = Delegate.wrap( NonNull, @@ -135,17 +87,6 @@ public fun AString?.defaultIfNull( defaultValue, ) -/** - * Maps a null [AString] `CharSequence` to an empty `String` - * - * Returns [AString.Null] if this [AString] is `null` or [AString.Null] - */ -@[JvmName("mapNullToEmpty") OptIn(InefficientAStringApi::class)] -public fun AString?.emptyIfNull(): AString = Delegate.wrap( - this, - NonNull, -) - /** * Maps a blank [AString] `CharSequence` to null * @@ -153,8 +94,8 @@ public fun AString?.emptyIfNull(): AString = Delegate.wrap( */ @[JvmName("mapBlankToNull") OptIn(InefficientAStringApi::class)] public fun AString?.nullIfBlank(): AString = Delegate.wrap( - this, NonBlank, + this, ) /** @@ -164,8 +105,8 @@ public fun AString?.nullIfBlank(): AString = Delegate.wrap( */ @[JvmName("mapEmptyToNull") OptIn(InefficientAStringApi::class)] public fun AString?.nullIfEmpty(): AString = Delegate.wrap( - this, NonEmpty, + this, ) /** @@ -187,6 +128,6 @@ public fun AString?.mapToString(): AString = Format.wrap( */ @[JvmName("trimCharSequence") OptIn(InefficientAStringApi::class)] public fun AString?.trim(): AString = Delegate.wrap( - this, Trim, + this, ) diff --git a/astring/src/test/java/xyz/tynn/astring/AStringFactoryTest.java b/astring/src/test/java/xyz/tynn/astring/AStringFactoryTest.java index c442a81..8002e1c 100644 --- a/astring/src/test/java/xyz/tynn/astring/AStringFactoryTest.java +++ b/astring/src/test/java/xyz/tynn/astring/AStringFactoryTest.java @@ -111,26 +111,6 @@ public void mapEmptyToNull_should_be_NULL_on_null() { assertEquals(AString.Null, AStringFactory.mapEmptyToNull(AString.Null)); } - @Test - public void mapNullToEmpty_should_be_empty_on_null() { - assertEquals(AStringFactory.createFromCharSequence(""), - AStringFactory.mapNullToEmpty(null)); - } - - @Test - @SuppressWarnings("ConstantConditions") - public void mapBlankToDefault_should_not_be_null_on_null() { - assertNotNull(AStringFactory.mapBlankToDefault(null, (CharSequence) null)); - assertNotNull(AStringFactory.mapBlankToDefault(null, (AString) null)); - } - - @Test - @SuppressWarnings("ConstantConditions") - public void mapEmptyToDefault_should_not_be_null_on_null() { - assertNotNull(AStringFactory.mapEmptyToDefault(null, (CharSequence) null)); - assertNotNull(AStringFactory.mapEmptyToDefault(null, (AString) null)); - } - @Test @SuppressWarnings("ConstantConditions") public void mapNullToDefault_should_not_be_null_on_null() { diff --git a/astring/src/test/java/xyz/tynn/astring/AStringReducerTest.java b/astring/src/test/java/xyz/tynn/astring/AStringReducerTest.java index af66e39..0e57639 100644 --- a/astring/src/test/java/xyz/tynn/astring/AStringReducerTest.java +++ b/astring/src/test/java/xyz/tynn/astring/AStringReducerTest.java @@ -6,6 +6,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static xyz.tynn.astring.AStringFactory.getAppId; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -17,15 +19,15 @@ public class AStringReducerTest { private final Iterable aStrings = List.of( - AStringFactory.getAppId(), + getAppId(), AStringFactory.getAppVersion() ); @Test public void delegate_should_wrap_null_AString() { AString.Reducer function = values -> "value"; - Assert.assertEquals(Delegate.wrap(function, AString.Null, AString.Null), - Delegate.wrap(function, null, null)); + assertEquals(Delegate.wrap(function, AString.Null, AString.Null, getAppId()), + Delegate.wrap(function, null, null, getAppId())); } @Test diff --git a/astring/src/test/java/xyz/tynn/astring/AStringTransformerTest.java b/astring/src/test/java/xyz/tynn/astring/AStringTransformerTest.java index 97c7f1a..5ffd884 100644 --- a/astring/src/test/java/xyz/tynn/astring/AStringTransformerTest.java +++ b/astring/src/test/java/xyz/tynn/astring/AStringTransformerTest.java @@ -19,8 +19,8 @@ public class AStringTransformerTest { @Test public void delegate_should_wrap_null_AString() { AString.Transformer function = value -> value; - assertEquals(Delegate.wrap(AString.Null, function), - Delegate.wrap(null, function)); + assertEquals(Delegate.wrap(function, AString.Null), + Delegate.wrap(function, null)); } @Test @@ -28,7 +28,7 @@ public void delegate_should_wrap_null_AString() { public void map_should_wrap_null_AString() { AString.Transformer function = value -> value; assertEquals( - Delegate.wrap(AString.Null, function), + Delegate.wrap(function, AString.Null), mapAString(null, function) ); } @@ -96,7 +96,7 @@ public void lambda_ref_should_be_efficient() { @Test public void delegate_should_return_Null_on_null_transformer() { - assertEquals(AString.Null, Delegate.wrap((AString) null, null)); + assertEquals(AString.Null, Delegate.wrap(null, (AString) null)); } private CharSequence function(CharSequence value) { diff --git a/astring/src/test/kotlin/xyz/tynn/astring/AStringFactoryKtTest.kt b/astring/src/test/kotlin/xyz/tynn/astring/AStringFactoryKtTest.kt index 95d49fc..3bb267f 100644 --- a/astring/src/test/kotlin/xyz/tynn/astring/AStringFactoryKtTest.kt +++ b/astring/src/test/kotlin/xyz/tynn/astring/AStringFactoryKtTest.kt @@ -374,8 +374,8 @@ internal class AStringFactoryKtTest { val aString = mockk() assertEquals( Delegate.wrap( - aString, Predicate.NonBlank, + aString, ), aString.nullIfBlank(), ) @@ -415,47 +415,10 @@ internal class AStringFactoryKtTest { val aString = mockk() assertEquals( Delegate.wrap( - aString, Predicate.NonEmpty, - ), - aString.nullIfEmpty(), - ) - } - - @Test - fun `emptyIfNull should return empty Wrapper for null`() { - assertEquals( - "".asAString(), - null.emptyIfNull(), - ) - } - - @Test - fun `emptyIfNull should return empty Wrapper for Null`() { - assertEquals( - "".asAString(), - null.asAString().emptyIfNull(), - ) - } - - @Test - fun `emptyIfNull should return identity for Wrapper`() { - val aString = "wrapper".asAString() - assertSame( - aString, - aString.emptyIfNull(), - ) - } - - @Test - fun `emptyIfNull should return Delegate`() { - val aString = mockk() - assertEquals( - Delegate.wrap( aString, - Predicate.NonNull, ), - aString.emptyIfNull(), + aString.nullIfEmpty(), ) } @@ -484,8 +447,8 @@ internal class AStringFactoryKtTest { val aString = mockk() assertEquals( Delegate.wrap( - aString, Transformer.Trim, + aString, ), aString.trim(), ) diff --git a/astring/src/test/kotlin/xyz/tynn/astring/AStringProviderKtTest.kt b/astring/src/test/kotlin/xyz/tynn/astring/AStringProviderKtTest.kt index a7f2a1a..4a6d916 100644 --- a/astring/src/test/kotlin/xyz/tynn/astring/AStringProviderKtTest.kt +++ b/astring/src/test/kotlin/xyz/tynn/astring/AStringProviderKtTest.kt @@ -56,7 +56,7 @@ internal class AStringProviderKtTest { } assertFalse { Delegate.wrap(mockk()) == - Delegate.wrap(mockk(), mockk()) + Delegate.wrap(mockk(), mockk()) } } diff --git a/astring/src/test/kotlin/xyz/tynn/astring/AStringReducerKtTest.kt b/astring/src/test/kotlin/xyz/tynn/astring/AStringReducerKtTest.kt index 087de57..e6b8e60 100644 --- a/astring/src/test/kotlin/xyz/tynn/astring/AStringReducerKtTest.kt +++ b/astring/src/test/kotlin/xyz/tynn/astring/AStringReducerKtTest.kt @@ -61,22 +61,23 @@ internal class AStringReducerKtTest { @Test fun `equals should be false for non reducer Delegate`() { assertFalse { - Delegate.wrap(mockk(), mockk()).equals("foo") + Delegate.wrap(mockk(), mockk()).equals("foo") } assertFalse { - Delegate.wrap(mockk(), mockk()) == mockk() + Delegate.wrap(mockk(), mockk()) == mockk() } assertFalse { - Delegate.wrap(mockk(), mockk()).equals(mockk()) + Delegate.wrap(mockk(), mockk()).equals(mockk()) } assertFalse { - Delegate.wrap(mockk(), mockk()).equals(mockk()) + Delegate.wrap(mockk(), mockk()).equals(mockk()) } assertFalse { - Delegate.wrap(mockk(), mockk()).equals(mockk()) + Delegate.wrap(mockk(), mockk()).equals(mockk()) } assertFalse { - Delegate.wrap(mockk(), mockk()) == Delegate.wrap(mockk()) + Delegate.wrap(mockk(), mockk()) == + Delegate.wrap(mockk()) } } diff --git a/astring/src/test/kotlin/xyz/tynn/astring/AStringTransformerKtTest.kt b/astring/src/test/kotlin/xyz/tynn/astring/AStringTransformerKtTest.kt index 4767a45..c8b1b9b 100644 --- a/astring/src/test/kotlin/xyz/tynn/astring/AStringTransformerKtTest.kt +++ b/astring/src/test/kotlin/xyz/tynn/astring/AStringTransformerKtTest.kt @@ -22,55 +22,48 @@ internal class AStringTransformerKtTest { @Test fun `equals should be true for matching transformer and receiver`() { assertTrue { - Delegate.wrap(AppId, Transformer()) == Delegate.wrap(AppId, Transformer()) + Delegate.wrap(Transformer(), AppId) == Delegate.wrap(Transformer(), AppId) } assertTrue { - Delegate.wrap(AppVersion, Transformer()) == Delegate.wrap(AppVersion, Transformer()) - } - assertTrue { - Delegate.wrap(AppId, Predicate.NonBlank) == Delegate.wrap(AppId, Predicate.NonBlank) - } - assertTrue { - Delegate.wrap(AppId, Predicate.NonEmpty) == Delegate.wrap(AppId, Predicate.NonEmpty) - } - assertTrue { - Delegate.wrap(AppId, Predicate.NonNull) == Delegate.wrap(AppId, Predicate.NonNull) + Delegate.wrap(Transformer(), AppVersion) == Delegate.wrap(Transformer(), AppVersion) } } @Test fun `equals should be false for non matching transformer`() { assertFalse { - Delegate.wrap(AppId, mockk()) == Delegate.wrap(AppId, mockk()) + Delegate.wrap(mockk(), AppId) == + Delegate.wrap(mockk(), AppId) } } @Test fun `equals should be false for non matching receiver`() { assertFalse { - Delegate.wrap(mockk(), Transformer()) == Delegate.wrap(mockk(), Transformer()) + Delegate.wrap(Transformer(), mockk()) == Delegate.wrap(Transformer(), mockk()) } } @Test fun `equals should be false for non transformer Delegate`() { assertFalse { - Delegate.wrap(mockk(), mockk()).equals("foo") + Delegate.wrap(mockk(), mockk()).equals("foo") } assertFalse { - Delegate.wrap(mockk(), mockk()) == mockk() + Delegate.wrap(mockk(), mockk()) == mockk() } assertFalse { - Delegate.wrap(mockk(), mockk()).equals(mockk()) + Delegate.wrap(mockk(), mockk()).equals(mockk()) } assertFalse { - Delegate.wrap(mockk(), mockk()).equals(mockk()) + Delegate.wrap(mockk(), mockk()).equals(mockk()) } assertFalse { - Delegate.wrap(mockk(), mockk()).equals(mockk()) + Delegate.wrap(mockk(), mockk()).equals(mockk()) } assertFalse { - Delegate.wrap(mockk(), mockk()) == Delegate.wrap(mockk()) + Delegate.wrap(mockk(), mockk()) == + Delegate.wrap(mockk()) } } @@ -79,8 +72,8 @@ internal class AStringTransformerKtTest { assertEquals( 5150, Delegate.wrap( - mockk { every { this@mockk.hashCode() } returns 345 }, - mockk { every { this@mockk.hashCode() } returns 123 }, + mockk { every { this@mockk.hashCode() } returns 123 }, + mockk { every { this@mockk.hashCode() } returns 345 }, ).hashCode(), ) } @@ -96,38 +89,6 @@ internal class AStringTransformerKtTest { ) } - @Test - fun `emptyIfNull should map null to an empty string`() { - assertEquals( - "", - context.aString( - AString(null) - .emptyIfNull(), - ) - ) - assertEquals( - "", - context.aString( - AString("") - .emptyIfNull(), - ) - ) - assertEquals( - " ", - context.aString( - AString(" ") - .emptyIfNull(), - ) - ) - assertEquals( - "value", - context.aString( - AString("value") - .emptyIfNull(), - ) - ) - } - @Test fun `nullIfBlank should map a blank string to null`() { assertNull(context.aString(AString(null).nullIfBlank())) @@ -163,205 +124,13 @@ internal class AStringTransformerKtTest { } @Test - fun `defaultIfBlank should return original if non blank`() { - assertEquals( - "value", - context.aString( - AString( - value = "value", - ).defaultIfBlank( - defaultValue = "", - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = "value", - ).defaultIfBlank( - defaultValue = AString( - value = "", - ), - ), - ), - ) - } - - @Test - fun `defaultIfBlank should return defaultValue if null`() { - assertEquals( - "value", - context.aString( - AString( - value = null, - ).defaultIfBlank( - defaultValue = "value", - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = "", - ).defaultIfBlank( - defaultValue = "value", - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = " ", - ).defaultIfBlank( - defaultValue = "value", - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = null, - ).defaultIfBlank( - defaultValue = AString( - value = "value", - ) - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = "", - ).defaultIfBlank( - defaultValue = AString( - value = "value", - ) - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = " ", - ).defaultIfBlank( - defaultValue = AString( - value = "value", - ) - ), - ), - ) - } - - @Test - fun `defaultIfEmpty should return original if non null`() { - assertEquals( - " ", - context.aString( - AString( - value = " ", - ).defaultIfEmpty( - defaultValue = "", - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = "value", - ).defaultIfEmpty( - defaultValue = "", - ), - ), - ) - assertEquals( - " ", - context.aString( - AString( - value = " ", - ).defaultIfEmpty( - defaultValue = AString( - value = "", - ), - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = "value", - ).defaultIfEmpty( - defaultValue = AString( - value = "", - ), - ), - ), - ) - } - - @Test - fun `defaultIfEmpty should return defaultValue if null`() { - assertEquals( - "value", - context.aString( - AString( - value = null, - ).defaultIfEmpty( - defaultValue = "value", - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = "", - ).defaultIfEmpty( - defaultValue = "value", - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = null, - ).defaultIfEmpty( - defaultValue = AString( - value = "value", - ) - ), - ), - ) - assertEquals( - "value", - context.aString( - AString( - value = "", - ).defaultIfEmpty( - defaultValue = AString( - value = "value", - ) - ), - ), - ) - } - - @Test - fun `defaultIfNull should return original if non null`() { + fun `ifNull should return original if non null`() { assertEquals( "", context.aString( AString( value = "", - ).defaultIfNull( + ).ifNull( defaultValue = " ", ), ), @@ -371,7 +140,7 @@ internal class AStringTransformerKtTest { context.aString( AString( value = " ", - ).defaultIfNull( + ).ifNull( defaultValue = "", ), ), @@ -381,7 +150,7 @@ internal class AStringTransformerKtTest { context.aString( AString( value = "value", - ).defaultIfNull( + ).ifNull( defaultValue = "", ), ), @@ -391,7 +160,7 @@ internal class AStringTransformerKtTest { context.aString( AString( value = "", - ).defaultIfNull( + ).ifNull( defaultValue = AString( value = " ", ), @@ -403,7 +172,7 @@ internal class AStringTransformerKtTest { context.aString( AString( value = " ", - ).defaultIfNull( + ).ifNull( defaultValue = AString( value = "", ), @@ -415,7 +184,7 @@ internal class AStringTransformerKtTest { context.aString( AString( value = "value", - ).defaultIfNull( + ).ifNull( defaultValue = AString( value = "", ), @@ -425,13 +194,13 @@ internal class AStringTransformerKtTest { } @Test - fun `defaultIfNull should return defaultValue if null`() { + fun `ifNull should return defaultValue if null`() { assertEquals( "value", context.aString( AString( value = null, - ).defaultIfNull( + ).ifNull( defaultValue = "value", ), ), @@ -441,7 +210,7 @@ internal class AStringTransformerKtTest { context.aString( AString( value = null, - ).defaultIfNull( + ).ifNull( defaultValue = AString( value = "value", )