Skip to content

Commit

Permalink
function scope izolation spec
Browse files Browse the repository at this point in the history
  • Loading branch information
tfij committed Oct 14, 2016
1 parent f2f121a commit d719e84
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/pl/allegro/tech/opel/OpelParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Rule IdentifiersListItem() {
Rule FunctionBody() {
return FirstOf(
Expression(),
Sequence("{ ", Body(), "} ", push(pop())), push(pop()));
Sequence("{ ", Body(), "} "));
}

Rule ListInstantiation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class OpelEngineFunctionIntegrationSpec extends Specification {
"val fun = (x, y) -> x*y; fun(2, 3, 4, 5)" || 6
}
def 'should avoid access to val defined in function outsite its'() {
def 'should avoid access to val defined in function outside its'() {
given:
def engine = create().build()
Expand Down Expand Up @@ -204,4 +204,33 @@ class OpelEngineFunctionIntegrationSpec extends Specification {
2 || 4
}
def "should izolate val declaration scope"() {
given:
def engine = create().build()
expect:
engine.eval(input).get() == expResult
where:
input << ["""
val b = 5;
val f = a -> {
val b = 10;
a*b
};
f(2)
""",
"""
val b = 5;
val f = a -> {
val b = 10;
a*b
};
f(b)
""",
]
expResult << [20, 50]
}
}

0 comments on commit d719e84

Please sign in to comment.