浏览代码

add some chef.translateTo tests

d98762625 7 年之前
父节点
当前提交
615cb561e4
共有 3 个文件被更改,包括 48 次插入8 次删除
  1. 0 8
      src/node/apiUtils.mjs
  2. 1 0
      test/index.mjs
  3. 47 0
      test/tests/nodeApi/translateTo.mjs

+ 0 - 8
src/node/apiUtils.mjs

@@ -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

+ 1 - 0
test/index.mjs

@@ -57,6 +57,7 @@ import "./tests/operations/PowerSet";
 
 
 import "./tests/nodeApi/nodeApi";
+import "./tests/nodeApi/translateTo";
 
 let allTestsPassing = true;
 const testStatusCounts = {

+ 47 - 0
test/tests/nodeApi/translateTo.mjs

@@ -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");
+    })
+]);