From 8e96a6eb44894c2aa468a991b724a568cfab1755 Mon Sep 17 00:00:00 2001 From: Alex Kanunnikov Date: Fri, 13 Jun 2025 23:47:30 +0300 Subject: [PATCH] improve test coverage --- test/glimmer-utils-test.ts | 98 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/test/glimmer-utils-test.ts b/test/glimmer-utils-test.ts index 31e9a63e..3df50e81 100644 --- a/test/glimmer-utils-test.ts +++ b/test/glimmer-utils-test.ts @@ -33,6 +33,104 @@ describe('glimmer-utils', function () { expect(astPath?.node.type).toBe('ElementNode'); }); + it('does not fall to loop in nested Block -> BlockStatement [1]', function () { + const input = ` +{{#if foo}} +we +{{else if bar}} +ee +{{/if}} + `; + const astPath = ASTPath.toPosition(preprocess(input), toPosition(Position.create(3, 11))); + + expect(astPath?.node['original']).toBe('bar'); + }); + it('does not fall to loop in nested Block -> BlockStatement [2]', function () { + const input = ` +{{#if foo}} +we +{{else if bar}} +ee +{{/if}} + `; + const astPath = ASTPath.toPosition(preprocess(input), toPosition(Position.create(3, 8))); + + expect(astPath?.node['original']).toBe('if'); + }); + it('does not fall to loop in nested Block -> BlockStatement [3]', function () { + const input = ` +{{#if foo}} +we +{{else if bar}} +ee +{{/if}} + `; + const astPath = ASTPath.toPosition(preprocess(input), toPosition(Position.create(3, 4))); + + expect(astPath?.node['type']).toBe('BlockStatement'); + }); + it('does not fall to loop in nested Block -> BlockStatement [4]', function () { + const input = ` +{{#if foo}} +we +{{else if bar}} +ee +{{/if}} + `; + const astPath = ASTPath.toPosition(preprocess(input), toPosition(Position.create(5, 4))); + + expect(astPath?.node['type']).toBe('BlockStatement'); + }); + it('does not fall to loop in nested Block -> BlockStatement [5]', function () { + const input = ` +{{#if foo}} +we +{{else if (can bar)}} +ee +{{/if}} + `; + const astPath = ASTPath.toPosition(preprocess(input), toPosition(Position.create(3, 12))); + + expect(astPath?.node['original']).toBe('can'); + }); + it('does not fall to loop in nested Block -> BlockStatement [6]', function () { + const input = ` +{{#if foo}} +we +{{else if (can bar)}} +ee +{{/if}} + `; + const astPath = ASTPath.toPosition(preprocess(input), toPosition(Position.create(3, 15))); + + expect(astPath?.node['original']).toBe('bar'); + }); + it('does not fall to loop in nested Block -> BlockStatement [7]', function () { + const input = ` +{{#if foo}} +we +{{else if (can bar)}} +ee +{{/if}} + `; + const astPath = ASTPath.toPosition(preprocess(input), toPosition(Position.create(3, 10))); + + expect(astPath?.node['type']).toBe('SubExpression'); + }); + it('does not fall to loop in nested Block -> BlockStatement [8]', function () { + const input = ` +{{#if foo}} +{{else if (can bar)}} + {{#if foo}} + {{else if (can bar)}} + ee + {{/if}} +{{/if}} + `; + const astPath = ASTPath.toPosition(preprocess(input), toPosition(Position.create(5, 3))); + + expect(astPath?.node['type']).toBe('TextNode'); + }); }); describe('getLocalScope', function () { it('works as expected', function () {