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

166 lines
5.9 KiB
TypeScript
Raw Normal View History

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 { Message } from "../../src/Message/Message";
import { CodingContract } from "../../src/CodingContracts";
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", () => {
2021-09-09 05:47:34 +02:00
const options = determineAllPossibilitiesForTabCompletion(Player, "connect ", 0);
2021-09-10 06:13:03 +02:00
expect(options).equal(["8.8.8.8", "near"]);
2021-09-05 01:09:30 +02:00
});
it("completes the buy command", () => {
2021-09-09 05:47:34 +02:00
const options = determineAllPossibilitiesForTabCompletion(Player, "buy ", 0);
2021-09-10 06:13:03 +02:00
expect(options).equal([
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",
]);
});
it("completes the scp command", () => {
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
Player.getHomeComputer().messages.push("af.lit");
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
2021-09-09 05:47:34 +02:00
const options1 = determineAllPossibilitiesForTabCompletion(Player, "scp ", 0);
2021-09-10 06:13:03 +02:00
expect(options1).equal(["/www/script.js", "af.lit", "note.txt", "www/"]);
2021-09-05 01:09:30 +02:00
2021-09-09 05:47:34 +02:00
const options2 = determineAllPossibilitiesForTabCompletion(Player, "scp note.txt ", 1);
2021-09-10 06:13:03 +02:00
expect(options2).equal([Player.getHomeComputer().ip, "home", "8.8.8.8", "near", "4.4.4.4", "far"]);
2021-09-05 01:09:30 +02:00
});
it("completes the kill, tail, mem, and check commands", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
for (const command of ["kill", "tail", "mem", "check"]) {
2021-09-10 06:13:03 +02:00
expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal(["/www/script.js", "www/"]);
2021-09-05 01:09:30 +02:00
}
});
it("completes the nano commands", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
2021-09-10 06:13:03 +02:00
expect(determineAllPossibilitiesForTabCompletion(Player, "nano ", 0)).equal([
2021-09-09 05:47:34 +02:00
"/www/script.js",
"note.txt",
".fconf",
"www/",
]);
2021-09-05 01:09:30 +02:00
});
it("completes the rm command", () => {
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"));
Player.getHomeComputer().messages.push(new Message("asl.msg"));
Player.getHomeComputer().messages.push("af.lit");
2021-09-10 06:13:03 +02:00
expect(determineAllPossibilitiesForTabCompletion(Player, "rm ", 0)).equal([
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", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
2021-09-10 06:13:03 +02:00
expect(determineAllPossibilitiesForTabCompletion(Player, "run ", 0)).equal([
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", () => {
Player.getHomeComputer().writeToTextFile("/www/note.txt", "oh hai mark");
Player.getHomeComputer().messages.push(new Message("asl.msg"));
Player.getHomeComputer().messages.push("af.lit");
2021-09-10 06:13:03 +02:00
expect(determineAllPossibilitiesForTabCompletion(Player, "cat ", 0)).equal([
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", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
for (const command of ["download", "mv"]) {
2021-09-10 06:13:03 +02:00
expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal([
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", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
2021-09-10 06:13:03 +02:00
expect(determineAllPossibilitiesForTabCompletion(Player, "cd ", 0)).equal(["www/"]);
2021-09-05 01:09:30 +02:00
});
it("completes the ls and cd commands", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
for (const command of ["ls", "cd"]) {
2021-09-10 06:13:03 +02:00
expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal(["www/"]);
2021-09-05 01:09:30 +02:00
}
});
it("completes commands starting with ./", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
2021-09-10 06:13:03 +02:00
expect(determineAllPossibilitiesForTabCompletion(Player, "run ./", 0)).equal([
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
});