UNPKG

r2-shared-js

Version:

Readium 2 'shared' for NodeJS (TypeScript)

75 lines 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ava_1 = require("ava"); var path = require("path"); var publication_1 = require("../src/models/publication"); var lcp_1 = require("r2-lcp-js/dist/es5/src/parser/epub/lcp"); var serializable_1 = require("r2-lcp-js/dist/es5/src/serializable"); var init_globals_1 = require("../src/init-globals"); var helpers_1 = require("./helpers"); (0, init_globals_1.initGlobalConverters_SHARED)(); (0, init_globals_1.initGlobalConverters_GENERIC)(); (0, lcp_1.setLcpNativePluginPath)(path.join(process.cwd(), "LCP", "lcp.node")); var contextStr1 = "http://context1"; var contextStr2 = "http://context2"; (0, ava_1.default)("JSON SERIALIZE: Publication.Context => string[]", function (t) { var pub = new publication_1.Publication(); pub.Context = []; pub.Context.push(contextStr1); pub.Context.push(contextStr2); (0, helpers_1.inspect)(pub); var json = (0, serializable_1.TaJsonSerialize)(pub); (0, helpers_1.logJSON)(json); (0, helpers_1.checkType_Array)(t, json["@context"]); var arr = json["@context"]; t.is(arr.length, 2); (0, helpers_1.checkType_String)(t, arr[0]); t.is(arr[0], contextStr1); (0, helpers_1.checkType_String)(t, arr[1]); t.is(arr[1], contextStr2); }); (0, ava_1.default)("JSON SERIALIZE: Publication.Context => string[1] collapse-array", function (t) { var pub = new publication_1.Publication(); pub.Context = [contextStr1]; (0, helpers_1.inspect)(pub); var json = (0, serializable_1.TaJsonSerialize)(pub); (0, helpers_1.logJSON)(json); (0, helpers_1.checkType_String)(t, json["@context"]); t.is(json["@context"], contextStr1); }); (0, ava_1.default)("JSON DESERIALIZE: Publication.Context => string[]", function (t) { var json = {}; json["@context"] = [contextStr1, contextStr2]; (0, helpers_1.logJSON)(json); var pub = (0, serializable_1.TaJsonDeserialize)(json, publication_1.Publication); (0, helpers_1.inspect)(pub); (0, helpers_1.checkType_Array)(t, pub.Context); t.is(pub.Context.length, 2); (0, helpers_1.checkType_String)(t, pub.Context[0]); t.is(pub.Context[0], contextStr1); (0, helpers_1.checkType_String)(t, pub.Context[1]); t.is(pub.Context[1], contextStr2); }); (0, ava_1.default)("JSON DESERIALIZE: Publication.Context => string[1]", function (t) { var json = {}; json["@context"] = [contextStr1]; (0, helpers_1.logJSON)(json); var pub = (0, serializable_1.TaJsonDeserialize)(json, publication_1.Publication); (0, helpers_1.inspect)(pub); (0, helpers_1.checkType_Array)(t, pub.Context); t.is(pub.Context.length, 1); (0, helpers_1.checkType_String)(t, pub.Context[0]); t.is(pub.Context[0], contextStr1); }); (0, ava_1.default)("JSON DESERIALIZE: Publication.Context => string", function (t) { var json = {}; json["@context"] = contextStr1; (0, helpers_1.logJSON)(json); var pub = (0, serializable_1.TaJsonDeserialize)(json, publication_1.Publication); (0, helpers_1.inspect)(pub); (0, helpers_1.checkType_Array)(t, pub.Context); t.is(pub.Context.length, 1); (0, helpers_1.checkType_String)(t, pub.Context[0]); t.is(pub.Context[0], contextStr1); }); //# sourceMappingURL=test-JSON-Context.js.map