Fixed tokenization to handle multi-level sign
This commit is contained in:
+10
-2
@@ -85,10 +85,18 @@ public class SubscriptionsStore {
|
|||||||
String s = splitted[i];
|
String s = splitted[i];
|
||||||
if (s.isEmpty()) {
|
if (s.isEmpty()) {
|
||||||
if (i != 0){
|
if (i != 0){
|
||||||
throw new ParseException("Bad format of topic, expetec toppic name between separators", i);
|
throw new ParseException("Bad format of topic, expetec topic name between separators", i);
|
||||||
}
|
}
|
||||||
res.add(Token.EMPTY);
|
res.add(Token.EMPTY);
|
||||||
} else {
|
} else if (s.equals("#")) {
|
||||||
|
//check that multi is the last symbol
|
||||||
|
if (i != splitted.length - 1 ) {
|
||||||
|
throw new ParseException("Bad format of topic, the multi symbol (#) has to be the last one after a separator", i);
|
||||||
|
}
|
||||||
|
res.add(Token.MULTI);
|
||||||
|
} else if (s.contains("#")) {
|
||||||
|
throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i);
|
||||||
|
}else {
|
||||||
res.add(new Token(s));
|
res.add(new Token(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
@@ -39,6 +39,26 @@ public class SubscriptionsStoreTest {
|
|||||||
store.splitTopic("/finance//stock/ibm");
|
store.splitTopic("/finance//stock/ibm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSplitTopicMultiValid() throws ParseException {
|
||||||
|
List tokens = store.splitTopic("finance/stock/#");
|
||||||
|
assertEqualsSeq(asArray("finance", "stock", Token.MULTI), tokens);
|
||||||
|
|
||||||
|
tokens = store.splitTopic("#");
|
||||||
|
assertEqualsSeq(asArray(Token.MULTI), tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(expected = ParseException.class)
|
||||||
|
public void testSplitTopicMultiInTheMiddleNotValid() throws ParseException {
|
||||||
|
store.splitTopic("finance/#/closingprice");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ParseException.class)
|
||||||
|
public void testSplitTopicMultiNotAferSeparatorNotValid() throws ParseException {
|
||||||
|
store.splitTopic("finance#");
|
||||||
|
}
|
||||||
|
|
||||||
private static Token[] asArray(Object... l) {
|
private static Token[] asArray(Object... l) {
|
||||||
Token[] tokens = new Token[l.length];
|
Token[] tokens = new Token[l.length];
|
||||||
for (int i = 0; i < l.length; i++) {
|
for (int i = 0; i < l.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user