Repository: willowtreeapps/assertk
Pull request #496 (2023-11-29 02:33:57)

Rename isSameAs/isNotSameAs to isSameInstanceAs/isNotSameInstanceAs
This makes it more clear these functions are about instance identity see: https://truth.dev/comparison

#495 

evant: The implementation is
```kotlin
fun <T> Assert<T>.isSameAs(expected: T) = isSameInstanceAs(expected)
```
so I don't think it's that important
JakeWharton: > The implementation is
> 
> ```kotlin
> fun <T> Assert<T>.isSameAs(expected: T) = isSameInstanceAs(expected)
> ```
> 
> so I don't think it's that important

I thought in the past you wanted me to keep tests for the old APIs, but it's absolutely possible I'm confusing this with other projects. I, too, think it's reasonable to omit.
evant: > > The implementation is
> > ```kotlin
> > fun <T> Assert<T>.isSameAs(expected: T) = isSameInstanceAs(expected)
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > so I don't think it's that important
> 
> I thought in the past you wanted me to keep tests for the old APIs, but it's absolutely possible I'm confusing this with other projects. I, too, think it's reasonable to omit.

Depends on what it was testing, anything more complicated than forwarding to a function which already has a test I would say to keep, yeah 

Patch:
diff --git a/assertk/src/commonMain/kotlin/assertk/assertions/any.kt b/assertk/src/commonMain/kotlin/assertk/assertions/any.kt
index a74cf79..cf062d2 100644
--- a/assertk/src/commonMain/kotlin/assertk/assertions/any.kt
+++ b/assertk/src/commonMain/kotlin/assertk/assertions/any.kt
@@ -28,7 +28,7 @@ fun Assert<Any>.hashCodeFun() = prop("hashCode", Any::hashCode)
 /**
  * Asserts the value is equal to the expected one, using `==`.
  * @see [isNotEqualTo]
- * @see [isSameAs]
+ * @see [isSameInstanceAs]
  */
 fun <T> Assert<T>.isEqualTo(expected: T) = given { actual ->
     if (actual == expected) return
@@ -38,7 +38,7 @@ fun <T> Assert<T>.isEqualTo(expected: T) = given { actual ->
 /**
  * Asserts the value is not equal to the expected one, using `!=`.
  * @see [isEqualTo]
- * @see [isNotSameAs]
+ * @see [isNotSameInstanceAs]
  */
 fun Assert<Any?>.isNotEqualTo(expected: Any?) = given { actual ->
     if (actual != expected) return
@@ -54,20 +54,36 @@ fun Assert<Any?>.isNotEqualTo(expected: Any?) = given { actual ->
 
 /**
  * Asserts the value is the same as the expected one, using `===`.
- * @see [isNotSameAs]
+ * @see [isNotSameInstanceAs]
  * @see [isEqualTo]
  */
-fun <T> Assert<T>.isSameAs(expected: T) = given { actual ->
+@Deprecated("renamed to isSameInstanceAs", replaceWith = ReplaceWith("isSameInstanceAs(expected)"))
+fun <T> Assert<T>.isSameAs(expected: T) = isSameInstanceAs(expected)
+
+/**
+ * Asserts the value is the same as the expected one, using `===`.
+ * @see [isNotSameInstanceAs]
+ * @see [isEqualTo]
+ */
+fun <T> Assert<T>.isSameInstanceAs(expected: T) = given { actual ->
     if (actual === expected) return
     expected(":${show(expected)} and:${show(actual)} to refer to the same object")
 }
 
 /**
  * Asserts the value is not the same as the expected one, using `!==`.
- * @see [isSameAs]
+ * @see [isSameInstanceAs]
+ * @see [isNotEqualTo]
+ */
+@Deprecated("renamed to isNotSameInstanceAs", replaceWith = ReplaceWith("isNotSameInstanceAs(expected)"))
+fun Assert<Any?>.isNotSameAs(expected: Any?) = isNotSameInstanceAs(expected)
+
+/**
+ * Asserts the value is not the same as the expected one, using `!==`.
+ * @see [isSameInstanceAs]
  * @see [isNotEqualTo]
  */
-fun Assert<Any?>.isNotSameAs(expected: Any?) = given { actual ->
+fun Assert<Any?>.isNotSameInstanceAs(expected: Any?) = given { actual ->
     if (actual !== expected) return
     expected(":${show(expected)} to not refer to the same object")
 }


Test patch:
diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt
index b08eebd..a8dbdad 100644
--- a/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt
+++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt
@@ -62,26 +62,26 @@ class AnyTest {
         assertEquals("expected to not be equal to:<test>", error.message)
     }
 
-    @Test fun isSameAs_same_objects_passes() {
-        assertThat(subject).isSameAs(subject)
+    @Test fun isSameInstanceAs_same_objects_passes() {
+        assertThat(subject).isSameInstanceAs(subject)
     }
 
-    @Test fun isSameAs_different_objects_fails() {
+    @Test fun isSameInstanceAs_different_objects_fails() {
         val nonSame = BasicObject("test")
         val error = assertFails("") {
-            assertThat(subject).isSameAs(nonSame)
+            assertThat(subject).isSameInstanceAs(nonSame)
         }
         assertEquals("expected:<test> and:<test> to refer to the same object", error.message)
     }
 
-    @Test fun isNotSameAs_non_same_objects_passes() {
+    @Test fun isNotSameInstanceAs_non_same_objects_passes() {
         val nonSame = BasicObject("test")
-        assertThat(subject).isNotSameAs(nonSame)
+        assertThat(subject).isNotSameInstanceAs(nonSame)
     }
 
-    @Test fun isNotSameAs_same_objects_fails() {
+    @Test fun isNotSameInstanceAs_same_objects_fails() {
         val error = assertFailsWith<AssertionError> {
-            assertThat(subject).isNotSameAs(subject)
+            assertThat(subject).isNotSameInstanceAs(subject)
         }
         assertEquals("expected:<test> to not refer to the same object", error.message)
     }