cif.spec.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import * as Data from '../cif/data-model'
  7. import TextField from '../cif/text/field'
  8. import * as Schema from '../cif/schema'
  9. const columnData = `123abc`;
  10. const intField = TextField({ data: columnData, indices: [0, 1, 1, 2, 2, 3], count: 3 }, 3);
  11. const strField = TextField({ data: columnData, indices: [3, 4, 4, 5, 5, 6], count: 3 }, 3);
  12. const testBlock = Data.Block({
  13. _atoms: Data.Category(3, {
  14. x: intField,
  15. name: strField
  16. })
  17. }, 'test');
  18. namespace TestSchema {
  19. export const atoms = { x: Schema.Field.int(), name: Schema.Field.str() }
  20. export const schema = { atoms }
  21. }
  22. describe('schema', () => {
  23. const data = Schema.apply(TestSchema.schema, testBlock);
  24. it('property access', () => {
  25. const { x, name } = data.atoms;
  26. expect(x.value(0)).toBe(1);
  27. expect(name.value(1)).toBe('b');
  28. });
  29. it('toArray', () => {
  30. const ret = data.atoms.x.toArray({ array: Int32Array });
  31. expect(ret.length).toBe(3);
  32. expect(ret[0]).toBe(1);
  33. expect(ret[1]).toBe(2);
  34. expect(ret[2]).toBe(3);
  35. })
  36. });