new test data parser parses hex numbers correct

This commit is contained in:
hneemann 2016-12-14 20:27:21 +01:00
parent a9360a465f
commit c31554c5b1
2 changed files with 19 additions and 1 deletions

View File

@ -143,7 +143,7 @@ public class Tokenizer {
boolean wasChar = true; boolean wasChar = true;
do { do {
c = readChar(); c = readChar();
if (isNumberChar(c) || c == 'x' || c == 'X') { if (isNumberChar(c) || isHexChar(c) || c == 'x' || c == 'X') {
builder.append((char) c); builder.append((char) c);
} else { } else {
unreadChar(c); unreadChar(c);
@ -208,6 +208,11 @@ public class Tokenizer {
|| (c == '_'); || (c == '_');
} }
private boolean isHexChar(int c) {
return (c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F');
}
private boolean isNumberChar(int c) { private boolean isNumberChar(int c) {
return (c >= '0' && c <= '9'); return (c >= '0' && c <= '9');
} }

View File

@ -35,6 +35,19 @@ public class ParserTest extends TestCase {
assertEquals(Value.Type.DONTCARE, td.getLines().get(2)[1].getType()); assertEquals(Value.Type.DONTCARE, td.getLines().get(2)[1].getType());
} }
public void testHex() throws TestingDataException, IOException, ParserException {
Parser td = new Parser("A B\n0 0xff").parse();
assertEquals(2, td.getNames().size());
assertEquals(1, td.getLines().size());
assertEquals(0, td.getLines().get(0)[0].getValue());
assertEquals(Value.Type.NORMAL, td.getLines().get(0)[0].getType());
assertEquals(255, td.getLines().get(0)[1].getValue());
assertEquals(Value.Type.NORMAL, td.getLines().get(0)[1].getType());
}
public void testMissingValue() throws IOException, ParserException { public void testMissingValue() throws IOException, ParserException {
try { try {
new Parser("A B\n0 0\n1").parse(); new Parser("A B\n0 0\n1").parse();