فهرست منبع

test: add template abbreviation

三咲智子 Kevin Deng 2 سال پیش
والد
کامیت
a68445bdac
1فایلهای تغییر یافته به همراه40 افزوده شده و 0 حذف شده
  1. 40 0
      packages/compiler-vapor/__tests__/abbreviation.spec.ts

+ 40 - 0
packages/compiler-vapor/__tests__/abbreviation.spec.ts

@@ -0,0 +1,40 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+const parser = new DOMParser()
+
+function parseHTML(html: string) {
+  return parser.parseFromString(html, 'text/html').body.innerHTML
+}
+
+function checkAbbr(template: string, abbrevation: string, expected: string) {
+  // TODO do some optimzations to make sure template === abbrevation
+  expect(parseHTML(abbrevation)).toBe(expected)
+}
+
+test('template abbreviation', () => {
+  checkAbbr('<div>hello</div>', '<div>hello', '<div>hello</div>')
+  checkAbbr(
+    '<div><div>hello</div></div>',
+    '<div><div>hello',
+    '<div><div>hello</div></div>',
+  )
+  checkAbbr(
+    '<div><span>foo</span><span/></div>',
+    '<div><span>foo</span><span>',
+    '<div><span>foo</span><span></span></div>',
+  )
+  checkAbbr(
+    '<div><hr/><div/></div>',
+    '<div><hr><div>',
+    '<div><hr><div></div></div>',
+  )
+  checkAbbr(
+    '<div><div/><hr/></div>',
+    '<div><div></div><hr>',
+    '<div><div></div><hr></div>',
+  )
+
+  checkAbbr('<span/>hello', '<span></span>hello', '<span></span>hello')
+})