Skip to content

Commit bbfd011

Browse files
committed
Add tests for prefix nesting
1 parent 96afc18 commit bbfd011

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/contexts.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,26 @@ end
162162
@test getoptic(vn_prefixed) === getoptic(vn)
163163
end
164164

165+
@testset "nested within arbitrary context stacks" begin
166+
vn = @varname(x[1])
167+
ctx1 = PrefixContext{:a}(DefaultContext())
168+
ctx2 = SamplingContext(ctx1)
169+
ctx3 = PrefixContext{:b}(ctx2)
170+
ctx4 = DynamicPPL.ValuesAsInModelContext(OrderedDict(), false, ctx3)
171+
vn_prefixed1 = prefix(ctx1, vn)
172+
vn_prefixed2 = prefix(ctx2, vn)
173+
vn_prefixed3 = prefix(ctx3, vn)
174+
vn_prefixed4 = prefix(ctx4, vn)
175+
@test DynamicPPL.getsym(vn_prefixed1) == Symbol("a.x")
176+
@test DynamicPPL.getsym(vn_prefixed2) == Symbol("a.x")
177+
@test DynamicPPL.getsym(vn_prefixed3) == Symbol("a.b.x")
178+
@test DynamicPPL.getsym(vn_prefixed4) == Symbol("a.b.x")
179+
@test DynamicPPL.getoptic(vn_prefixed1) === DynamicPPL.getoptic(vn)
180+
@test DynamicPPL.getoptic(vn_prefixed2) === DynamicPPL.getoptic(vn)
181+
@test DynamicPPL.getoptic(vn_prefixed3) === DynamicPPL.getoptic(vn)
182+
@test DynamicPPL.getoptic(vn_prefixed4) === DynamicPPL.getoptic(vn)
183+
end
184+
165185
context = DynamicPPL.PrefixContext{:prefix}(SamplingContext())
166186
@testset "evaluation: $(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS
167187
# Sample with the context.

0 commit comments

Comments
 (0)