Testing Text Transformation Compiler Features in uni-app
This test suite validates text transformation functionality in the uni-app UTS compiler, focusing on element node creation and text interpolation. It verifies how different text patterns and template expressions are compiled into virtual DOM nodes.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-app-uts/__tests__/android/transforms/transformText.spec.ts
import { assert } from '../testUtils'
describe('compiler: transform text', () => {
test('transform text', () => {
assert(`<text>hello</text>`, `createElementVNode("text", null, "hello")`)
assert(`<view>hello</view>`, `createElementVNode("view", null, "hello")`)
assert(
`<view><text>hello</text></view>`,
`createElementVNode("view", null, [
createElementVNode("text", null, "hello")
])`
)
assert(
`<view>aaa{{bbb}}ccc</view>`,
`createElementVNode("view", null, "aaa" + toDisplayString(_ctx.bbb) + "ccc", 1 /* TEXT */)`
)
assert(
`<view>aaa{{bbb}}<view>ccc{{ddd}}</view>{{eee}}fff<text>{{ggg}}</text></view>`,
`createElementVNode("view", null, [
"aaa" + toDisplayString(_ctx.bbb),
createElementVNode("view", null, "ccc" + toDisplayString(_ctx.ddd), 1 /* TEXT */),
toDisplayString(_ctx.eee) + "fff",
createElementVNode("text", null, toDisplayString(_ctx.ggg), 1 /* TEXT */)
])`
)
})
test('\n', () => {
assert(
`<view>
<text>\\\\\n 换行</text>
<text>\\\\n 换行</text>
<text>\\\n 换行</text>
<text>\\n 换行</text>
<text>\n 换行</text>
<text>\n 换行 \\n 换行 \\\n 换行 \\\\n 换行 \\\\\n 换行</text>
</view>`,
`createElementVNode(\"view\", null, [
createElementVNode(\"text\", null, \"\\\\\\\\ 换行\"),
createElementVNode(\"text\", null, \"\\\\n 换行\"),
createElementVNode(\"text\", null, \"\\\\ 换行\"),
createElementVNode(\"text\", null, \"\\n 换行\"),
createElementVNode(\"text\", null, \" 换行\"),
createElementVNode(\"text\", null, \" 换行 \\n 换行 \\\\ 换行 \\\\\\n 换行 \\\\\\\\ 换行\")
])`
)
})
})