UNPKG

@brimdata/zealot

Version:

The Javascript Client for Zed Lakes

128 lines (127 loc) 4.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _zq = require("./cmd/zq"); const _encoder = require("./encoder"); const _zuiTestData = require("zui-test-data"); const file = (0, _zuiTestData.getPath)("sample.zson"); test("super simple", async ()=>{ const input = await (0, _zq.zq)({ input: '{hello: "world"}', format: "zjson" }); const decoded = (0, _encoder.decode)(input); const encoded = (0, _encoder.encode)(decoded); for(let i = 0; i < input.length; ++i){ expect(encoded[i]).toEqual(input[i]); } }); test("super simple 2 typedefs", async ()=>{ const input = await (0, _zq.zq)({ input: '{hello: ["world"]}', format: "zjson" }); const decoded = (0, _encoder.decode)(input); const encoded = (0, _encoder.encode)(decoded); for(let i = 0; i < input.length; ++i){ expect(encoded[i]).toEqual(input[i]); } }); test("simply type value", async ()=>{ const input = await (0, _zq.zq)({ input: "{hello: <string>}", format: "zjson" }); const decoded = (0, _encoder.decode)(input); const encoded = (0, _encoder.encode)(decoded); for(let i = 0; i < input.length; ++i){ expect(encoded[i]).toEqual(input[i]); } }); test("decode, then encode", async ()=>{ const input = await (0, _zq.zq)({ file, format: "zjson" }); const decoded = (0, _encoder.decode)(input); const encoded = (0, _encoder.encode)(decoded); for(let i = 0; i < input.length; ++i){ expect(encoded[i]).toEqual(input[i]); } }); test("decode, then encode a fused input", async ()=>{ const input = await (0, _zq.zq)({ query: "fuse", file, format: "zjson" }); const decoded = (0, _encoder.decode)(input); const encoded = (0, _encoder.encode)(decoded); for(let i = 0; i < input.length; ++i){ expect(encoded[i]).toEqual(input[i]); } }); test("decode, encode with type values", async ()=>{ const input = await (0, _zq.zq)({ query: "* | count() by typeof(this) | sort count, typeof", file, format: "zjson" }); expect((0, _encoder.encode)((0, _encoder.decode)(input))).toEqual(input); }); test("types from one search are the same", async ()=>{ const groupBy = await (0, _zq.zq)({ query: "* | count() by typeof(this) | sort count, typeof", file, format: "zjson" }); const list = await (0, _zq.zq)({ file, format: "zjson" }); const [row1] = (0, _encoder.decode)(groupBy); const accessType = row1.get("typeof").value; const rows = (0, _encoder.decode)(list); const accessRecords = rows.filter((r)=>r.type === accessType); expect(accessRecords.map((r)=>r.toString())).toEqual([ "{info:Access List Example,nets:[10.1.1.0/24,10.1.2.0/24]}" ]); }); test("encode decode a field", async ()=>{ const input = await (0, _zq.zq)({ query: "*", file, format: "zjson" }); const records = (0, _encoder.decode)(input); expect.assertions(250); records.forEach((rec)=>{ rec.flatColumns.forEach((column)=>{ const field = rec.getField(column); if (!field) return; const after = (0, _encoder.decode)((0, _encoder.encode)(field)); expect(field).toEqual(after); expect(field.value.type === after.value.type).toBe(true); }); }); }); test("encode decode a typeof value", async ()=>{ const input = await (0, _zq.zq)({ query: "count() by typeof(this) | sort typeof", file, format: "zjson" }); const records = (0, _encoder.decode)(input); expect.assertions(36); records.forEach((rec)=>{ rec.flatColumns.forEach((column)=>{ const field = rec.getField(column); if (!field) return; const after = (0, _encoder.decode)((0, _encoder.encode)(field)); if (!field) return; expect(field).toEqual(after); expect(field.value.type === after.value.type).toBe(true); }); }); });