Skip to content

Commit

Permalink
testing eval context builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal Zukowski committed Sep 12, 2016
1 parent f78ca70 commit 3301174
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/test/groovy/pl/allegro/tech/opel/EvalContextBuilderSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package pl.allegro.tech.opel

import spock.lang.Specification

import static pl.allegro.tech.opel.EvalContextBuilder.create
import static pl.allegro.tech.opel.TestUtil.constFunctionReturning

class EvalContextBuilderSpec extends Specification {
def "should create merged context using elements from secondary context"() {
given:
def primary = create()
.withCompletedVariable('vv', 'value1')
.withFunction('ff', constFunctionReturning('from fun 1'))
.build()
def secondary = create()
.withCompletedVariable('v', 'value2')
.withFunction('f', constFunctionReturning('from fun 2'))
.build()

when:
def context = EvalContextBuilder.mergeContexts(primary, secondary)

then:
context.getVariable('v').get().get() == 'value2'
context.getFunction('f').get().apply([]).get() == 'from fun 2'
}

def "should create merged context using elements from primary context"() {
given:
def primary = create()
.withCompletedVariable('v', 'value1')
.withFunction('f', constFunctionReturning('from fun 1'))
.build()
def secondary = create()
.withCompletedVariable('v', 'value2')
.withFunction('f', constFunctionReturning('from fun 2'))
.build()

when:
def context = EvalContextBuilder.mergeContexts(primary, secondary)

then:
context.getVariable('v').get().get() == 'value1'
context.getFunction('f').get().apply([]).get() == 'from fun 1'
}
}

0 comments on commit 3301174

Please sign in to comment.