Create CharType.forCharacter() method
This commit is contained in:
parent
7d8b74608f
commit
da3ce7c65f
|
@ -128,6 +128,21 @@ class VersionParser implements Parser<Version> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the type for a given character.
|
||||||
|
*
|
||||||
|
* @param chr the character to get the type for
|
||||||
|
* @return the type of the specified character
|
||||||
|
*/
|
||||||
|
static CharType forCharacter(Character chr) {
|
||||||
|
for (CharType type : values()) {
|
||||||
|
if (type.isMatchedBy(chr)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package com.github.zafarkhaja.semver;
|
package com.github.zafarkhaja.semver;
|
||||||
|
|
||||||
|
import com.github.zafarkhaja.semver.VersionParser.CharType;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static com.github.zafarkhaja.semver.VersionParser.CharType.*;
|
import static com.github.zafarkhaja.semver.VersionParser.CharType.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
@ -88,4 +89,15 @@ public class VersionParserCharTypeTest {
|
||||||
assertFalse(ILLEGAL.isMatchedBy('a'));
|
assertFalse(ILLEGAL.isMatchedBy('a'));
|
||||||
assertFalse(ILLEGAL.isMatchedBy('0'));
|
assertFalse(ILLEGAL.isMatchedBy('0'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnCharTypeForCharacter() {
|
||||||
|
assertEquals(DIGIT, CharType.forCharacter('1'));
|
||||||
|
assertEquals(LETTER, CharType.forCharacter('a'));
|
||||||
|
assertEquals(DOT, CharType.forCharacter('.'));
|
||||||
|
assertEquals(HYPHEN, CharType.forCharacter('-'));
|
||||||
|
assertEquals(PLUS, CharType.forCharacter('+'));
|
||||||
|
assertEquals(EOL, CharType.forCharacter(null));
|
||||||
|
assertEquals(ILLEGAL, CharType.forCharacter('!'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user