Skip to content

Commit

Permalink
Merge pull request allegro#24 from allegro/empty_map
Browse files Browse the repository at this point in the history
empty map exception
  • Loading branch information
rzukow authored Oct 20, 2016
2 parents 8c87e95 + b136d6e commit 45655c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/java/pl/allegro/tech/opel/OpelParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ Rule MapInstantiation() {
Rule Pairs() {
return Sequence(
push(nodeFactory.emptyPairsListNode()),
FirstOf(Sequence(Pair(), ZeroOrMore(", ", Pair())), EMPTY));
FirstOf(Sequence(Pair(), ZeroOrMore(", ", Pair())), ": ")
);
}

Rule Pair() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OpelEngineMapIntegrationSpec extends Specification {

where:
input || expResult
"{}" || [:]
"{:}" || [:]
"{'x':2}" || [x: 2]
"({'x': 2 })" || [x: 2]
"{'x': 2, 'y':3 }" || [x: 2, y: 3]
Expand Down Expand Up @@ -123,4 +123,20 @@ class OpelEngineMapIntegrationSpec extends Specification {
"({'get': x->x+x}.get('get'))('g')"|| 'gg'
"({'get': x->x+x}.get)('get')" || 'getget'
}
@Unroll
def 'should not parse #input'() {
given:
def engine = create().build()
when:
engine.eval(input)
then:
OpelException ex = thrown()
ex.getMessage() == "Error parsing expression: '${input}'"
where:
input << ["{}", "{ }", "{, }", "{ , }"]
}
}

0 comments on commit 45655c3

Please sign in to comment.