From 19c991b8b26f2d4fbd69c296935bb9ae7d150aff Mon Sep 17 00:00:00 2001 From: Searge Date: Wed, 2 May 2018 14:44:53 +0200 Subject: [PATCH] Added tests for suggesting numerical values instead of string values in suggestion builder --- .../suggestion/SuggestionsBuilderTest.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/mojang/brigadier/suggestion/SuggestionsBuilderTest.java b/src/test/java/com/mojang/brigadier/suggestion/SuggestionsBuilderTest.java index e46888c..b908ab5 100644 --- a/src/test/java/com/mojang/brigadier/suggestion/SuggestionsBuilderTest.java +++ b/src/test/java/com/mojang/brigadier/suggestion/SuggestionsBuilderTest.java @@ -5,6 +5,10 @@ import com.mojang.brigadier.context.StringRange; import org.junit.Before; import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; @@ -58,4 +62,25 @@ public class SuggestionsBuilderTest { assertThat(other.getStart(), is(builder.getStart())); assertThat(other.getRemaining(), equalTo(builder.getRemaining())); } -} \ No newline at end of file + + @Test + public void sort_alphabetical() { + Suggestions result = builder.suggest("2").suggest("4").suggest("6").suggest("8").suggest("30").suggest("32").build(); + List actual = result.getList().stream().map(Suggestion::getText).collect(Collectors.toList()); + assertThat(actual, equalTo(Lists.newArrayList( "2", "30", "32", "4", "6", "8"))); + } + + @Test + public void sort_numerical() { + Suggestions result = builder.suggest(2).suggest(4).suggest(6).suggest(8).suggest(30).suggest(32).build(); + List actual = result.getList().stream().map(Suggestion::getText).collect(Collectors.toList()); + assertThat(actual, equalTo(Lists.newArrayList( "2", "4", "6", "8", "30", "32"))); + } + + @Test + public void sort_mixed() { + Suggestions result = builder.suggest("11").suggest("22").suggest("33").suggest("a").suggest("b").suggest("c").suggest(2).suggest(4).suggest(6).suggest(8).suggest(30).suggest(32).suggest("3a").suggest("a3").build(); + List actual = result.getList().stream().map(Suggestion::getText).collect(Collectors.toList()); + assertThat(actual, equalTo(Lists.newArrayList( "11", "2", "22", "33", "3a", "4", "6", "8", "30", "32", "a", "a3", "b", "c"))); + } +}