From af841dc8722949485958b12d661d7c02111abf41 Mon Sep 17 00:00:00 2001 From: Joonas Mertanen Date: Thu, 8 Aug 2019 15:03:23 +0300 Subject: [PATCH] Add test for property access syntax --- test/unit/parser/tokenizer.ts | 7 +++++++ test/unit/template/value.ts | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/test/unit/parser/tokenizer.ts b/test/unit/parser/tokenizer.ts index 661f12ea2..1a88b2fff 100644 --- a/test/unit/parser/tokenizer.ts +++ b/test/unit/parser/tokenizer.ts @@ -66,6 +66,13 @@ describe('tokenizer', function () { expect(tokens[0]).instanceOf(OutputToken) expect(tokens[0].raw).to.equal('{{foo\n|date:\n"%Y-%m-%d"\n}}') }) + it('should handle complex object property access', function () { + const html = '{{ obj["my:property with anything"] }}' + const tokens = tokenizer.tokenize(html) + expect(tokens.length).to.equal(1) + expect(tokens[0]).instanceOf(OutputToken) + expect(tokens[0].value).to.equal('obj["my:property with anything"]') + }) it('should throw if tag not closed', function () { expect(() => { tokenizer.tokenize('{% assign foo = bar {{foo}}') diff --git a/test/unit/template/value.ts b/test/unit/template/value.ts index a5f824e0d..0222ee13c 100644 --- a/test/unit/template/value.ts +++ b/test/unit/template/value.ts @@ -96,6 +96,18 @@ describe('Value', function () { it('should tokenize a filter with a single argument', function () { expect(Value.tokenize('foo | add: 1')).to.eql(['foo', '|', 'add', ':', '1']) }) + it('should tokenize array indexing', function () { + expect(Value.tokenize('arr[0]')).to.eql(['arr[0]']) + }) + it('should tokenize simple object access', function () { + expect(Value.tokenize('obj["foo"]')).to.eql(['obj["foo"]']) + }) + it('should tokenize simple dot syntax object access', function () { + expect(Value.tokenize('obj.foo')).to.eql(['obj.foo']) + }) + it('should tokenize complex object property access', function () { + expect(Value.tokenize('obj["complex:string here"]')).to.eql(['obj["complex:string here"]']) + }) }) describe('#value()', function () {