"""Offline Eclipse Bookmarks ruler marker & Bookmarks view verifier for Ch29 (add-bookmarks)."""
import json
VERSION = "CPython 3.12.14 offline Eclipse Bookmarks marker & view verifier (desktop SWT IDE absent)"
def check(name, summary, expected, actual):
return {
"name": name,
"summary": summary,
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = []
# Case 1: Add Bookmark on vertical ruler stores file, line, description, and ruler icon
bookmarks = []
def add_bookmark(file_path, line, description):
bm = {"id": len(bookmarks) + 1, "file": file_path, "line": line, "description": description}
bookmarks.append(bm)
return bm
add_bookmark("src/com/example/OrderService.java", 42, "Check discount rounding rule")
add_bookmark("src/com/example/PaymentClient.java", 88, "Retry timeout configuration")
cases.append(
check(
"add_bookmark_ruler_and_store",
"Verify Add Bookmark on vertical ruler records file, line, and custom bookmark name",
{
"count": 2,
"first_entry": {
"file": "src/com/example/OrderService.java",
"line": 42,
"description": "Check discount rounding rule",
},
},
{
"count": len(bookmarks),
"first_entry": {
"file": bookmarks[0]["file"],
"line": bookmarks[0]["line"],
"description": bookmarks[0]["description"],
},
},
)
)
# Case 2: Open Bookmarks view (Window > Show View > Other -> General > Bookmarks) and Go to navigation
views = [
{"category": "General", "name": "Bookmarks"},
{"category": "General", "name": "Outline"},
{"category": "General", "name": "Tasks"},
{"category": "Java", "name": "Package Explorer"},
]
matched_views = [f"{v['category']} > {v['name']}" for v in views if "bookmark" in v["name"].lower()]
target = bookmarks[1]
goto_cursor = (target["file"], target["line"])
cases.append(
check(
"bookmarks_view_discovery_and_goto",
"Verify filtering 'Bookmark' in Show View locates General > Bookmarks and Go to jumps to line",
{
"matched_views": ["General > Bookmarks"],
"goto_target": ["src/com/example/PaymentClient.java", 88],
},
{
"matched_views": matched_views,
"goto_target": list(goto_cursor),
},
)
)
# Case 3: Remove Bookmark via ruler and Delete via Bookmarks view
# Remove via vertical ruler on line 42
bookmarks = [b for b in bookmarks if not (b["file"] == "src/com/example/OrderService.java" and b["line"] == 42)]
after_ruler_remove = len(bookmarks)
# Delete remaining entry from Bookmarks view
bookmarks = [b for b in bookmarks if b["id"] != 2]
after_view_delete = len(bookmarks)
cases.append(
check(
"remove_bookmark_ruler_and_view",
"Verify removing bookmarks via vertical ruler Remove Bookmark and Bookmarks view Delete stays synchronized",
{
"after_ruler_remove": 1,
"after_view_delete": 0,
},
{
"after_ruler_remove": after_ruler_remove,
"after_view_delete": after_view_delete,
},
)
)
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/eclipse-add-bookmarks-lab/explore-add-bookmarks.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-add-bookmarks.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联35章) · 含当前章节或实例 · mbskycom202612a2259.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2258.zip