| 217 | } |
| 218 | |
| 219 | ValidationSummary validateBook(const std::string& bookDir, GameState& gs, bool verbose) |
| 220 | { |
| 221 | ValidationSummary summary; |
| 222 | EvalState& state = static_cast<EvalState&>(gs); |
| 223 | auto files = listFiles(bookDir, ".md"); |
| 224 | |
| 225 | for (auto& file : files) |
| 226 | { |
| 227 | std::string content = readAll(file); |
| 228 | if (content.empty()) |
| 229 | continue; |
| 230 | |
| 231 | auto blocks = extractCodeBlocks(content); |
| 232 | // Extract just filename for display |
| 233 | std::string fname = file; |
| 234 | size_t sep = fname.find_last_of("/\\"); |
| 235 | if (sep != std::string::npos) |
| 236 | fname = fname.substr(sep + 1); |
| 237 | |
| 238 | for (int i = 0; i < (int)blocks.size(); i++) |
| 239 | { |
| 240 | std::string src = fname + ":" + std::to_string(blocks[i].lineNumber); |
| 241 | auto res = tryEval(src, i, blocks[i].code, blocks[i].lang, state); |
| 242 | |
| 243 | if (res.status == "pass") |
| 244 | summary.passed++; |
| 245 | else if (res.status == "fail") |
| 246 | summary.failed++; |
| 247 | else |
| 248 | summary.skipped++; |
| 249 | |
| 250 | if (verbose || res.status == "fail") |
| 251 | summary.results.push_back(res); |
| 252 | } |
| 253 | } |
| 254 | return summary; |
| 255 | } |
| 256 | |
| 257 | // Simple JSON string array extraction - handles nested brackets in strings |
| 258 | static std::string extractJsonStringArray(const std::string& json, const std::string& key) |