蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

离线校验 Dart SDK 安装命令、DartPad 特性、VS Code 运行方式与标准项目骨架

PYTHONWindows x64、CPython 3.12.14 离线 Dart 3.x 语义验证器(本机未安装原生 Dart SDK)。explore-install.py
explore-install.py145 行
"""Offline Dart 3.x semantic verification lab for Chapter 03 (install)."""
import json
import re
import shutil

VERSION = "CPython 3.12.14 offline Dart 3.x semantic verifier (dart SDK absent)"


def case_sdk_install_commands_and_probe():
    cmds = {
        "macos": ["brew tap dart-lang/dart", "brew install dart"],
        "windows": ["choco install dart-sdk"],
        "linux": ["sudo apt-get update", "sudo apt-get install dart"],
        "verify": ["dart --version", "dart --help"],
    }
    sample_out = "Dart SDK version: 3.5.0 (stable)"
    ver_match = re.search(r"Dart SDK version:\s*(\d+\.\d+\.\d+)\s*\((\w+)\)", sample_out)
    expected = {
        "local_dart_installed": False,
        "os_count": 3,
        "parsed_version": "3.5.0",
        "parsed_channel": "stable",
        "verify_commands": ["dart --version", "dart --help"],
    }
    actual = {
        "local_dart_installed": shutil.which("dart") is not None,
        "os_count": 3,
        "parsed_version": ver_match.group(1) if ver_match else "",
        "parsed_channel": ver_match.group(2) if ver_match else "",
        "verify_commands": cmds["verify"],
    }
    return {
        "name": "sdk_install_commands_and_probe",
        "summary": "探测本机 Dart SDK 缺席状态并校验 macOS/Windows/Linux 安装命令及版本输出解析",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_dartpad_capabilities():
    url = "https://dartpad.dev"
    features = ["零配置", "支持 Flutter", "代码分享", "语法高亮", "版本可选"]
    expected = {
        "url": "https://dartpad.dev",
        "https": True,
        "feature_count": 5,
        "supports_flutter": True,
    }
    actual = {
        "url": url,
        "https": url.startswith("https://"),
        "feature_count": len(features),
        "supports_flutter": "支持 Flutter" in features,
    }
    return {
        "name": "dartpad_capabilities",
        "summary": "校验 DartPad 在线编辑器入口地址与 5 项核心零配置特性",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_ide_and_vscode_run_modes():
    run_modes = {
        "右键菜单": "Run Without Debugging",
        "快捷键": "Ctrl+F5 / Cmd+F5",
        "终端命令": "dart run hello.dart",
    }
    ides = {
        "IntelliJ IDEA": "Dart 插件",
        "Android Studio": "内置支持",
        "VS Code": "Dart 扩展",
    }
    hello_src = "void main() {\n  print('Hello, Dart!');\n}\n"
    m = re.search(r"print\('([^']*)'\);", hello_src)
    expected = {
        "run_mode_count": 3,
        "cli_run_cmd": "dart run hello.dart",
        "ide_count": 3,
        "vscode_extension": "Dart 扩展",
        "hello_output": "Hello, Dart!",
    }
    actual = {
        "run_mode_count": len(run_modes),
        "cli_run_cmd": run_modes["终端命令"],
        "ide_count": len(ides),
        "vscode_extension": ides["VS Code"],
        "hello_output": m.group(1) if m else "",
    }
    return {
        "name": "ide_and_vscode_run_modes",
        "summary": "校验 VS Code Dart 扩展的三种运行方式、hello.dart 示例及三大 IDE 适配矩阵",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_dart_create_project_scaffold():
    project = "my_first_app"
    scaffold = {
        "bin/": f"bin/{project}.dart",
        "lib/": f"lib/{project}.dart",
        "test/": f"test/{project}_test.dart",
        "pubspec.yaml": "pubspec.yaml",
        "analysis_options.yaml": "analysis_options.yaml",
    }
    expected = {
        "create_cmd": "dart create my_first_app",
        "run_cmd": "dart run",
        "required_entries": 5,
        "entry_file": "bin/my_first_app.dart",
        "test_file": "test/my_first_app_test.dart",
    }
    actual = {
        "create_cmd": f"dart create {project}",
        "run_cmd": "dart run",
        "required_entries": len(scaffold),
        "entry_file": scaffold["bin/"],
        "test_file": scaffold["test/"],
    }
    return {
        "name": "dart_create_project_scaffold",
        "summary": "校验 dart create 生成的标准项目目录结构与 bin/lib/test/pubspec.yaml/analysis_options.yaml 职责",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_sdk_install_commands_and_probe(),
        case_dartpad_capabilities(),
        case_ide_and_vscode_run_modes(),
        case_dart_create_project_scaffold(),
    ]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14 离线 Dart 3.x 语义验证器(本机未安装原生 Dart SDK)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14 离线 Dart 3.x 语义验证器(本机未安装原生 Dart SDK)。

入口文件:projects/dart-install-lab/explore-install.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-install.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14 离线 Dart 3.x 语义验证器(本机未安装原生 Dart SDK)。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Dart

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2545.zip

下载课程关联工程包:Dart

课程关联工程包(登记关联21章) · 含当前章节或实例 · mbskycom202612a2534.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习