mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
fix read/write variable in parent's scope, fix #39
This commit is contained in:
+10
-3
@@ -116,9 +116,16 @@ describe('scope', function () {
|
||||
expect(scope.get('posts[category.diary[0]].name'), 'A Nice Day')
|
||||
})
|
||||
|
||||
it('should create parents if needed', function () {
|
||||
scope.set('foo.bar.coo', 'COO')
|
||||
expect(scope.get('foo.bar.coo'), 'COO')
|
||||
it('should create in parent scope if needed', function () {
|
||||
scope.push({})
|
||||
scope.set('bar.coo', 'COO')
|
||||
expect(scope.get('bar.coo')).to.equal('COO')
|
||||
})
|
||||
it("should set parents' corresponding value", function () {
|
||||
scope.push({})
|
||||
scope.set('foo', 'bar')
|
||||
scope.pop()
|
||||
expect(scope.get('foo')).to.equal('bar')
|
||||
})
|
||||
})
|
||||
describe('strict_variables', function () {
|
||||
|
||||
@@ -33,6 +33,19 @@ describe('tags/for', function () {
|
||||
.to.eventually.equal('foo-coo-')
|
||||
})
|
||||
|
||||
describe('scope', function () {
|
||||
it('should read super scope', function () {
|
||||
var src = '{%for a in (1..2)%}{{num}}{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, {num: 1}))
|
||||
.to.eventually.equal('11')
|
||||
})
|
||||
it('should write super scope', function () {
|
||||
var src = '{%for a in (1..2)%}{{num}}{%assign num = 2%}{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, {num: 1}))
|
||||
.to.eventually.equal('12')
|
||||
})
|
||||
})
|
||||
|
||||
describe('illegal', function () {
|
||||
it('should reject when for not closed', function () {
|
||||
var src = '{%for c in alpha%}{{c}}'
|
||||
|
||||
Reference in New Issue
Block a user