"""Offline VS Code new file, HTML IntelliSense & split editor layout verifier for Ch10."""
import json
import tempfile
from pathlib import Path
VERSION = "CPython 3.12.14 offline VS Code Explorer & multi-editor layout verifier"
def check(name, summary, expected, actual):
return {
"name": name,
"summary": summary,
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = []
# Case 1: Explorer New File (index.html) & HTML IntelliSense prefix suggestions
html_tags = ["div", "dl", "dt", "dd", "details", "dialog", "header", "section"]
prefix = "di"
suggestions = [t for t in html_tags if t.startswith(prefix)]
with tempfile.TemporaryDirectory() as tmp:
ws = Path(tmp)
idx_file = ws / "index.html"
idx_file.write_text("<!DOCTYPE html>\n<html><body><div>Hello</div></body></html>\n", encoding="utf-8")
cases.append(
check(
"explorer_new_file_and_intellisense",
"Verify creating index.html in workspace and filtering HTML IntelliSense suggestions",
{
"created_file": "index.html",
"extension": ".html",
"suggestions_for_di": ["div", "dialog"],
"tab_inserted_top": "div",
},
{
"created_file": idx_file.name,
"extension": idx_file.suffix,
"suggestions_for_di": suggestions,
"tab_inserted_top": suggestions[0],
},
)
)
# Case 2: Multi-tab editor & vertical/horizontal split editor group model + view toggle
sidebar_open = True
sidebar_open = not sidebar_open
sidebar_open = not sidebar_open
layout = {
"orientation": "vertical",
"groups": [
{"id": 1, "tabs": ["index.html", "style.css"], "active": "index.html"},
{"id": 2, "tabs": ["app.js"], "active": "app.js"},
],
}
cases.append(
check(
"multi_tab_and_split_editor_layout",
"Verify Activity Bar view toggle and multi-group split editor tab state",
{
"sidebar_reopened": True,
"group_count": 2,
"total_tabs": 3,
"active_files": ["index.html", "app.js"],
},
{
"sidebar_reopened": sidebar_open,
"group_count": len(layout["groups"]),
"total_tabs": sum(len(g["tabs"]) for g in layout["groups"]),
"active_files": [g["active"] for g in layout["groups"]],
},
)
)
print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。
入口文件:projects/vscode-explore-the-user-interface-lab/explore-explore-the-user-interface.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-explore-the-user-interface.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2208.zip
课程关联工程包(登记关联25章) · 含当前章节或实例 · mbskycom202612a2203.zip