mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 22:21:01 +01:00
add some chef.translateTo tests
This commit is contained in:
parent
c96a1df8e1
commit
615cb561e4
@ -89,14 +89,6 @@ export async function translateTo(input, type) {
|
||||
return await dish.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @namespace Api
|
||||
* @param searchTerm
|
||||
*/
|
||||
export function search(searchTerm) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract properties from an operation by instantiating it and
|
||||
|
@ -57,6 +57,7 @@ import "./tests/operations/PowerSet";
|
||||
|
||||
|
||||
import "./tests/nodeApi/nodeApi";
|
||||
import "./tests/nodeApi/translateTo";
|
||||
|
||||
let allTestsPassing = true;
|
||||
const testStatusCounts = {
|
||||
|
47
test/tests/nodeApi/translateTo.mjs
Normal file
47
test/tests/nodeApi/translateTo.mjs
Normal file
@ -0,0 +1,47 @@
|
||||
/* eslint no-console: 0 */
|
||||
|
||||
/**
|
||||
* nodeApi.js
|
||||
*
|
||||
* Test node api utilities
|
||||
*
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import assert from "assert";
|
||||
import it from "../assertionHandler";
|
||||
import chef from "../../../src/node/index";
|
||||
import TestRegister from "../../TestRegister";
|
||||
import BigNumber from "bignumber.js";
|
||||
|
||||
TestRegister.addApiTests([
|
||||
it("should have a translateTo function", () => {
|
||||
assert(chef.translateTo);
|
||||
}),
|
||||
|
||||
it("should translate to number from string", async () => {
|
||||
const hex = await chef.toHex("1");
|
||||
const translated = await chef.translateTo(hex, "number");
|
||||
assert.equal(31, translated);
|
||||
}),
|
||||
|
||||
it("should translate from string to byte array", async () => {
|
||||
const str = await chef.toBase32("something");
|
||||
const translated = await chef.translateTo(str, "bytearray");
|
||||
assert.deepEqual(translated, [79, 78, 88, 87, 50, 90, 76, 85, 78, 66, 85, 87, 52, 90, 89, 61]);
|
||||
}),
|
||||
|
||||
it("should convert a number to a big numner", async () => {
|
||||
const result = await chef.translateTo(31, "bignumber");
|
||||
assert.deepEqual(result, BigNumber(31));
|
||||
}),
|
||||
|
||||
it("should be symmetric", async () => {
|
||||
const result = await chef.setUnion("1 2 3 4:3 4 5 6", [":", " "]);
|
||||
const bytearray = await chef.translateTo(result, "bytearray");
|
||||
const translated = await chef.translateTo(bytearray, "string");
|
||||
assert.equal(translated, "1 2 3 4 5 6");
|
||||
})
|
||||
]);
|
Loading…
Reference in New Issue
Block a user