UNPKG

@brimdata/zealot

Version:

The Javascript Client for Zed Lakes

61 lines (60 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _zq = require("../../cmd/zq"); const _zed = require("../../zed"); const _factory = require("../../test/factory"); test("field path", ()=>{ const r = (0, _factory.createRecord)({ id: { person: "alice" } }); const f = r.getField([ "id", "person" ]); expect(f?.value.toString()).toBe("alice"); expect(f?.name).toBe("person"); expect(f?.path).toEqual([ "id", "person" ]); }); test("field path with nested named types", async ()=>{ const objects = await (0, _zq.zq)({ input: '{a: {b: {c: "foo"}(=c)}(=b)}(=a)', format: "zjson" }); const rows = _zed.DefaultContext.decode(objects); const field = rows[0].getField([ "a", "b", "c" ]); expect(field?.path).toEqual([ "a", "b", "c" ]); expect(field?.rootRecord === rows[0]).toBe(true); }); test("field path with nested unnamed types", async ()=>{ const objects = await (0, _zq.zq)({ input: '{a: {b: {c: "foo"}}}', format: "zjson" }); const rows = _zed.DefaultContext.decode(objects); const field = rows[0].getField([ "a", "b", "c" ]); expect(field?.path).toEqual([ "a", "b", "c" ]); expect(field?.rootRecord === rows[0]).toBe(true); });