bitburner-src/test/jest/Terminal/determineAllPossibilitiesForTabCompletion.test.ts

156 lines
6.5 KiB
TypeScript
Raw Normal View History

import { CityName } from './../../../src/Locations/data/CityNames';
/* eslint-disable no-await-in-loop */
2021-12-19 21:42:40 +01:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2022-01-05 01:09:34 +01:00
import { jest, describe, expect, test } from "@jest/globals";
2021-12-19 21:42:40 +01:00
import { Player } from "../../../src/Player";
import { determineAllPossibilitiesForTabCompletion } from "../../../src/Terminal/determineAllPossibilitiesForTabCompletion";
import { Server } from "../../../src/Server/Server";
import { AddToAllServers, prestigeAllServers } from "../../../src/Server/AllServers";
import { LocationName } from "../../../src/Locations/data/LocationNames";
import { CodingContract } from "../../../src/CodingContracts";
2021-08-27 05:22:24 +02:00
2022-01-05 01:09:34 +01:00
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
virtual: true,
});
2021-08-27 05:22:24 +02:00
describe("determineAllPossibilitiesForTabCompletion", function () {
2021-09-05 01:09:30 +02:00
let closeServer: Server;
let farServer: Server;
beforeEach(() => {
prestigeAllServers();
Player.init();
closeServer = new Server({
ip: "8.8.8.8",
hostname: "near",
hackDifficulty: 1,
moneyAvailable: 70000,
numOpenPortsRequired: 0,
organizationName: LocationName.NewTokyoNoodleBar,
requiredHackingSkill: 1,
serverGrowth: 3000,
2021-08-27 05:22:24 +02:00
});
2021-09-05 01:09:30 +02:00
farServer = new Server({
ip: "4.4.4.4",
hostname: "far",
hackDifficulty: 1,
moneyAvailable: 70000,
numOpenPortsRequired: 0,
organizationName: CityName.Aevum,
2021-09-05 01:09:30 +02:00
requiredHackingSkill: 1,
serverGrowth: 3000,
2021-08-27 05:22:24 +02:00
});
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().serversOnNetwork.push(closeServer.ip);
closeServer.serversOnNetwork.push(Player.getHomeComputer().ip);
closeServer.serversOnNetwork.push(farServer.ip);
farServer.serversOnNetwork.push(closeServer.ip);
AddToAllServers(closeServer);
AddToAllServers(farServer);
});
it("completes the connect command", async () => {
const options = await determineAllPossibilitiesForTabCompletion(Player, "connect ", 0);
expect(options).toEqual(["near"]);
2021-09-05 01:09:30 +02:00
});
it("completes the buy command", async () => {
const options = await determineAllPossibilitiesForTabCompletion(Player, "buy ", 0);
2022-01-05 01:09:34 +01:00
expect(options.sort()).toEqual(
[
"BruteSSH.exe",
"FTPCrack.exe",
"relaySMTP.exe",
"HTTPWorm.exe",
"SQLInject.exe",
"DeepscanV1.exe",
"DeepscanV2.exe",
"AutoLink.exe",
"ServerProfiler.exe",
"Formulas.exe",
].sort(),
);
2021-09-05 01:09:30 +02:00
});
it("completes the scp command", async () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
Player.getHomeComputer().messages.push("af.lit");
2022-01-05 01:09:34 +01:00
Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark");
const options1 = await determineAllPossibilitiesForTabCompletion(Player, "scp ", 0);
expect(options1).toEqual(["/www/script.js", "af.lit", "note.txt", "www/"]);
2021-09-05 01:09:30 +02:00
const options2 = await determineAllPossibilitiesForTabCompletion(Player, "scp note.txt ", 1);
expect(options2).toEqual(["home", "near", "far"]);
2021-09-05 01:09:30 +02:00
});
it("completes the kill, tail, mem, and check commands", async () => {
2022-01-05 01:09:34 +01:00
Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark");
2021-09-05 01:09:30 +02:00
for (const command of ["kill", "tail", "mem", "check"]) {
const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0);
expect(options).toEqual(["/www/script.js", "www/"]);
2021-09-05 01:09:30 +02:00
}
});
it("completes the nano commands", async () => {
2022-01-05 01:09:34 +01:00
Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark");
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
const options = await determineAllPossibilitiesForTabCompletion(Player, "nano ", 0);
2022-01-05 01:09:34 +01:00
expect(options).toEqual(["/www/script.js", "note.txt", "www/"]);
2021-09-05 01:09:30 +02:00
});
it("completes the rm command", async () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
2022-01-05 01:09:34 +01:00
Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark");
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
2021-10-14 08:07:05 +02:00
Player.getHomeComputer().messages.push("asl.msg");
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().messages.push("af.lit");
const options = await determineAllPossibilitiesForTabCompletion(Player, "rm ", 0);
2022-01-05 01:09:34 +01:00
expect(options).toEqual(["/www/script.js", "NUKE.exe", "af.lit", "note.txt", "linklist.cct", "www/"]);
2021-09-05 01:09:30 +02:00
});
it("completes the run command", async () => {
2022-01-05 01:09:34 +01:00
Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark");
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
const options = await determineAllPossibilitiesForTabCompletion(Player, "run ", 0);
2022-01-05 01:09:34 +01:00
expect(options).toEqual(["/www/script.js", "NUKE.exe", "linklist.cct", "www/"]);
2021-09-05 01:09:30 +02:00
});
it("completes the cat command", async () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToTextFile("/www/note.txt", "oh hai mark");
2021-10-14 08:07:05 +02:00
Player.getHomeComputer().messages.push("asl.msg");
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().messages.push("af.lit");
const options = await determineAllPossibilitiesForTabCompletion(Player, "cat ", 0);
2022-01-05 01:09:34 +01:00
expect(options).toEqual(["asl.msg", "af.lit", "/www/note.txt", "www/"]);
2021-09-05 01:09:30 +02:00
});
it("completes the download and mv commands", async () => {
2022-01-05 01:09:34 +01:00
Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark");
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
for (const command of ["download", "mv"]) {
const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0);
2022-01-05 01:09:34 +01:00
expect(options).toEqual(["/www/script.js", "note.txt", "www/"]);
2021-09-05 01:09:30 +02:00
}
});
it("completes the cd command", async () => {
2022-01-05 01:09:34 +01:00
Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark");
const options = await determineAllPossibilitiesForTabCompletion(Player, "cd ", 0);
expect(options).toEqual(["www/"]);
2021-09-05 01:09:30 +02:00
});
it("completes the ls and cd commands", async () => {
2022-01-05 01:09:34 +01:00
Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark");
2021-09-05 01:09:30 +02:00
for (const command of ["ls", "cd"]) {
const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0);
expect(options).toEqual(["www/"]);
2021-09-05 01:09:30 +02:00
}
});
it("completes commands starting with ./", async () => {
2022-01-05 01:09:34 +01:00
Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark");
const options = await determineAllPossibilitiesForTabCompletion(Player, "run ./", 0);
2022-01-05 01:09:34 +01:00
expect(options).toEqual([".//www/script.js", "NUKE.exe", "./www/"]);
2021-09-05 01:09:30 +02:00
});
2021-08-27 05:22:24 +02:00
});