Files
foundryvtt-reve-de-dragon/tests/scripts/tc-10-des-custom.sh
T

95 lines
4.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# ============================================================================
# TC-10 — Dés Custom
# Usage: ./tc-10-des-custom.sh [--navigate]
# ============================================================================
set -uo pipefail
source "$(dirname "$0")/tc-header.sh"
echo ""
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ TC-10 — Dés Custom ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
tc_ensure_ready
# ============================================================================
echo "--- TC-10-001: Dé TMR (d8) ---"
# ============================================================================
R=$(jse_get_async "
try {
const dice = game.system.rdd.Dice;
if (!dice) return {error: 'no Dice'};
const roll = await dice.roll('1dt');
const total = roll.total;
const valid = total >= 1 && total <= 8;
return { total, valid, formula: roll.formula };
} catch(e) { return {error: e?.message || String(e)}; }
")
TOTAL=$(eval_ok "$R" total)
VALID=$(eval_ok "$R" valid)
ERR=$(eval_ok "$R" error)
[ "$VALID" = "True" ] && pass "TC-10-001: dé TMR = $TOTAL (1-8)" || fail "TC-10-001: KO ($ERR)"
# ============================================================================
echo "--- TC-10-002: Dé Draconique (d8 explosif) ---"
# ============================================================================
R=$(jse_get_async "
try {
const dice = game.system.rdd.Dice;
const roll = await dice.roll('1dd');
const total = roll.total;
// draconic die can explode on 7, total can be 0 on failure
const valid = total >= 0;
return { total, valid, formula: roll.formula };
} catch(e) { return {error: e?.message || String(e)}; }
")
TOTAL=$(eval_ok "$R" total)
VALID=$(eval_ok "$R" valid)
ERR=$(eval_ok "$R" error)
[ "$VALID" = "True" ] && pass "TC-10-002: dé draconique = $TOTAL" || fail "TC-10-002: KO ($ERR)"
# ============================================================================
echo "--- TC-10-003: Dé Heure (d12) ---"
# ============================================================================
R=$(jse_get_async "
try {
const dice = game.system.rdd.Dice;
if (typeof dice.rollHeure !== 'function') return {error: 'no rollHeure'};
const result = await dice.rollHeure();
// rollHeure returns a Number directly, not a Roll object
const total = typeof result === 'number' ? result : result?.total;
const valid = total >= 0 && total <= 11;
return { total, valid, type: typeof result };
} catch(e) { return {error: e?.message || String(e)}; }
")
TOTAL=$(eval_ok "$R" total)
VALID=$(eval_ok "$R" valid)
ERR=$(eval_ok "$R" error)
[ "$VALID" = "True" ] && pass "TC-10-003: dé heure = $TOTAL (0-11)" || fail "TC-10-003: KO ($ERR)"
# ============================================================================
echo "--- TC-10-005: Résolution d100 ---"
# ============================================================================
R=$(jse_get_async "
try {
const { RdDResolutionTable } = await import('/systems/foundryvtt-reve-de-dragon/module/rdd-resolution-table.js');
const result = await RdDResolutionTable.rollData({carac: 12, level: 0, forceDiceResult: 50});
const code = result?.rolled?.code;
const isSuccess = result?.rolled?.isSuccess;
return { code, isSuccess, hasRolled: !!result?.rolled };
} catch(e) { return {error: e?.message || String(e)}; }
")
CODE=$(eval_ok "$R" code)
HASROLLED=$(eval_ok "$R" hasRolled)
ERR=$(eval_ok "$R" error)
[ "$HASROLLED" = "True" ] && pass "TC-10-005: résolution d100 code=$CODE" || fail "TC-10-005: KO ($ERR)"
# ============================================================================
echo ""
echo "--- Console errors ---"
ERRS=$(tc_console_errors)
[ "$ERRS" -le 5 ] 2>/dev/null && pass "Console errors ≤5 ($ERRS)" || fail "Console errors: $ERRS"
tc_summary