-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide additional String formating utility method to reduce code dup…
…lication
- Loading branch information
Showing
8 changed files
with
114 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
key.util/src/test/java/org/key_project/util/StringsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* This file is part of KeY - https://key-project.org | ||
* KeY is licensed under the GNU General Public License Version 2 | ||
* SPDX-License-Identifier: GPL-2.0-only */ | ||
package org.key_project.util; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class StringsTest { | ||
|
||
@Test | ||
void containsWholeWord() { | ||
String[] sentences = new String[] { | ||
"asfKeY;prover", | ||
"KeY prover", | ||
"KeY,prover", | ||
"KeY;prover", | ||
"key;prover" | ||
}; | ||
assertTrue(Strings.containsWholeWord(sentences[0], "prover")); | ||
assertFalse(Strings.containsWholeWord(sentences[0], "KeY")); | ||
assertTrue(Strings.containsWholeWord(sentences[1], "prover")); | ||
assertTrue(Strings.containsWholeWord(sentences[1], "KeY")); | ||
assertTrue(Strings.containsWholeWord(sentences[2], "prover")); | ||
assertTrue(Strings.containsWholeWord(sentences[2], "KeY")); | ||
assertTrue(Strings.containsWholeWord(sentences[3], "prover")); | ||
assertTrue(Strings.containsWholeWord(sentences[3], "KeY")); | ||
assertTrue(Strings.containsWholeWord(sentences[4], "prover")); | ||
assertFalse(Strings.containsWholeWord(sentences[4], "KeY")); | ||
} | ||
|
||
@Test | ||
void isJMLComment() { | ||
String[] correctComments = { | ||
"/*@ requires ", "//@ requires", | ||
"/*+KeY@ requires", "//+KeY@ requires", | ||
"/*-OtherTool@", "//-OtherTool@" | ||
}; | ||
String[] inCorrectComments = { | ||
"/* @ requires ", "// @ requires", | ||
"/*+OtherTool@ requires", "//+OtherTool@ requires", | ||
"/*-KeY@", "//*-KeY@" | ||
}; | ||
|
||
for (var comment : correctComments) { | ||
assertTrue(Strings.isJMLComment(comment), | ||
"Classified correct comment as incorrect: " + comment); | ||
} | ||
for (var comment : inCorrectComments) { | ||
assertFalse(Strings.isJMLComment(comment), | ||
"Classified incorrect comment as correct: " + comment); | ||
} | ||
} | ||
|
||
@Test | ||
void formatAsList() { | ||
Iterator<String> it = Arrays.stream(new String[] { "a", "b", "c" }).iterator(); | ||
assertEquals("%a;b;c$", Strings.formatAsList(it, '%', ';', '$')); | ||
|
||
it = Arrays.stream(new String[] { "a" }).iterator(); | ||
assertEquals("%a$", Strings.formatAsList(it, '%', ';', '$')); | ||
|
||
it = Arrays.stream(new String[] {}).iterator(); | ||
assertEquals("%$", Strings.formatAsList(it, '%', ';', '$')); | ||
} | ||
} |