Skip to content

Commit

Permalink
Merge pull request #751 from 4drian3d/fix/tagresolver-equality
Browse files Browse the repository at this point in the history
fix: Fixed TagResolvers equality
  • Loading branch information
kezz authored Apr 29, 2022
2 parents 57d5319 + 4ca3afa commit 711a5c8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.internal.serializer.ClaimConsumer;
import net.kyori.adventure.text.minimessage.internal.serializer.SerializableResolver;
Expand Down Expand Up @@ -78,4 +79,21 @@ public void handle(final @NotNull Component serializable, final @NotNull ClaimCo
((SerializableResolver) this.resolver).handle(serializable, consumer);
}
}

@Override
public boolean equals(final @Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CachingTagResolver)) {
return false;
}
final CachingTagResolver that = (CachingTagResolver) other;
return Objects.equals(this.resolver, that.resolver);
}

@Override
public int hashCode() {
return Objects.hash(this.cache, this.resolver);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package net.kyori.adventure.text.minimessage.tag.resolver;

import java.util.Map;
import java.util.Objects;
import net.kyori.adventure.text.minimessage.tag.Tag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -45,4 +46,21 @@ public boolean contributeToMap(final @NotNull Map<String, Tag> map) {
map.putAll(this.tagMap);
return true;
}

@Override
public boolean equals(final @Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof MapTagResolver)) {
return false;
}
final MapTagResolver that = (MapTagResolver) other;
return Objects.equals(this.tagMap, that.tagMap);
}

@Override
public int hashCode() {
return Objects.hash(this.tagMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package net.kyori.adventure.text.minimessage.tag.resolver;

import java.util.Arrays;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.ParsingException;
Expand Down Expand Up @@ -89,4 +90,21 @@ public void handle(final @NotNull Component serializable, final @NotNull ClaimCo
}
}
}

@Override
public boolean equals(final @Nullable Object other) {
if (other == this) {
return true;
}
if (!(other instanceof SequentialTagResolver)) {
return false;
}
final SequentialTagResolver that = (SequentialTagResolver) other;
return Arrays.equals(this.resolvers, that.resolvers);
}

@Override
public int hashCode() {
return Arrays.hashCode(this.resolvers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,27 @@ void testValidTagName() {
assertDoesNotThrow(() -> TagResolver.resolver("v_9_v", Tag.preProcessParsed("something")));
}

@Test
void testTagResolverEquality() {
final TagResolver first = TagResolver.resolver(
Placeholder.unparsed("single", "replace"),
TagResolver.standard(),
TagResolver.empty(),
TagResolver.resolver("tag", Tag.selfClosingInserting(Component.empty()))
);
final TagResolver second = TagResolver.resolver(
Placeholder.unparsed("single", "replace"),
TagResolver.standard(),
TagResolver.empty(),
TagResolver.resolver("tag", Tag.selfClosingInserting(Component.empty()))
);

AbstractTest.dummyContext("equality test")
.deserialize("<test>", first, second);

assertEquals(first, second);
}

private static @NotNull Tag resolveForTest(final TagResolver resolver, final String tag) {
try {
final Context ctx = AbstractTest.dummyContext("help i shouldn't be seen");
Expand Down

0 comments on commit 711a5c8

Please sign in to comment.