การเรนเดอร์th-TH

ยืนยัน

Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.

Asserts that a condition is true at runtime.

Aliases: assert

Syntax: ยืนยัน <expression> [ตาย <expression>]

Category#

testing

Examples#

radix/corpus/adfirma/adfirma.fab (canonical · keyword)#

Asserts that a condition is true at runtime.

test "assertions validate invariants" {
    const int x ← 10
    assert x ≻ 0
    assert x ≡ 10 panic "x decem esse debet"
    const string ชื่อ ← "Marcus"
    assert ชื่อ ≡ "Marcus"
    assert ชื่อ ≠ "" panic "nomen vacuum non sit"
    const bool viget ← true
    assert viget
    assert viget ≡ true panic "vigere debet"
}

# =============================================================================
# ยืนยัน — Asserts that a condition is true at runtime.
# =============================================================================
#
# What this teaches:
#   • Runtime assertions — `ยืนยัน <condition>` validates invariants during
#     program execution
#   • Custom messages — `ยืนยัน <condition> ตาย "message"` adds descriptive
#     diagnostic text on failure
#   • Testing category — ยืนยัน is the primary assertion keyword for test
#     and verification code
#
# Common mistakes:
#   • using `ยืนยัน` outside `ทดสอบ` or `ทดสอบชุด` (WARN006); use `ตาย` for invariant violations in production code or move assertions into test blocks
#
# See also: ทดสอบ, ทำ, จับ
# =============================================================================

# ยืนยัน — runtime assertions
#
# ยืนยัน <condition>
# ยืนยัน <condition> ตาย "nuntius"
#
# GRAMMAR:
#   adfirmaStmt :← 'ยืนยัน' expr ('ตาย' expr)?
#
# EXPECTED OUTPUT:
#   empty — ยืนยัน only (adfirma.expected)

main {
    const int x ← 10

    # Simple assertion without message
    assert x ≻ 0

    # Assertion with custom message
    assert x ≡ 10 panic "x decem esse debet"

    # Multiple assertions
    const string ชื่อ ← "Marcus"
    assert ชื่อ ≡ "Marcus"
    assert ชื่อ ≠ "" panic "nomen vacuum non sit"

    # Boolean assertions
    const bool viget ← true
    assert viget
    assert viget ≡ true panic "vigere debet"
}