Skip to content

Commit

Permalink
Fix #14: add an isOnlyEmojis method
Browse files Browse the repository at this point in the history
  • Loading branch information
vdurmont committed Feb 13, 2017
1 parent 107534d commit 91281b3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/vdurmont/emoji/EmojiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ public static boolean isEmoji(String string) {
EMOJI_TRIE.isEmoji(string.toCharArray()).exactMatch();
}

/**
* Tests if a given String only contains emojis.
*
* @param string the string to test
*
* @return true if the string only contains emojis, false else
*/
public static boolean isOnlyEmojis(String string) {
return string != null && EmojiParser.removeAllEmojis(string).isEmpty();
}

/**
* Checks if sequence of chars contain an emoji.
* @param sequence Sequence of char that may contain emoji in full or
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/com/vdurmont/emoji/EmojiManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,42 @@ public void isEmoji_for_an_emoji_and_other_chars_returns_false() {
assertFalse(isEmoji);
}

@Test
public void isOnlyEmojis_for_an_emoji_returns_true() {
// GIVEN
String str = "πŸ˜€";

// WHEN
boolean isEmoji = EmojiManager.isOnlyEmojis(str);

// THEN
assertTrue(isEmoji);
}

@Test
public void isOnlyEmojis_for_emojis_returns_true() {
// GIVEN
String str = "πŸ˜€πŸ˜€πŸ˜€";

// WHEN
boolean isEmoji = EmojiManager.isOnlyEmojis(str);

// THEN
assertTrue(isEmoji);
}

@Test
public void isOnlyEmojis_for_random_string_returns_false() {
// GIVEN
String str = "πŸ˜€a";

// WHEN
boolean isEmoji = EmojiManager.isOnlyEmojis(str);

// THEN
assertFalse(isEmoji);
}

@Test
public void getAllTags_returns_the_tags() {
// GIVEN
Expand Down

0 comments on commit 91281b3

Please sign in to comment.