Skip to content

Commit

Permalink
Merge pull request #287 from usethesource/fix-issue-286-with-tests
Browse files Browse the repository at this point in the history
fix issue 286 with tests
  • Loading branch information
jurgenvinju authored Jan 5, 2025
2 parents 5beec0e + a32ccbb commit adcc455
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/main/java/io/usethesource/vallang/type/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,16 @@ public Type getTypeParameters() {
*/
public int compareTo(Type o) {
if (isSubtypeOf(o)) {
return -1;
} else if (o.isSubtypeOf(this)) {
return o.isSubtypeOf(this)
? 0
: -1;
}
else if (o.isSubtypeOf(this)) {
return 1;
}
return 0;
else {
return 0;
}
}

protected boolean isSubtypeOfParameter(Type type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -61,6 +60,30 @@ public void emptyTupleNeverHasLabels(TypeFactory tf) {
assertTrue(tf.tupleEmpty() == tf.tupleType(new Type[0], new String[0]));
}

@ParameterizedTest @ArgumentsSource(ValueProvider.class) @TypeConfig(Option.ALL)
public void compareTo(Type t, Type u) {
if (t.isSubtypeOf(u)) {
if (!t.equivalent(u)) {
assertTrue(t.compareTo(u) == -1);
}
else {
assertTrue(t.compareTo(u) == 0);
}
}
else if (u.isSubtypeOf(t)) {
if (!t.equivalent(u)) {
assertTrue(t.compareTo(u) == 1);
}
else {
assertTrue(t.compareTo(u) == 0);
}
}
else {
assertTrue(t.compareTo(u) == 0);
assertTrue(u.compareTo(t) == 0);
}
}

@ParameterizedTest @ArgumentsSource(ValueProvider.class) @TypeConfig(Option.ALL)
public void covariance(TypeFactory tf, Type t, Type u) {
if (!t.comparable(u)) {
Expand Down

0 comments on commit adcc455

Please sign in to comment.