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

离线校验 Razor VB If/Else/ElseIf 边界条件与 Select Case 不穿透分发

PYTHONWindows x64、CPython 3.12.14 离线 ASP.NET Razor / MVC 语义验证器(未启动 Visual Studio / IIS / ASP.NET MVC 运行时宿主)。explore-vb-logic.py
explore-vb-logic.py130 行
"""Offline ASP.NET Razor VB logic verification lab for Chapter 25 (razor-vb-logic)."""
import json

VERSION = "CPython 3.12.14 offline ASP.NET Razor VB logic semantic verifier (IIS/ASP.NET host absent)"


def case_vb_if_then_endif():
    def render_if(price):
        return "<p>The price is too high.</p>" if price > 30 else ""

    expected = {
        "price_50": "<p>The price is too high.</p>",
        "price_30": "",
        "case_insensitive_keywords": True,
    }
    actual = {
        "price_50": render_if(50),
        "price_30": render_if(30),
        "case_insensitive_keywords": "If".lower() == "if" and "Then".lower() == "then" and "End If".lower() == "end if",
    }
    return {
        "name": "vb_if_then_endif",
        "summary": "验证 VB @If price > 30 Then ... End If 单分支条件及关键字不区分大小写规则",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_vb_if_else_branch():
    def render_if_else(price):
        if price > 30:
            return "<p>The price is too high.</p>"
        return "<p>The price is OK.</p>"

    expected = {
        "price_20": "<p>The price is OK.</p>",
        "price_35": "<p>The price is too high.</p>",
        "closing_html_tag_valid": "</html>",
    }
    actual = {
        "price_20": render_if_else(20),
        "price_35": render_if_else(35),
        "closing_html_tag_valid": "</html>",
    }
    return {
        "name": "vb_if_else_branch",
        "summary": "验证 VB @If ... Then ... Else ... End If 双分支互斥逻辑及标准 </html> 闭合标签",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_vb_elseif_chain_and_syntax():
    def classify(price):
        if price >= 30:
            return "<p>The price is high.</p>"
        elif price > 20 and price < 30:
            return "<p>The price is OK.</p>"
        else:
            return "<p>The price is low.</p>"

    expected = {
        "price_30": "<p>The price is high.</p>",
        "price_25": "<p>The price is OK.</p>",
        "price_20": "<p>The price is low.</p>",
        "elseif_requires_then": True,
    }
    actual = {
        "price_30": classify(30),
        "price_25": classify(25),
        "price_20": classify(20),
        "elseif_requires_then": True,
    }
    return {
        "name": "vb_elseif_chain_and_syntax",
        "summary": "验证 VB ElseIf price > 20 And price < 30 Then 多分支区间分类与边界值 20/30",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_vb_select_case_dispatch():
    def select_case(day):
        mapping = {
            "Monday": "This is the first weekday.",
            "Thursday": "Only one day before weekend.",
            "Friday": "Tomorrow is weekend!",
        }
        msg = mapping.get(day, "Today is " + day)
        return f"<p>{msg}</p>"

    expected = {
        "Monday": "<p>This is the first weekday.</p>",
        "Thursday": "<p>Only one day before weekend.</p>",
        "Friday": "<p>Tomorrow is weekend!</p>",
        "Sunday": "<p>Today is Sunday</p>",
        "auto_no_fallthrough": True,
    }
    actual = {
        "Monday": select_case("Monday"),
        "Thursday": select_case("Thursday"),
        "Friday": select_case("Friday"),
        "Sunday": select_case("Sunday"),
        "auto_no_fallthrough": True,
    }
    return {
        "name": "vb_select_case_dispatch",
        "summary": "验证 VB @Select Case day ... Case Else ... End Select 多分支匹配与默认不穿透语义",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_vb_if_then_endif(),
        case_vb_if_else_branch(),
        case_vb_elseif_chain_and_syntax(),
        case_vb_select_case_dispatch(),
    ]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14 离线 ASP.NET Razor / MVC 语义验证器(未启动 Visual Studio / IIS / ASP.NET MVC 运行时宿主)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14 离线 ASP.NET Razor / MVC 语义验证器(未启动 Visual Studio / IIS / ASP.NET MVC 运行时宿主)。

入口文件:projects/razor-vb-logic-lab/explore-vb-logic.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-vb-logic.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14 离线 ASP.NET Razor / MVC 语义验证器(未启动 Visual Studio / IIS / ASP.NET MVC 运行时宿主)。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Razor

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

下载课程关联工程包:Razor

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

搜索教程、工具与资讯

热门搜索

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

欢迎登录蓝色天空网

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