From f84b3786dcd17ae58dfd08c0e91247f32065fef5 Mon Sep 17 00:00:00 2001 From: JoostK Date: Thu, 1 Oct 2020 17:09:38 +0200 Subject: [PATCH] test(language-service): test ICU expressions in hybrid visitor (#39072) This commit adds tests for locating expressions within ICU expressions. PR Close #39072 --- .../ivy/test/hybrid_visitor_spec.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/language-service/ivy/test/hybrid_visitor_spec.ts b/packages/language-service/ivy/test/hybrid_visitor_spec.ts index 556ac0a601..04d3578238 100644 --- a/packages/language-service/ivy/test/hybrid_visitor_spec.ts +++ b/packages/language-service/ivy/test/hybrid_visitor_spec.ts @@ -324,6 +324,45 @@ describe('findNodeAtPosition for template AST', () => { expect(node).toBeInstanceOf(e.PropertyRead); expect((node as e.PropertyRead).name).toBe('bar'); }); + + it('should locate switch value in ICUs', () => { + const {errors, nodes, position} = parse(`{sw¦itch, plural, other {text}}">`); + expect(errors).toBe(null); + const node = findNodeAtPosition(nodes, position); + expect(isExpressionNode(node!)).toBe(true); + expect(node).toBeInstanceOf(e.PropertyRead); + expect((node as e.PropertyRead).name).toBe('switch'); + }); + + it('should locate switch value in nested ICUs', () => { + const {errors, nodes, position} = parse( + `{expr, plural, other { {ne¦sted, plural, =1 { {{nestedInterpolation}} }} }}">`); + expect(errors).toBe(null); + const node = findNodeAtPosition(nodes, position); + expect(isExpressionNode(node!)).toBe(true); + expect(node).toBeInstanceOf(e.PropertyRead); + expect((node as e.PropertyRead).name).toBe('nested'); + }); + + it('should locate interpolation expressions in ICUs', () => { + const {errors, nodes, position} = + parse(`{expr, plural, other { {{ i¦nterpolation }} }}">`); + expect(errors).toBe(null); + const node = findNodeAtPosition(nodes, position); + expect(isExpressionNode(node!)).toBe(true); + expect(node).toBeInstanceOf(e.PropertyRead); + expect((node as e.PropertyRead).name).toBe('interpolation'); + }); + + it('should locate interpolation expressions in nested ICUs', () => { + const {errors, nodes, position} = parse( + `{expr, plural, other { {nested, plural, =1 { {{n¦estedInterpolation}} }} }}">`); + expect(errors).toBe(null); + const node = findNodeAtPosition(nodes, position); + expect(isExpressionNode(node!)).toBe(true); + expect(node).toBeInstanceOf(e.PropertyRead); + expect((node as e.PropertyRead).name).toBe('nestedInterpolation'); + }); }); describe('findNodeAtPosition for expression AST', () => {