import {Interface, interfaceComplexity, newValue, subInterface} from "./interface"; test('interfaceComplexity works for primitive', async () => { const i: Interface = { type: 'primitive', primitive: { value: 'string', }, }; expect(interfaceComplexity(i)).toEqual(1); }); test('interfaceComplexity works for lists', async () => { const i: Interface = { type: 'list', list: { entry: { type: 'primitive', primitive: { value: 'string', }, }, }, }; expect(interfaceComplexity(i)).toEqual(2); }); test('interfaceComplexity works for maps', async () => { const i: Interface = { type: 'map', map: { entries: [ { key: 'a', schema: { type: 'primitive', primitive: { value: 'string', }, }, }, { key: 'b', schema: { type: 'primitive', primitive: { value: 'boolean', }, }, }, ] }, }; expect(interfaceComplexity(i)).toEqual(3); }); test('newValue works for primitive', async () => { const i: Interface = { type: 'primitive', primitive: { value: 'string', } } const v = newValue(i); expect(v).toEqual(''); }); test('subInterface works for primitive', async () => { const i: Interface = { type: 'primitive', primitive: { value: 'string', } }; const i2: Interface = { type: 'primitive', primitive: { value: 'string', } }; const i3: Interface = { type: 'primitive', primitive: { value: 'float', } }; expect(subInterface(i, i2)).toEqual(true); expect(subInterface(i, i3)).toEqual(false); }); test('subInterface works for map', async () => { const i: Interface = { type: 'map', map: { entries: [ { key: 'a', schema: { type: 'primitive', primitive: { value: 'string', }, }, }, { key: 'b', schema: { type: 'primitive', primitive: { value: 'float', }, }, }, ], } }; const i2: Interface = { type: 'map', map: { entries: [ { key: 'a', schema: { type: 'primitive', primitive: { value: 'string', }, }, }, { key: 'b', schema: { type: 'primitive', primitive: { value: 'float', }, }, }, { key: 'c', schema: { type: 'primitive', primitive: { value: 'boolean', }, }, }, ], } }; const i3: Interface = { type: 'map', map: { entries: [ { key: 'a', schema: { type: 'primitive', primitive: { value: 'string', }, }, }, { key: 'c', schema: { type: 'primitive', primitive: { value: 'float', }, }, }, ], } }; expect(subInterface(i, i2)).toEqual(true); expect(subInterface(i, i3)).toEqual(false); });