bc-minecraft-bedrock-project
Version:
The typescript library responsible for reading/parsing minecraft bedrock data
57 lines • 2.93 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const bc_minecraft_bedrock_command_1 = require("bc-minecraft-bedrock-command");
const custom_command_1 = require("./custom-command");
const process_1 = require("./process");
describe('Behavior Pack/Script custom command processing', () => {
it('parses inline command registration with parameter lists', () => {
const commands = (0, process_1.process)({
uri: 'c:\\bp\\scripts\\custom.js',
getText: () => `
CustomCommandRegistry.registerCommand({
name: "example:hello",
description: "Says hello",
permission: CommandPermissionLevel.Admin,
mandatoryParameters: [
{ name: "target", type: CustomArgumentType.EntitySelector }
],
optionalParameters: [
{ name: "count", type: CustomArgumentType.Integer }
]
}, () => {});
`,
});
const container = (0, custom_command_1.toCommandContainer)({ forEach: (callbackfn) => commands.forEach(callbackfn) });
expect((0, bc_minecraft_bedrock_command_1.hasCommandData)('example:hello', false, container)).toBeTruthy();
const command = commands[0].syntaxes[0];
expect(command.source?.uri).toEqual('c:\\bp\\scripts\\custom.js');
expect(command.parameters).toEqual([
{ text: 'example:hello', type: bc_minecraft_bedrock_command_1.ParameterType.keyword, required: true },
{ text: 'target', type: bc_minecraft_bedrock_command_1.ParameterType.selector, required: true },
{ text: 'count', type: bc_minecraft_bedrock_command_1.ParameterType.integer, required: false },
]);
});
it('resolves variable-based registration and replaces commands by file', () => {
const first = (0, process_1.process)({
uri: 'c:\\bp\\scripts\\custom.ts',
getText: () => `
const definition = {
name: "example:bye",
description: "Says bye",
parameters: [{ name: "msg", type: CustomArgumentType.String }]
};
CustomCommandRegistry.registerCommand(definition, () => {});
`,
});
const firstContainer = (0, custom_command_1.toCommandContainer)({ forEach: (callbackfn) => first.forEach(callbackfn) });
expect((0, bc_minecraft_bedrock_command_1.hasCommandData)('example:bye', false, firstContainer)).toBeTruthy();
const second = (0, process_1.process)({
uri: 'c:\\bp\\scripts\\custom.ts',
getText: () => `CustomCommandRegistry.registerCommand({ name: "example:new" }, () => {});`,
});
const secondContainer = (0, custom_command_1.toCommandContainer)({ forEach: (callbackfn) => second.forEach(callbackfn) });
expect((0, bc_minecraft_bedrock_command_1.hasCommandData)('example:bye', false, secondContainer)).toBeFalsy();
expect((0, bc_minecraft_bedrock_command_1.hasCommandData)('example:new', false, secondContainer)).toBeTruthy();
});
});
//# sourceMappingURL=process.test.js.map