redscript-mc 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +31 -0
- package/.github/ISSUE_TEMPLATE/wrong_output.md +33 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +34 -0
- package/.github/workflows/ci.yml +29 -0
- package/.github/workflows/publish-extension.yml +35 -0
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/README.zh.md +261 -0
- package/dist/__tests__/cli.test.d.ts +1 -0
- package/dist/__tests__/cli.test.js +140 -0
- package/dist/__tests__/codegen.test.d.ts +1 -0
- package/dist/__tests__/codegen.test.js +121 -0
- package/dist/__tests__/diagnostics.test.d.ts +4 -0
- package/dist/__tests__/diagnostics.test.js +149 -0
- package/dist/__tests__/e2e.test.d.ts +6 -0
- package/dist/__tests__/e2e.test.js +1528 -0
- package/dist/__tests__/lexer.test.d.ts +1 -0
- package/dist/__tests__/lexer.test.js +316 -0
- package/dist/__tests__/lowering.test.d.ts +1 -0
- package/dist/__tests__/lowering.test.js +819 -0
- package/dist/__tests__/mc-integration.test.d.ts +12 -0
- package/dist/__tests__/mc-integration.test.js +395 -0
- package/dist/__tests__/mc-syntax.test.d.ts +1 -0
- package/dist/__tests__/mc-syntax.test.js +112 -0
- package/dist/__tests__/nbt.test.d.ts +1 -0
- package/dist/__tests__/nbt.test.js +82 -0
- package/dist/__tests__/optimizer-advanced.test.d.ts +1 -0
- package/dist/__tests__/optimizer-advanced.test.js +124 -0
- package/dist/__tests__/optimizer.test.d.ts +1 -0
- package/dist/__tests__/optimizer.test.js +118 -0
- package/dist/__tests__/parser.test.d.ts +1 -0
- package/dist/__tests__/parser.test.js +717 -0
- package/dist/__tests__/repl.test.d.ts +1 -0
- package/dist/__tests__/repl.test.js +27 -0
- package/dist/__tests__/runtime.test.d.ts +1 -0
- package/dist/__tests__/runtime.test.js +276 -0
- package/dist/__tests__/structure-optimizer.test.d.ts +1 -0
- package/dist/__tests__/structure-optimizer.test.js +33 -0
- package/dist/__tests__/typechecker.test.d.ts +1 -0
- package/dist/__tests__/typechecker.test.js +364 -0
- package/dist/ast/types.d.ts +357 -0
- package/dist/ast/types.js +9 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +407 -0
- package/dist/codegen/cmdblock/index.d.ts +26 -0
- package/dist/codegen/cmdblock/index.js +45 -0
- package/dist/codegen/mcfunction/index.d.ts +34 -0
- package/dist/codegen/mcfunction/index.js +413 -0
- package/dist/codegen/structure/index.d.ts +18 -0
- package/dist/codegen/structure/index.js +249 -0
- package/dist/compile.d.ts +30 -0
- package/dist/compile.js +152 -0
- package/dist/data/arena/function/__load.mcfunction +6 -0
- package/dist/data/arena/function/__tick.mcfunction +2 -0
- package/dist/data/arena/function/announce_leaders/else_1.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/then_0.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0.mcfunction +7 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders/foreach_1.mcfunction +6 -0
- package/dist/data/arena/function/announce_leaders/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders.mcfunction +6 -0
- package/dist/data/arena/function/arena_tick/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/arena_tick/then_0.mcfunction +4 -0
- package/dist/data/arena/function/arena_tick.mcfunction +11 -0
- package/dist/data/counter/function/__load.mcfunction +5 -0
- package/dist/data/counter/function/__tick.mcfunction +2 -0
- package/dist/data/counter/function/counter_tick/merge_2.mcfunction +1 -0
- package/dist/data/counter/function/counter_tick/then_0.mcfunction +3 -0
- package/dist/data/counter/function/counter_tick.mcfunction +11 -0
- package/dist/data/minecraft/tags/function/load.json +5 -0
- package/dist/data/minecraft/tags/function/tick.json +5 -0
- package/dist/data/quiz/function/__load.mcfunction +16 -0
- package/dist/data/quiz/function/__tick.mcfunction +6 -0
- package/dist/data/quiz/function/__trigger_quiz_a_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_b_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_c_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_start_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/answer_a.mcfunction +4 -0
- package/dist/data/quiz/function/answer_b.mcfunction +4 -0
- package/dist/data/quiz/function/answer_c.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_4.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_7.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/merge_2.mcfunction +1 -0
- package/dist/data/quiz/function/ask_question/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/then_0.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_3.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_6.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question.mcfunction +7 -0
- package/dist/data/quiz/function/finish_quiz.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/else_10.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_16.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_4.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_7.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/merge_11.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_14.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_17.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_2.mcfunction +8 -0
- package/dist/data/quiz/function/handle_answer/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/then_0.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_12.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_15.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_3.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_6.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_9.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer.mcfunction +11 -0
- package/dist/data/quiz/function/start_quiz.mcfunction +5 -0
- package/dist/data/shop/function/__load.mcfunction +7 -0
- package/dist/data/shop/function/__tick.mcfunction +3 -0
- package/dist/data/shop/function/__trigger_shop_buy_dispatch.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/else_1.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_4.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_7.mcfunction +3 -0
- package/dist/data/shop/function/complete_purchase/merge_2.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_5.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_8.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/then_0.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_3.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_6.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase.mcfunction +7 -0
- package/dist/data/shop/function/handle_shop_trigger.mcfunction +3 -0
- package/dist/data/turret/function/__load.mcfunction +5 -0
- package/dist/data/turret/function/__tick.mcfunction +4 -0
- package/dist/data/turret/function/__trigger_deploy_turret_dispatch.mcfunction +4 -0
- package/dist/data/turret/function/deploy_turret.mcfunction +8 -0
- package/dist/data/turret/function/turret_tick/at_1.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_0.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_2.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/tick_body.mcfunction +3 -0
- package/dist/data/turret/function/turret_tick/tick_skip.mcfunction +1 -0
- package/dist/data/turret/function/turret_tick.mcfunction +5 -0
- package/dist/diagnostics/index.d.ts +44 -0
- package/dist/diagnostics/index.js +140 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +126 -0
- package/dist/ir/builder.d.ts +32 -0
- package/dist/ir/builder.js +99 -0
- package/dist/ir/types.d.ts +117 -0
- package/dist/ir/types.js +15 -0
- package/dist/lexer/index.d.ts +36 -0
- package/dist/lexer/index.js +458 -0
- package/dist/lowering/index.d.ts +106 -0
- package/dist/lowering/index.js +2041 -0
- package/dist/mc-test/client.d.ts +128 -0
- package/dist/mc-test/client.js +174 -0
- package/dist/mc-test/runner.d.ts +28 -0
- package/dist/mc-test/runner.js +150 -0
- package/dist/mc-test/setup.d.ts +11 -0
- package/dist/mc-test/setup.js +98 -0
- package/dist/mc-validator/index.d.ts +17 -0
- package/dist/mc-validator/index.js +322 -0
- package/dist/nbt/index.d.ts +86 -0
- package/dist/nbt/index.js +250 -0
- package/dist/optimizer/commands.d.ts +36 -0
- package/dist/optimizer/commands.js +349 -0
- package/dist/optimizer/passes.d.ts +34 -0
- package/dist/optimizer/passes.js +227 -0
- package/dist/optimizer/structure.d.ts +8 -0
- package/dist/optimizer/structure.js +344 -0
- package/dist/pack.mcmeta +6 -0
- package/dist/parser/index.d.ts +76 -0
- package/dist/parser/index.js +1193 -0
- package/dist/repl.d.ts +16 -0
- package/dist/repl.js +165 -0
- package/dist/runtime/index.d.ts +101 -0
- package/dist/runtime/index.js +1288 -0
- package/dist/typechecker/index.d.ts +42 -0
- package/dist/typechecker/index.js +629 -0
- package/docs/COMPILATION_STATS.md +142 -0
- package/docs/IMPLEMENTATION_GUIDE.md +512 -0
- package/docs/LANGUAGE_REFERENCE.md +415 -0
- package/docs/MC_MAPPING.md +280 -0
- package/docs/STRUCTURE_TARGET.md +80 -0
- package/docs/mc-reference/commands.md +259 -0
- package/editors/vscode/.vscodeignore +10 -0
- package/editors/vscode/LICENSE +21 -0
- package/editors/vscode/README.md +78 -0
- package/editors/vscode/build.mjs +28 -0
- package/editors/vscode/icon.png +0 -0
- package/editors/vscode/mcfunction-language-configuration.json +28 -0
- package/editors/vscode/out/extension.js +7236 -0
- package/editors/vscode/package-lock.json +566 -0
- package/editors/vscode/package.json +137 -0
- package/editors/vscode/redscript-language-configuration.json +28 -0
- package/editors/vscode/snippets/redscript.json +114 -0
- package/editors/vscode/src/codeactions.ts +89 -0
- package/editors/vscode/src/completion.ts +130 -0
- package/editors/vscode/src/extension.ts +239 -0
- package/editors/vscode/src/hover.ts +1120 -0
- package/editors/vscode/src/symbols.ts +207 -0
- package/editors/vscode/syntaxes/mcfunction.tmLanguage.json +740 -0
- package/editors/vscode/syntaxes/redscript.tmLanguage.json +357 -0
- package/editors/vscode/tsconfig.json +13 -0
- package/jest.config.js +5 -0
- package/package.json +38 -0
- package/src/__tests__/cli.test.ts +130 -0
- package/src/__tests__/codegen.test.ts +128 -0
- package/src/__tests__/diagnostics.test.ts +195 -0
- package/src/__tests__/e2e.test.ts +1721 -0
- package/src/__tests__/fixtures/mc-commands-1.21.4.json +18734 -0
- package/src/__tests__/formatter.test.ts +46 -0
- package/src/__tests__/lexer.test.ts +356 -0
- package/src/__tests__/lowering.test.ts +962 -0
- package/src/__tests__/mc-integration.test.ts +409 -0
- package/src/__tests__/mc-syntax.test.ts +96 -0
- package/src/__tests__/nbt.test.ts +58 -0
- package/src/__tests__/optimizer-advanced.test.ts +144 -0
- package/src/__tests__/optimizer.test.ts +129 -0
- package/src/__tests__/parser.test.ts +800 -0
- package/src/__tests__/repl.test.ts +33 -0
- package/src/__tests__/runtime.test.ts +289 -0
- package/src/__tests__/structure-optimizer.test.ts +38 -0
- package/src/__tests__/typechecker.test.ts +395 -0
- package/src/ast/types.ts +248 -0
- package/src/cli.ts +445 -0
- package/src/codegen/cmdblock/index.ts +63 -0
- package/src/codegen/mcfunction/index.ts +471 -0
- package/src/codegen/structure/index.ts +305 -0
- package/src/compile.ts +188 -0
- package/src/diagnostics/index.ts +186 -0
- package/src/examples/README.md +77 -0
- package/src/examples/SHOWCASE_GAME.md +43 -0
- package/src/examples/arena.rs +44 -0
- package/src/examples/counter.rs +12 -0
- package/src/examples/pvp_arena.rs +131 -0
- package/src/examples/quiz.rs +90 -0
- package/src/examples/rpg.rs +13 -0
- package/src/examples/shop.rs +30 -0
- package/src/examples/showcase_game.rs +552 -0
- package/src/examples/stdlib_demo.rs +181 -0
- package/src/examples/turret.rs +27 -0
- package/src/examples/world_manager.rs +23 -0
- package/src/formatter/index.ts +22 -0
- package/src/index.ts +161 -0
- package/src/ir/builder.ts +114 -0
- package/src/ir/types.ts +119 -0
- package/src/lexer/index.ts +555 -0
- package/src/lowering/index.ts +2406 -0
- package/src/mc-test/client.ts +259 -0
- package/src/mc-test/runner.ts +140 -0
- package/src/mc-test/setup.ts +70 -0
- package/src/mc-validator/index.ts +367 -0
- package/src/nbt/index.ts +321 -0
- package/src/optimizer/commands.ts +416 -0
- package/src/optimizer/passes.ts +233 -0
- package/src/optimizer/structure.ts +441 -0
- package/src/parser/index.ts +1437 -0
- package/src/repl.ts +165 -0
- package/src/runtime/index.ts +1403 -0
- package/src/stdlib/README.md +156 -0
- package/src/stdlib/combat.rs +20 -0
- package/src/stdlib/cooldown.rs +45 -0
- package/src/stdlib/math.rs +49 -0
- package/src/stdlib/mobs.rs +99 -0
- package/src/stdlib/player.rs +29 -0
- package/src/stdlib/strings.rs +7 -0
- package/src/stdlib/timer.rs +51 -0
- package/src/templates/README.md +126 -0
- package/src/templates/combat.rs +96 -0
- package/src/templates/economy.rs +40 -0
- package/src/templates/mini-game-framework.rs +117 -0
- package/src/templates/quest.rs +78 -0
- package/src/test_programs/zombie_game.rs +25 -0
- package/src/typechecker/index.ts +737 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RedScript MC Integration Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests compiled datapacks against a real Paper 1.21.4 server.
|
|
5
|
+
*
|
|
6
|
+
* Prerequisites:
|
|
7
|
+
* - Paper server running with TestHarnessPlugin on port 25561
|
|
8
|
+
* - MC_SERVER_DIR env var pointing to server directory
|
|
9
|
+
*
|
|
10
|
+
* Run: MC_SERVER_DIR=~/mc-test-server npx jest mc-integration --testTimeout=120000
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* RedScript MC Integration Tests
|
|
4
|
+
*
|
|
5
|
+
* Tests compiled datapacks against a real Paper 1.21.4 server.
|
|
6
|
+
*
|
|
7
|
+
* Prerequisites:
|
|
8
|
+
* - Paper server running with TestHarnessPlugin on port 25561
|
|
9
|
+
* - MC_SERVER_DIR env var pointing to server directory
|
|
10
|
+
*
|
|
11
|
+
* Run: MC_SERVER_DIR=~/mc-test-server npx jest mc-integration --testTimeout=120000
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
const path = __importStar(require("path"));
|
|
49
|
+
const compile_1 = require("../compile");
|
|
50
|
+
const client_1 = require("../mc-test/client");
|
|
51
|
+
const MC_HOST = process.env.MC_HOST ?? 'localhost';
|
|
52
|
+
const MC_PORT = parseInt(process.env.MC_PORT ?? '25561');
|
|
53
|
+
const MC_SERVER_DIR = process.env.MC_SERVER_DIR ?? path.join(process.env.HOME, 'mc-test-server');
|
|
54
|
+
const DATAPACK_DIR = path.join(MC_SERVER_DIR, 'world', 'datapacks', 'redscript-test');
|
|
55
|
+
let serverOnline = false;
|
|
56
|
+
let mc;
|
|
57
|
+
/** Write compiled RedScript source into the shared test datapack directory.
|
|
58
|
+
* Merges minecraft tag files (tick.json / load.json) instead of overwriting. */
|
|
59
|
+
function writeFixture(source, namespace) {
|
|
60
|
+
fs.mkdirSync(DATAPACK_DIR, { recursive: true });
|
|
61
|
+
// Write pack.mcmeta once
|
|
62
|
+
if (!fs.existsSync(path.join(DATAPACK_DIR, 'pack.mcmeta'))) {
|
|
63
|
+
fs.writeFileSync(path.join(DATAPACK_DIR, 'pack.mcmeta'), JSON.stringify({
|
|
64
|
+
pack: { pack_format: 48, description: 'RedScript integration tests' }
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
const result = (0, compile_1.compile)(source, { namespace });
|
|
68
|
+
if (result.error)
|
|
69
|
+
throw new Error(`Compile error in ${namespace}: ${result.error}`);
|
|
70
|
+
for (const file of result.files ?? []) {
|
|
71
|
+
if (file.path === 'pack.mcmeta')
|
|
72
|
+
continue;
|
|
73
|
+
const filePath = path.join(DATAPACK_DIR, file.path);
|
|
74
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
75
|
+
// Merge minecraft tag files (tick.json, load.json) instead of overwriting
|
|
76
|
+
if (file.path.includes('data/minecraft/tags/') && fs.existsSync(filePath)) {
|
|
77
|
+
const existing = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
78
|
+
const incoming = JSON.parse(file.content);
|
|
79
|
+
const merged = { values: [...new Set([...(existing.values ?? []), ...(incoming.values ?? [])])] };
|
|
80
|
+
fs.writeFileSync(filePath, JSON.stringify(merged, null, 2));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
fs.writeFileSync(filePath, file.content);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
beforeAll(async () => {
|
|
88
|
+
mc = new client_1.MCTestClient(MC_HOST, MC_PORT);
|
|
89
|
+
serverOnline = await mc.isOnline();
|
|
90
|
+
if (!serverOnline) {
|
|
91
|
+
console.warn(`⚠ MC server not running at ${MC_HOST}:${MC_PORT} — skipping integration tests`);
|
|
92
|
+
console.warn(` Run: MC_SERVER_DIR=~/mc-test-server npx ts-node src/mc-test/setup.ts`);
|
|
93
|
+
console.warn(` Then restart the MC server and re-run tests.`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// ── Write fixtures + use safe reloadData (no /reload confirm) ───────
|
|
97
|
+
// counter.rs
|
|
98
|
+
if (fs.existsSync(path.join(__dirname, '../examples/counter.rs'))) {
|
|
99
|
+
writeFixture(fs.readFileSync(path.join(__dirname, '../examples/counter.rs'), 'utf-8'), 'counter');
|
|
100
|
+
}
|
|
101
|
+
if (fs.existsSync(path.join(__dirname, '../examples/world_manager.rs'))) {
|
|
102
|
+
writeFixture(fs.readFileSync(path.join(__dirname, '../examples/world_manager.rs'), 'utf-8'), 'world_manager');
|
|
103
|
+
}
|
|
104
|
+
writeFixture(`
|
|
105
|
+
@tick
|
|
106
|
+
fn on_tick() {
|
|
107
|
+
scoreboard_set("#tick_counter", "ticks", scoreboard_get("#tick_counter", "ticks") + 1);
|
|
108
|
+
}
|
|
109
|
+
`, 'tick_test');
|
|
110
|
+
writeFixture(`
|
|
111
|
+
fn check_score() {
|
|
112
|
+
let x: int = scoreboard_get("#check_x", "test_score");
|
|
113
|
+
if (x > 5) {
|
|
114
|
+
scoreboard_set("#check_x", "result", 1);
|
|
115
|
+
} else {
|
|
116
|
+
scoreboard_set("#check_x", "result", 0);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
`, 'inline_test');
|
|
120
|
+
// ── E2E scenario fixtures ────────────────────────────────────────────
|
|
121
|
+
// Scenario A: mini game loop (timer countdown + ended flag)
|
|
122
|
+
writeFixture(`
|
|
123
|
+
@tick
|
|
124
|
+
fn game_tick() {
|
|
125
|
+
let time: int = scoreboard_get("#game", "timer");
|
|
126
|
+
if (time > 0) {
|
|
127
|
+
scoreboard_set("#game", "timer", time - 1);
|
|
128
|
+
}
|
|
129
|
+
if (time == 1) {
|
|
130
|
+
scoreboard_set("#game", "ended", 1);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
fn start_game() {
|
|
134
|
+
scoreboard_set("#game", "timer", 5);
|
|
135
|
+
scoreboard_set("#game", "ended", 0);
|
|
136
|
+
}
|
|
137
|
+
`, 'game_loop');
|
|
138
|
+
// Scenario B: two functions, same temp var namespace — verify no collision
|
|
139
|
+
writeFixture(`
|
|
140
|
+
fn calc_sum() {
|
|
141
|
+
let a: int = scoreboard_get("#math", "val_a");
|
|
142
|
+
let b: int = scoreboard_get("#math", "val_b");
|
|
143
|
+
scoreboard_set("#math", "sum", a + b);
|
|
144
|
+
}
|
|
145
|
+
fn calc_product() {
|
|
146
|
+
let x: int = scoreboard_get("#math", "val_x");
|
|
147
|
+
let y: int = scoreboard_get("#math", "val_y");
|
|
148
|
+
scoreboard_set("#math", "product", x * y);
|
|
149
|
+
}
|
|
150
|
+
fn run_both() {
|
|
151
|
+
calc_sum();
|
|
152
|
+
calc_product();
|
|
153
|
+
}
|
|
154
|
+
`, 'math_test');
|
|
155
|
+
// Scenario C: 3-deep call chain, each step modifies shared state
|
|
156
|
+
writeFixture(`
|
|
157
|
+
fn step3() {
|
|
158
|
+
let v: int = scoreboard_get("#chain", "val");
|
|
159
|
+
scoreboard_set("#chain", "val", v * 2);
|
|
160
|
+
}
|
|
161
|
+
fn step2() {
|
|
162
|
+
let v: int = scoreboard_get("#chain", "val");
|
|
163
|
+
scoreboard_set("#chain", "val", v + 5);
|
|
164
|
+
step3();
|
|
165
|
+
}
|
|
166
|
+
fn step1() {
|
|
167
|
+
scoreboard_set("#chain", "val", 10);
|
|
168
|
+
step2();
|
|
169
|
+
}
|
|
170
|
+
`, 'call_chain');
|
|
171
|
+
// Scenario D: setblock batching optimizer — 4 adjacent setblocks → fill
|
|
172
|
+
writeFixture(`
|
|
173
|
+
fn build_row() {
|
|
174
|
+
setblock((0, 70, 0), "minecraft:stone");
|
|
175
|
+
setblock((1, 70, 0), "minecraft:stone");
|
|
176
|
+
setblock((2, 70, 0), "minecraft:stone");
|
|
177
|
+
setblock((3, 70, 0), "minecraft:stone");
|
|
178
|
+
}
|
|
179
|
+
`, 'fill_test');
|
|
180
|
+
// ── Full reset + safe data reload ────────────────────────────────────
|
|
181
|
+
await mc.fullReset();
|
|
182
|
+
// Pre-create scoreboards
|
|
183
|
+
for (const obj of ['ticks', 'seconds', 'test_score', 'result', 'calc', 'rs',
|
|
184
|
+
'timer', 'ended', 'val_a', 'val_b', 'sum', 'val_x', 'val_y', 'product', 'val']) {
|
|
185
|
+
await mc.command(`/scoreboard objectives add ${obj} dummy`).catch(() => { });
|
|
186
|
+
}
|
|
187
|
+
await mc.command('/scoreboard players set counter ticks 0');
|
|
188
|
+
await mc.command('/scoreboard players set #tick_counter ticks 0');
|
|
189
|
+
await mc.command('/scoreboard players set #check_x test_score 10');
|
|
190
|
+
await mc.command('/scoreboard players set #check_x result 99');
|
|
191
|
+
// Safe reload (Bukkit.reloadData — only datapacks, no plugin restart)
|
|
192
|
+
console.log(' Reloading datapacks (safe reloadData)...');
|
|
193
|
+
await mc.reload();
|
|
194
|
+
await new Promise(r => setTimeout(r, 5000)); // wall-clock wait for data reload
|
|
195
|
+
// Initialize __load functions
|
|
196
|
+
await mc.command('/function counter:__load').catch(() => { });
|
|
197
|
+
await mc.command('/function inline_test:__load').catch(() => { });
|
|
198
|
+
await mc.ticks(20);
|
|
199
|
+
console.log(' Setup complete.');
|
|
200
|
+
}, 60000);
|
|
201
|
+
describe('MC Integration Tests', () => {
|
|
202
|
+
// ─── Test 1: Server connectivity ─────────────────────────────────────
|
|
203
|
+
test('server is online and healthy', async () => {
|
|
204
|
+
if (!serverOnline)
|
|
205
|
+
return;
|
|
206
|
+
const status = await mc.status();
|
|
207
|
+
expect(status.online).toBe(true);
|
|
208
|
+
expect(status.tps_1m).toBeGreaterThan(10); // Allow recovery after reload
|
|
209
|
+
console.log(` Server: ${status.version}, TPS: ${status.tps_1m.toFixed(1)}`);
|
|
210
|
+
});
|
|
211
|
+
// ─── Test 2: Counter tick ─────────────────────────────────────────────
|
|
212
|
+
test('counter.rs: tick function increments scoreboard over time', async () => {
|
|
213
|
+
if (!serverOnline)
|
|
214
|
+
return;
|
|
215
|
+
await mc.ticks(40); // Wait 2s (counter was already init'd in beforeAll)
|
|
216
|
+
const count = await mc.scoreboard('counter', 'ticks');
|
|
217
|
+
expect(count).toBeGreaterThan(0);
|
|
218
|
+
console.log(` counter/ticks after setup+40 ticks: ${count}`);
|
|
219
|
+
});
|
|
220
|
+
// ─── Test 3: setblock ────────────────────────────────────────────────
|
|
221
|
+
test('world_manager.rs: setblock places correct block', async () => {
|
|
222
|
+
if (!serverOnline)
|
|
223
|
+
return;
|
|
224
|
+
// Clear just the lobby area, keep other state
|
|
225
|
+
await mc.fullReset({ x1: -10, y1: 60, z1: -10, x2: 15, y2: 80, z2: 15, resetScoreboards: false });
|
|
226
|
+
await mc.command('/function world_manager:__load');
|
|
227
|
+
await mc.command('/function world_manager:reset_lobby_platform');
|
|
228
|
+
await mc.ticks(10);
|
|
229
|
+
const block = await mc.block(4, 65, 4);
|
|
230
|
+
expect(block.type).toBe('minecraft:gold_block');
|
|
231
|
+
console.log(` Block at (4,65,4): ${block.type}`);
|
|
232
|
+
});
|
|
233
|
+
// ─── Test 4: fill ────────────────────────────────────────────────────
|
|
234
|
+
test('world_manager.rs: fill creates smooth_stone floor', async () => {
|
|
235
|
+
if (!serverOnline)
|
|
236
|
+
return;
|
|
237
|
+
// Runs after test 3, floor should still be there
|
|
238
|
+
const block = await mc.block(4, 64, 4);
|
|
239
|
+
expect(block.type).toBe('minecraft:smooth_stone');
|
|
240
|
+
console.log(` Floor at (4,64,4): ${block.type}`);
|
|
241
|
+
});
|
|
242
|
+
// ─── Test 5: Scoreboard arithmetic ───────────────────────────────────
|
|
243
|
+
test('scoreboard arithmetic works via commands', async () => {
|
|
244
|
+
if (!serverOnline)
|
|
245
|
+
return;
|
|
246
|
+
await mc.command('/scoreboard players set TestA calc 10');
|
|
247
|
+
await mc.command('/scoreboard players set TestB calc 25');
|
|
248
|
+
await mc.command('/scoreboard players operation TestA calc += TestB calc');
|
|
249
|
+
await mc.ticks(2);
|
|
250
|
+
const result = await mc.scoreboard('TestA', 'calc');
|
|
251
|
+
expect(result).toBe(35);
|
|
252
|
+
console.log(` 10 + 25 = ${result}`);
|
|
253
|
+
});
|
|
254
|
+
// ─── Test 6: Scoreboard proxy for announce ────────────────────────────
|
|
255
|
+
test('scoreboard proxy test (chat logging not supported for /say)', async () => {
|
|
256
|
+
if (!serverOnline)
|
|
257
|
+
return;
|
|
258
|
+
await mc.command('/scoreboard objectives add announce_test dummy');
|
|
259
|
+
await mc.command('/scoreboard players set announce_marker announce_test 42');
|
|
260
|
+
await mc.ticks(2);
|
|
261
|
+
const marker = await mc.scoreboard('announce_marker', 'announce_test');
|
|
262
|
+
expect(marker).toBe(42);
|
|
263
|
+
console.log(` Marker value: ${marker}`);
|
|
264
|
+
});
|
|
265
|
+
// ─── Test 7: if/else logic via inline script ──────────────────────────
|
|
266
|
+
test('inline rs: if/else (x=10 > 5) sets result=1', async () => {
|
|
267
|
+
if (!serverOnline)
|
|
268
|
+
return;
|
|
269
|
+
// #check_x test_score=10 was set in beforeAll, run check_score
|
|
270
|
+
await mc.command('/function inline_test:check_score');
|
|
271
|
+
await mc.ticks(5);
|
|
272
|
+
const result = await mc.scoreboard('#check_x', 'result');
|
|
273
|
+
expect(result).toBe(1);
|
|
274
|
+
console.log(` if (10 > 5) → result: ${result}`);
|
|
275
|
+
});
|
|
276
|
+
// ─── Test 8: Entity counting ──────────────────────────────────────────
|
|
277
|
+
test('entity query: armor_stands survive peaceful mode', async () => {
|
|
278
|
+
if (!serverOnline)
|
|
279
|
+
return;
|
|
280
|
+
await mc.fullReset({ clearArea: false, killEntities: true, resetScoreboards: false });
|
|
281
|
+
await mc.command('/summon minecraft:armor_stand 0 65 0');
|
|
282
|
+
await mc.command('/summon minecraft:armor_stand 2 65 0');
|
|
283
|
+
await mc.command('/summon minecraft:armor_stand 4 65 0');
|
|
284
|
+
await mc.ticks(5);
|
|
285
|
+
const stands = await mc.entities('@e[type=minecraft:armor_stand]');
|
|
286
|
+
expect(stands.length).toBe(3);
|
|
287
|
+
console.log(` Spawned 3 armor_stands, found: ${stands.length}`);
|
|
288
|
+
await mc.command('/kill @e[type=minecraft:armor_stand]');
|
|
289
|
+
});
|
|
290
|
+
// ─── Test 9: @tick dispatcher runs every tick ─────────────────────────
|
|
291
|
+
test('@tick: tick_test increments #tick_counter every tick', async () => {
|
|
292
|
+
if (!serverOnline)
|
|
293
|
+
return;
|
|
294
|
+
// Reset counter
|
|
295
|
+
await mc.command('/scoreboard players set #tick_counter ticks 0');
|
|
296
|
+
await mc.ticks(40); // 2s
|
|
297
|
+
const ticks = await mc.scoreboard('#tick_counter', 'ticks');
|
|
298
|
+
expect(ticks).toBeGreaterThanOrEqual(10); // At least 10 of 40 ticks fired
|
|
299
|
+
console.log(` #tick_counter after 40 ticks: ${ticks}`);
|
|
300
|
+
});
|
|
301
|
+
// ─── Test 10: fullReset clears blocks ─────────────────────────────────
|
|
302
|
+
test('fullReset clears previously placed blocks', async () => {
|
|
303
|
+
if (!serverOnline)
|
|
304
|
+
return;
|
|
305
|
+
await mc.command('/setblock 5 65 5 minecraft:diamond_block');
|
|
306
|
+
await mc.ticks(2);
|
|
307
|
+
let block = await mc.block(5, 65, 5);
|
|
308
|
+
expect(block.type).toBe('minecraft:diamond_block');
|
|
309
|
+
await mc.fullReset({ x1: 0, y1: 60, z1: 0, x2: 10, y2: 75, z2: 10, resetScoreboards: false });
|
|
310
|
+
block = await mc.block(5, 65, 5);
|
|
311
|
+
expect(block.type).toBe('minecraft:air');
|
|
312
|
+
console.log(` Block after reset: ${block.type} ✓`);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
// ─── E2E Scenario Tests ───────────────────────────────────────────────────────
|
|
316
|
+
describe('E2E Scenario Tests', () => {
|
|
317
|
+
// Scenario A: Mini game loop
|
|
318
|
+
// Verifies: @tick auto-runs, scoreboard read-modify-write, two if conditions
|
|
319
|
+
// in the same function, timer countdown converges to ended=1
|
|
320
|
+
test('A: game_loop timer countdown sets ended=1 after N ticks', async () => {
|
|
321
|
+
if (!serverOnline)
|
|
322
|
+
return;
|
|
323
|
+
// game_tick is @tick - it runs every server tick automatically.
|
|
324
|
+
// start_game sets timer=5, but game_tick may already decrement it by the
|
|
325
|
+
// time we query. Use a large timer and just verify it reaches 0 eventually.
|
|
326
|
+
await mc.command('/scoreboard players set #game timer 0');
|
|
327
|
+
await mc.command('/scoreboard players set #game ended 0');
|
|
328
|
+
await mc.ticks(2);
|
|
329
|
+
await mc.command('/function game_loop:__load');
|
|
330
|
+
await mc.command('/function game_loop:start_game'); // timer=5, ended=0
|
|
331
|
+
// Wait 25 ticks — enough for 5 decrements + margin
|
|
332
|
+
await mc.ticks(25);
|
|
333
|
+
const ended = await mc.scoreboard('#game', 'ended');
|
|
334
|
+
expect(ended).toBe(1);
|
|
335
|
+
const finalTimer = await mc.scoreboard('#game', 'timer');
|
|
336
|
+
expect(finalTimer).toBe(0);
|
|
337
|
+
console.log(` timer hit 0 (final=${finalTimer}), ended=${ended} ✓`);
|
|
338
|
+
});
|
|
339
|
+
// Scenario B: No temp var collision between two functions called in sequence
|
|
340
|
+
// Verifies: each function's $t0/$t1 temp vars are isolated per-call, not globally shared
|
|
341
|
+
// If there's a bug, calc_product would see sum's leftover $t vars and produce wrong result
|
|
342
|
+
test('B: calc_sum + calc_product called in sequence — no temp var collision', async () => {
|
|
343
|
+
if (!serverOnline)
|
|
344
|
+
return;
|
|
345
|
+
await mc.command('/function math_test:__load');
|
|
346
|
+
await mc.command('/scoreboard players set #math val_a 7');
|
|
347
|
+
await mc.command('/scoreboard players set #math val_b 3');
|
|
348
|
+
await mc.command('/scoreboard players set #math val_x 4');
|
|
349
|
+
await mc.command('/scoreboard players set #math val_y 5');
|
|
350
|
+
await mc.command('/function math_test:run_both'); // calc_sum() then calc_product()
|
|
351
|
+
await mc.ticks(5);
|
|
352
|
+
const sum = await mc.scoreboard('#math', 'sum');
|
|
353
|
+
const product = await mc.scoreboard('#math', 'product');
|
|
354
|
+
expect(sum).toBe(10); // 7 + 3
|
|
355
|
+
expect(product).toBe(20); // 4 × 5
|
|
356
|
+
console.log(` sum=${sum} (expect 10), product=${product} (expect 20) ✓`);
|
|
357
|
+
});
|
|
358
|
+
// Scenario C: 3-deep call chain, shared state threaded through
|
|
359
|
+
// Verifies: function calls preserve scoreboard state across stack frames
|
|
360
|
+
// step1: val=10 → step2: val=10+5=15 → step3: val=15×2=30
|
|
361
|
+
test('C: 3-deep call chain preserves intermediate state (10→15→30)', async () => {
|
|
362
|
+
if (!serverOnline)
|
|
363
|
+
return;
|
|
364
|
+
await mc.command('/function call_chain:__load');
|
|
365
|
+
await mc.command('/scoreboard players set #chain val 0');
|
|
366
|
+
await mc.command('/function call_chain:step1');
|
|
367
|
+
await mc.ticks(5);
|
|
368
|
+
const val = await mc.scoreboard('#chain', 'val');
|
|
369
|
+
expect(val).toBe(30); // (10 + 5) * 2 = 30
|
|
370
|
+
console.log(` call chain result: ${val} (expect 30) ✓`);
|
|
371
|
+
});
|
|
372
|
+
// Scenario D: Setblock batching optimizer — 4 adjacent setblocks compiled to fill
|
|
373
|
+
// Verifies: optimizer's fill-batching pass produces correct MC behavior
|
|
374
|
+
// (not just that the output says "fill", but that ALL 4 blocks are actually stone)
|
|
375
|
+
test('D: fill optimizer — 4 adjacent setblocks all placed correctly', async () => {
|
|
376
|
+
if (!serverOnline)
|
|
377
|
+
return;
|
|
378
|
+
await mc.fullReset({ x1: -5, y1: 65, z1: -5, x2: 10, y2: 75, z2: 10, resetScoreboards: false });
|
|
379
|
+
await mc.command('/function fill_test:__load');
|
|
380
|
+
await mc.command('/function fill_test:build_row');
|
|
381
|
+
await mc.ticks(5);
|
|
382
|
+
// All 4 blocks should be stone (optimizer batched into fill 0 70 0 3 70 0 stone)
|
|
383
|
+
for (let x = 0; x <= 3; x++) {
|
|
384
|
+
const block = await mc.block(x, 70, 0);
|
|
385
|
+
expect(block.type).toBe('minecraft:stone');
|
|
386
|
+
}
|
|
387
|
+
// Neighbors should still be air (fill didn't overshoot)
|
|
388
|
+
const before = await mc.block(-1, 70, 0);
|
|
389
|
+
const after = await mc.block(4, 70, 0);
|
|
390
|
+
expect(before.type).toBe('minecraft:air');
|
|
391
|
+
expect(after.type).toBe('minecraft:air');
|
|
392
|
+
console.log(` fill_test: blocks [0-3,70,0]=stone, [-1]/[4]=air ✓`);
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
//# sourceMappingURL=mc-integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const compile_1 = require("../compile");
|
|
39
|
+
const mc_validator_1 = require("../mc-validator");
|
|
40
|
+
const FIXTURE_PATH = path.join(__dirname, 'fixtures', 'mc-commands-1.21.4.json');
|
|
41
|
+
const EXAMPLES = ['counter', 'arena', 'shop', 'quiz', 'turret'];
|
|
42
|
+
function getCommands(source, namespace = 'test') {
|
|
43
|
+
const result = (0, compile_1.compile)(source, { namespace });
|
|
44
|
+
expect(result.success).toBe(true);
|
|
45
|
+
expect(result.files).toBeDefined();
|
|
46
|
+
return (result.files ?? [])
|
|
47
|
+
.filter(file => file.path.endsWith('.mcfunction'))
|
|
48
|
+
.flatMap(file => file.content.split('\n'))
|
|
49
|
+
.filter(line => line.trim().length > 0);
|
|
50
|
+
}
|
|
51
|
+
function validateSource(validator, source, namespace) {
|
|
52
|
+
return getCommands(source, namespace)
|
|
53
|
+
.map(cmd => ({ cmd, result: validator.validate(cmd) }))
|
|
54
|
+
.filter(entry => !entry.result.valid)
|
|
55
|
+
.map(entry => ({ cmd: entry.cmd, error: entry.result.error }));
|
|
56
|
+
}
|
|
57
|
+
describe('MC Command Syntax Validation', () => {
|
|
58
|
+
const validator = new mc_validator_1.MCCommandValidator(FIXTURE_PATH);
|
|
59
|
+
test('counter example generates valid MC commands', () => {
|
|
60
|
+
const src = fs.readFileSync(path.join(__dirname, '..', 'examples', 'counter.rs'), 'utf-8');
|
|
61
|
+
const errors = validateSource(validator, src, 'counter');
|
|
62
|
+
expect(errors).toHaveLength(0);
|
|
63
|
+
});
|
|
64
|
+
EXAMPLES.forEach(name => {
|
|
65
|
+
test(`${name}.rs generates valid MC commands`, () => {
|
|
66
|
+
const src = fs.readFileSync(path.join(__dirname, '..', 'examples', `${name}.rs`), 'utf-8');
|
|
67
|
+
const errors = validateSource(validator, src, name);
|
|
68
|
+
if (errors.length > 0) {
|
|
69
|
+
console.log('Invalid commands:', errors);
|
|
70
|
+
}
|
|
71
|
+
expect(errors).toHaveLength(0);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
test('string interpolation generates valid tellraw', () => {
|
|
75
|
+
const errors = validateSource(validator, `
|
|
76
|
+
fn chat() {
|
|
77
|
+
let score: int = 7;
|
|
78
|
+
say("You have \${score} points");
|
|
79
|
+
}
|
|
80
|
+
`, 'interpolation');
|
|
81
|
+
expect(errors).toHaveLength(0);
|
|
82
|
+
});
|
|
83
|
+
test('array operations generate valid data commands', () => {
|
|
84
|
+
const errors = validateSource(validator, `
|
|
85
|
+
fn arrays() {
|
|
86
|
+
let arr: int[] = [];
|
|
87
|
+
arr.push(4);
|
|
88
|
+
arr.push(9);
|
|
89
|
+
let popped: int = arr.pop();
|
|
90
|
+
let len: int = arr.len;
|
|
91
|
+
|
|
92
|
+
scoreboard_set("arrays", "len", len);
|
|
93
|
+
scoreboard_set("arrays", "last", popped);
|
|
94
|
+
}
|
|
95
|
+
`, 'arrays');
|
|
96
|
+
expect(errors).toHaveLength(0);
|
|
97
|
+
});
|
|
98
|
+
test('match generates valid execute commands', () => {
|
|
99
|
+
const errors = validateSource(validator, `
|
|
100
|
+
fn choose() {
|
|
101
|
+
let choice: int = 2;
|
|
102
|
+
match (choice) {
|
|
103
|
+
1 => { say("one"); }
|
|
104
|
+
2 => { say("two"); }
|
|
105
|
+
_ => { say("other"); }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
`, 'matching');
|
|
109
|
+
expect(errors).toHaveLength(0);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=mc-syntax.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const structure_1 = require("../codegen/structure");
|
|
38
|
+
const nbt_1 = require("../nbt");
|
|
39
|
+
describe('NBT codec', () => {
|
|
40
|
+
test('round-trips a compound tag', () => {
|
|
41
|
+
const tag = nbt_1.nbt.compound({ x: nbt_1.nbt.int(42), name: nbt_1.nbt.string('test') });
|
|
42
|
+
const buf = (0, nbt_1.writeNbt)(tag, 'root');
|
|
43
|
+
const parsed = (0, nbt_1.readNbt)(buf);
|
|
44
|
+
expect(parsed.name).toBe('root');
|
|
45
|
+
expect(parsed.tag).toEqual(tag);
|
|
46
|
+
});
|
|
47
|
+
test('round-trips nested lists and arrays', () => {
|
|
48
|
+
const tag = nbt_1.nbt.compound({
|
|
49
|
+
nested: nbt_1.nbt.list(10 /* TagType.Compound */, [
|
|
50
|
+
nbt_1.nbt.compound({ values: nbt_1.nbt.intArray([1, 2, 3]) }),
|
|
51
|
+
nbt_1.nbt.compound({ bytes: nbt_1.nbt.byteArray([-1, 0, 1]) }),
|
|
52
|
+
]),
|
|
53
|
+
longs: { type: 12 /* TagType.LongArray */, value: BigInt64Array.from([1n, 2n, 3n]) },
|
|
54
|
+
});
|
|
55
|
+
const buf = (0, nbt_1.writeNbt)(tag, 'root');
|
|
56
|
+
const parsed = (0, nbt_1.readNbt)(buf);
|
|
57
|
+
expect(parsed.tag).toEqual(tag);
|
|
58
|
+
});
|
|
59
|
+
test('handles longs correctly', () => {
|
|
60
|
+
const tag = nbt_1.nbt.compound({ ts: nbt_1.nbt.long(9007199254740993n) });
|
|
61
|
+
const buf = (0, nbt_1.writeNbt)(tag, '');
|
|
62
|
+
const parsed = (0, nbt_1.readNbt)(buf);
|
|
63
|
+
const root = parsed.tag;
|
|
64
|
+
expect(root.entries.get('ts')).toEqual(nbt_1.nbt.long(9007199254740993n));
|
|
65
|
+
expect(root.entries.get('ts').value).toBe(9007199254740993n);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('Structure generator', () => {
|
|
69
|
+
test('compiles counter.rs to a non-empty structure', () => {
|
|
70
|
+
const filePath = 'src/examples/counter.rs';
|
|
71
|
+
const src = fs.readFileSync(filePath, 'utf-8');
|
|
72
|
+
const { buffer, blockCount } = (0, structure_1.compileToStructure)(src, 'counter', filePath);
|
|
73
|
+
expect(buffer.length).toBeGreaterThan(100);
|
|
74
|
+
expect(blockCount).toBeGreaterThan(0);
|
|
75
|
+
const parsed = (0, nbt_1.readNbt)(buffer);
|
|
76
|
+
const root = parsed.tag;
|
|
77
|
+
const blocks = root.entries.get('blocks');
|
|
78
|
+
expect(parsed.name).toBe('');
|
|
79
|
+
expect(blocks?.type).toBe(9 /* TagType.List */);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=nbt.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|