diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java index 5e70bd6..f2bc8ab 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java @@ -30,6 +30,7 @@ public class Variable { matcher.matches(); boolean hasEquals = false; + boolean fromMinus = false; String body = matcher.group(2); while(true){ int space = indexOf(body, "\\s+"); @@ -52,7 +53,11 @@ public class Variable { this.value = new Value(value); body = body.substring(value.length()+1); break; - + }else if(fromMinus){ + System.out.println("fromMinus "+value); + this.name = value; + body = body.substring(value.length()+1); + break; } else if(min == space){ if(value.isEmpty()){ do { @@ -74,11 +79,32 @@ public class Variable { }else if(min == equals){ hasEquals = true; body = body.substring(value.length()+1); - }else if(min == minus) { + }else if(min == minus){ + value = value+"<"; System.out.println("MINUS"); + int maxus = 1; + while(maxus > 0){ + char current = body.charAt(value.length()); + value+=current; + if(current == '<'){ + maxus++; + } + if(current == '>'){ + maxus--; + } + } + this.type = value; + body = body.substring(value.length()); + while(indexOf(body, "\\s+") == 0){ + body = body.substring(1); + } + fromMinus = true; + System.out.println("fromMinus on "+body); + }else if(min == quote){ + this.name = value; + body = body.substring(value.length()); break; }else { - break; } } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/VariableTest.java b/src/be/jeffcheasey88/peeratcode/parser/java/VariableTest.java index 5e7126c..f5bd878 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/VariableTest.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/VariableTest.java @@ -67,14 +67,29 @@ class VariableTest { void case4(){ try { Variable variable = new Variable(); - variable.parse("Testt; "); + variable.parse("Testast; "); assertEquals(0, variable.getModifier()); - assertEquals("Test", variable.getType()); + assertEquals("Testas", variable.getType()); assertEquals("t", variable.getName()); assertNull(variable.getValue()); }catch(Exception e){ fail(e); } } + + @Test + void case5(){ + try { + Variable variable = new Variable(); + variable.parse(" int i,j,k,l=1; "); + + assertEquals(0, variable.getModifier()); + assertEquals("int", variable.getType()); + assertEquals("i", variable.getName()); + assertNull(variable.getValue()); + }catch(Exception e){ + fail(e); + } + } } diff --git a/src/be/jeffcheasey88/peeratcode/repository/DatabaseRepository.java b/src/be/jeffcheasey88/peeratcode/repository/DatabaseRepository.java index 5547fbe..0f337c3 100644 --- a/src/be/jeffcheasey88/peeratcode/repository/DatabaseRepository.java +++ b/src/be/jeffcheasey88/peeratcode/repository/DatabaseRepository.java @@ -68,7 +68,7 @@ public class DatabaseRepository { private Puzzle makePuzzle(ResultSet puzzleResult) throws SQLException { return new Puzzle(puzzleResult.getInt("id_puzzle"), puzzleResult.getString("name"), - puzzleResult.getString("content"), null, "", 0, puzzleResult.getInt("origin")); + puzzleResult.getString("content"), null, "", 0, hasColumn(puzzleResult, "origin") ? puzzleResult.getInt("origin") : -1); } private Chapter makeChapter(ResultSet chapterResult) throws SQLException { diff --git a/src/be/jeffcheasey88/peeratcode/routes/PuzzleElement.java b/src/be/jeffcheasey88/peeratcode/routes/PuzzleElement.java index 71eb193..2c3f67b 100644 --- a/src/be/jeffcheasey88/peeratcode/routes/PuzzleElement.java +++ b/src/be/jeffcheasey88/peeratcode/routes/PuzzleElement.java @@ -33,7 +33,7 @@ public class PuzzleElement implements Response { puzzleJSON.put("id", puzzle.getId()); puzzleJSON.put("name", puzzle.getName()); puzzleJSON.put("content", puzzle.getContent()); - if (puzzle.getDepend() > 0) + if (puzzle.getDepend() > 0) puzzleJSON.put("depend", puzzle.getDepend()); writer.write(puzzleJSON.toJSONString()); } diff --git a/testApi/test.java b/testApi/test.java deleted file mode 100644 index 00607b6..0000000 --- a/testApi/test.java +++ /dev/null @@ -1 +0,0 @@ -ceci est du code source java \ No newline at end of file