Skip to content

Commit

Permalink
feature: Add a new standard join configuration for spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
RedDaedalus committed Aug 13, 2023
1 parent 249a333 commit b5b6d40
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ public interface JoinConfiguration extends Buildable<JoinConfiguration, JoinConf
return JoinConfigurationImpl.STANDARD_NEW_LINES;
}

/**
* Provides a join configuration with no prefix or suffix that simply joins the components together using the {@link Component#space()} component.
*
* <p>A purely text based example of this syntax, without introducing the concepts of components, would join the two strings 'hello' and 'there' together,
* creating the following output: 'hello there'.</p>
*
* @return the join configuration
* @since 4.14.0
*/
static @NotNull JoinConfiguration spaces() {
return JoinConfigurationImpl.STANDARD_SPACES;
}

/**
* Provides a join configuration with no prefix or suffix that simply joins the components together using a single comma, matching a CSV like layout.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ final class JoinConfigurationImpl implements JoinConfiguration {
static final JoinConfigurationImpl NULL = new JoinConfigurationImpl();

static final JoinConfiguration STANDARD_NEW_LINES = JoinConfiguration.separator(Component.newline());
static final JoinConfiguration STANDARD_SPACES = JoinConfiguration.separator(Component.space());
static final JoinConfiguration STANDARD_COMMA_SEPARATED = JoinConfiguration.separator(Component.text(","));
static final JoinConfiguration STANDARD_COMMA_SPACE_SEPARATED = JoinConfiguration.separator(Component.text(", "));
static final JoinConfiguration STANDARD_ARRAY_LIKE = JoinConfiguration.builder()
Expand Down
15 changes: 15 additions & 0 deletions api/src/test/java/net/kyori/adventure/text/JoinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,21 @@ final void testStandardJoinConfigurationsNewLines() {
);
}

@Test
final void testStandardJoinConfigurationsSpaces() {
final Component result = Component.join(JoinConfiguration.spaces(), Component.text("line 1"), Component.text("line 2"), Component.text("line 3"));
assertEquals(
Component.text()
.append(Component.text("line 1"))
.append(Component.space())
.append(Component.text("line 2"))
.append(Component.space())
.append(Component.text("line 3"))
.build(),
result
);
}

@Test
final void testStandardJoinConfigurationsCommas() {
final Component result = Component.join(JoinConfiguration.commas(false), Component.text("line 1"), Component.text("line 2"), Component.text("line 3"));
Expand Down

0 comments on commit b5b6d40

Please sign in to comment.