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

183 lines
6.5 KiB
TypeScript
Raw Normal View History

/* eslint-disable no-await-in-loop */
2021-12-19 21:42:40 +01:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jest, describe, expect, test } from '@jest/globals'
2021-08-27 05:22:24 +02:00
import { Player } from "../../src/Player";
import { determineAllPossibilitiesForTabCompletion } from "../../src/Terminal/determineAllPossibilitiesForTabCompletion";
import { Server } from "../../src/Server/Server";
2021-09-09 05:47:34 +02:00
import { AddToAllServers, prestigeAllServers } from "../../src/Server/AllServers";
2021-08-27 05:22:24 +02:00
import { LocationName } from "../../src/Locations/data/LocationNames";
import { CodingContract } from "../../src/CodingContracts";
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: LocationName.Aevum,
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);
expect(options.sort()).toEqual([
2021-09-05 01:09:30 +02:00
"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");
Player.getHomeComputer().writeToScriptFile("/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 () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
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 () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
const options = await determineAllPossibilitiesForTabCompletion(Player, "nano ", 0);
expect(options).toEqual([
2021-09-09 05:47:34 +02:00
"/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");
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
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);
expect(options).toEqual([
2021-09-07 20:31:47 +02:00
"/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 () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
const options = await determineAllPossibilitiesForTabCompletion(Player, "run ", 0);
expect(options).toEqual([
2021-09-07 20:31:47 +02:00
"/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);
expect(options).toEqual([
2021-09-07 20:31:47 +02:00
"asl.msg",
"af.lit",
"/www/note.txt",
"www/",
]);
2021-09-05 01:09:30 +02:00
});
it("completes the download and mv commands", async () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
for (const command of ["download", "mv"]) {
const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0);
expect(options).toEqual([
2021-09-09 05:47:34 +02:00
"/www/script.js",
"note.txt",
"www/",
]);
2021-09-05 01:09:30 +02:00
}
});
it("completes the cd command", async () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToScriptFile("/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 () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
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 () => {
2021-09-05 01:09:30 +02:00
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
const options = await determineAllPossibilitiesForTabCompletion(Player, "run ./", 0);
expect(options).toEqual([
2021-09-09 05:47:34 +02:00
".//www/script.js",
"NUKE.exe",
"./www/",
]);
2021-09-05 01:09:30 +02:00
});
2021-08-27 05:22:24 +02:00
});