backend.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. let test = 1;
  2. const check = (value, expect) => {
  3. console.log("Running test " + test + "...");
  4. test = test + 1;
  5. if (value.toString() === expect.toString()) {
  6. console.log("Pass.");
  7. console.log("");
  8. return;
  9. }
  10. console.log("FAIL!!!");
  11. console.log("Expected: \"" + expect.toString() + "\".");
  12. console.log("Result: \"" + value.toString() + "\".");
  13. console.log("");
  14. }
  15. const test_all = async () => {
  16. console.log("Loading and testing loader + phrasebook.");
  17. const libtranslate = require("../source/core.js");
  18. const flat = await new libtranslate
  19. .loader("test/flat.json", true)
  20. .load();
  21. check(flat.get("test a"), "Test A");
  22. check(flat.get("simple"), "prosta");
  23. console.log("Loading and testing languages library.");
  24. const langs = await new libtranslate
  25. .languages("test/", true)
  26. .load("index.json");
  27. const loaded = await langs.select("pl_PL");
  28. check(loaded.get("test a"), "Test A");
  29. console.log("Testing objects notation.");
  30. const obj = await langs.select("en_US");
  31. check(obj.get("test.result"), "yes");
  32. check(obj.get("test a"), "Test A");
  33. console.log("Testing format.");
  34. check(obj.get("test.format").format({ many: 10 }), "More than 10");
  35. };
  36. test_all();