From 36191c0bed5961486c3c1b972e8e3dcb81f49a50 Mon Sep 17 00:00:00 2001 From: jameswilddev Date: Mon, 27 May 2019 00:33:42 +0100 Subject: [PATCH] Added label parts (#6). --- src/index.tests.ts | 4 ++++ src/index.ts | 5 +++++ src/label-part.tests.ts | 7 +++++++ src/label-part.ts | 13 +++++++++++++ src/shared.tests.ts | 14 ++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 src/label-part.tests.ts create mode 100644 src/label-part.ts diff --git a/src/index.tests.ts b/src/index.tests.ts index 62626cf..3c38201 100644 --- a/src/index.tests.ts +++ b/src/index.tests.ts @@ -8,6 +8,7 @@ import * as entityReferenceColumn from "./entity-reference-column" import * as integerColumn from "./integer-column" import * as floatColumn from "./float-column" import * as column from "./column" +import * as labelPart from "./label-part" import * as schema from "./schema" import * as index from "./index" @@ -40,6 +41,9 @@ describe(`index`, () => { describe(`column`, () => { it(`schema`, () => expect(index.column).toBe(column.schema)) }) + describe(`label part`, () => { + it(`schema`, () => expect(index.labelPart).toBe(labelPart.schema)) + }) describe(`schema`, () => { it(`schema`, () => expect(index.schema).toBe(schema.schema)) }) diff --git a/src/index.ts b/src/index.ts index 5fb3dbd..b372f38 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,6 +43,11 @@ export { Type as Column } from "./column" +export { + schema as labelPart, + Type as LabelPart +} from "./label-part" + export { schema as schema, Type as Schema diff --git a/src/label-part.tests.ts b/src/label-part.tests.ts new file mode 100644 index 0000000..7b6b044 --- /dev/null +++ b/src/label-part.tests.ts @@ -0,0 +1,7 @@ +import "jasmine" +import * as labelPart from "./label-part" +import * as shared from "./shared.tests" + +describe(`label part`, () => { + shared.testLabelPart(labelPart.schema, instance => instance, `instance`) +}) diff --git a/src/label-part.ts b/src/label-part.ts new file mode 100644 index 0000000..8f0a7e9 --- /dev/null +++ b/src/label-part.ts @@ -0,0 +1,13 @@ +import * as jsonschema from "jsonschema" +import * as identifier from "./identifier" + +export const schema: jsonschema.Schema = { + description: `A chain of column identifiers which can be followed to find a value which is to be used as part of a label.`, + type: `array`, + items: identifier.schema +} + +/** + * A chain of column identifiers which can be followed to find a value which is to be used as part of a label. + */ +export type Type = ReadonlyArray diff --git a/src/shared.tests.ts b/src/shared.tests.ts index 163295a..33f8988 100644 --- a/src/shared.tests.ts +++ b/src/shared.tests.ts @@ -746,3 +746,17 @@ export function testColumn( }) }) } + +export function testLabelPart( + schema: jsonschema.Schema, + instanceFactory: InstanceFactory, + property: string +): void { + run(exhaustiveIdentifierStrings, value => accepts(schema, instanceFactory([value]))) + run(emptyArrays, value => accepts(schema, instanceFactory(value))) + run(nonIdentifierStrings, value => rejects(schema, instanceFactory([value]), `${property}[0]`, `does not match pattern "^[_a-z0-9]{6}$"`)) + run(nonStrings, value => rejects(schema, instanceFactory([value]), `${property}[0]`, `is not of a type(s) string`)) + run(nonArrays, value => rejects(schema, instanceFactory(value), property, `is not of a type(s) array`)) + describe(`multiple identifiers`, () => accepts(schema, instanceFactory([`for_eg`, `val_id`, `like__`, `__this`]))) + describe(`duplicate identifiers`, () => accepts(schema, instanceFactory([`for_eg`, `val_id`, `like__`, `val_id`, `__this`]))) +}