From 7cd1b7fcaf43a93d637f74ba724bf34549bdca27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E6=B1=9F=E4=B8=9C=E5=8E=BB?= <6405352+dlxqlig@users.noreply.github.com> Date: Wed, 23 Oct 2019 22:35:45 +0800 Subject: [PATCH] test(compiler-dom): test namespace parsing (#356) --- packages/compiler-dom/__tests__/parse.spec.ts | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/packages/compiler-dom/__tests__/parse.spec.ts b/packages/compiler-dom/__tests__/parse.spec.ts index 6a5b22b4..a202eda4 100644 --- a/packages/compiler-dom/__tests__/parse.spec.ts +++ b/packages/compiler-dom/__tests__/parse.spec.ts @@ -205,4 +205,141 @@ describe('DOM parser', () => { }) }) }) + + describe('Namespaces', () => { + test('HTML namesapce', () => { + const ast = parse('test', parserOptions) + const element = ast.children[0] as ElementNode + + expect(element.ns).toBe(DOMNamespaces.HTML) + }) + + test('SVG namesapce', () => { + const ast = parse('test', parserOptions) + const element = ast.children[0] as ElementNode + + expect(element.ns).toBe(DOMNamespaces.SVG) + }) + + test('MATH_ML namesapce', () => { + const ast = parse('test', parserOptions) + const element = ast.children[0] as ElementNode + + expect(element.ns).toBe(DOMNamespaces.MATH_ML) + }) + + test('SVG in MATH_ML namesapce', () => { + const ast = parse( + '', + parserOptions + ) + const elementMath = ast.children[0] as ElementNode + const elementAnnotation = elementMath.children[0] as ElementNode + const elementSvg = elementAnnotation.children[0] as ElementNode + + expect(elementMath.ns).toBe(DOMNamespaces.MATH_ML) + expect(elementSvg.ns).toBe(DOMNamespaces.SVG) + }) + + test('html text/html in MATH_ML namesapce', () => { + const ast = parse( + '', + parserOptions + ) + + const elementMath = ast.children[0] as ElementNode + const elementAnnotation = elementMath.children[0] as ElementNode + const element = elementAnnotation.children[0] as ElementNode + + expect(elementMath.ns).toBe(DOMNamespaces.MATH_ML) + expect(element.ns).toBe(DOMNamespaces.HTML) + }) + + test('html application/xhtml+xml in MATH_ML namesapce', () => { + const ast = parse( + '', + parserOptions + ) + const elementMath = ast.children[0] as ElementNode + const elementAnnotation = elementMath.children[0] as ElementNode + const element = elementAnnotation.children[0] as ElementNode + + expect(elementMath.ns).toBe(DOMNamespaces.MATH_ML) + expect(element.ns).toBe(DOMNamespaces.HTML) + }) + + test('mtext malignmark in MATH_ML namesapce', () => { + const ast = parse( + '', + parserOptions + ) + const elementMath = ast.children[0] as ElementNode + const elementText = elementMath.children[0] as ElementNode + const element = elementText.children[0] as ElementNode + + expect(elementMath.ns).toBe(DOMNamespaces.MATH_ML) + expect(element.ns).toBe(DOMNamespaces.MATH_ML) + }) + + test('mtext and not malignmark tag in MATH_ML namesapce', () => { + const ast = parse('', parserOptions) + const elementMath = ast.children[0] as ElementNode + const elementText = elementMath.children[0] as ElementNode + const element = elementText.children[0] as ElementNode + + expect(elementMath.ns).toBe(DOMNamespaces.MATH_ML) + expect(element.ns).toBe(DOMNamespaces.HTML) + }) + + test('foreignObject tag in SVG namesapce', () => { + const ast = parse( + '', + parserOptions + ) + const elementSvg = ast.children[0] as ElementNode + const elementForeignObject = elementSvg.children[0] as ElementNode + const element = elementForeignObject.children[0] as ElementNode + + expect(elementSvg.ns).toBe(DOMNamespaces.SVG) + expect(element.ns).toBe(DOMNamespaces.HTML) + }) + + test('desc tag in SVG namesapce', () => { + const ast = parse('', parserOptions) + const elementSvg = ast.children[0] as ElementNode + const elementDesc = elementSvg.children[0] as ElementNode + const element = elementDesc.children[0] as ElementNode + + expect(elementSvg.ns).toBe(DOMNamespaces.SVG) + expect(element.ns).toBe(DOMNamespaces.HTML) + }) + + test('title tag in SVG namesapce', () => { + const ast = parse('', parserOptions) + const elementSvg = ast.children[0] as ElementNode + const elementTitle = elementSvg.children[0] as ElementNode + const element = elementTitle.children[0] as ElementNode + + expect(elementSvg.ns).toBe(DOMNamespaces.SVG) + expect(element.ns).toBe(DOMNamespaces.HTML) + }) + + test('SVG in HTML namesapce', () => { + const ast = parse('', parserOptions) + const elementHtml = ast.children[0] as ElementNode + const element = elementHtml.children[0] as ElementNode + + expect(elementHtml.ns).toBe(DOMNamespaces.HTML) + expect(element.ns).toBe(DOMNamespaces.SVG) + }) + + test('MATH in HTML namesapce', () => { + const ast = parse('', parserOptions) + const elementHtml = ast.children[0] as ElementNode + const element = elementHtml.children[0] as ElementNode + + expect(elementHtml.ns).toBe(DOMNamespaces.HTML) + expect(element.ns).toBe(DOMNamespaces.MATH_ML) + }) + }) })