"""Offline VS Code Welcome & Editing workbench layout verifier for Ch06 (start-intro)."""
import json
VERSION = "CPython 3.12.14 offline VS Code workbench & status-bar verifier"
def check(name, summary, expected, actual):
return {
"name": name,
"summary": summary,
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = []
# Case 1: Welcome page & Editing workbench layout regions
welcome = {
"activity_bar_highlights": ["资源管理器", "搜索", "版本控制", "运行和调试"],
"start_actions": ["新建文件", "打开...", "运行命令..."],
"recent_folders": ["bluesky-demo"],
"walkthroughs": ["开始使用 VS Code", "了解基础知识", "提高工作效率"],
}
workbench = {
"activity_bar_icons": ["资源管理器", "搜索", "源代码管理", "运行和调试", "扩展"],
"active_sidebar": "资源管理器",
"workspace_folder": "BLUESKY-DEMO",
"active_file": "test.html",
}
cases.append(
check(
"welcome_and_workbench_layout",
"Verify Welcome page 4 zones and Editing workbench Activity Bar / Explorer tree structure",
{
"start_action_count": 3,
"walkthrough_count": 3,
"activity_icon_count": 5,
"workspace_and_file": "BLUESKY-DEMO/test.html",
},
{
"start_action_count": len(welcome["start_actions"]),
"walkthrough_count": len(welcome["walkthroughs"]),
"activity_icon_count": len(workbench["activity_bar_icons"]),
"workspace_and_file": f"{workbench['workspace_folder']}/{workbench['active_file']}",
},
)
)
# Case 2: Editor content highlighting tokens & Status Bar metadata
html_lines = [
"<!DOCTYPE html>",
'<html lang="zh-CN">',
"<head>",
' <meta charset="UTF-8">',
" <title>Test</title>",
"</head>",
"<body>",
" <h1>Hello VS Code</h1>",
" <p>Line 9</p>",
" <p>Line 10</p>",
" <p>Cursor Line 11</p>",
"</body>",
"</html>",
]
raw_doc = "\n".join(html_lines)
status_bar = {
"git_branch": "main",
"cursor_line": 11,
"encoding": "UTF-8",
"eol": "LF" if "\r\n" not in raw_doc else "CRLF",
"language_mode": "HTML",
"terminal_shell": "zsh",
}
cases.append(
check(
"editor_and_status_bar_inspector",
"Verify HTML syntax tokens (DOCTYPE html, <h1>), line 11 cursor tracking, and Status Bar fields",
{
"has_doctype_and_h1": True,
"line_11_present": True,
"git_branch": "main",
"encoding_eol_lang": ["UTF-8", "LF", "HTML"],
"terminal_shell": "zsh",
},
{
"has_doctype_and_h1": ("DOCTYPE html" in raw_doc and "<h1>" in raw_doc),
"line_11_present": "Cursor Line 11" in html_lines[status_bar["cursor_line"] - 1],
"git_branch": status_bar["git_branch"],
"encoding_eol_lang": [status_bar["encoding"], status_bar["eol"], status_bar["language_mode"]],
"terminal_shell": status_bar["terminal_shell"],
},
)
)
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-start-intro-lab/explore-start-intro.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-start-intro.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联25章) · 含当前章节或实例 · mbskycom202612a2203.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2221.zip