Skip to content
This repository has been archived by the owner on Jul 20, 2019. It is now read-only.

Commit

Permalink
Added label parts (#6).
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed May 26, 2019
1 parent a8de0bb commit 36191c0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.tests.ts
Expand Up @@ -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"

Expand Down Expand Up @@ -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))
})
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions 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`)
})
13 changes: 13 additions & 0 deletions 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<identifier.Type>
14 changes: 14 additions & 0 deletions src/shared.tests.ts
Expand Up @@ -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`])))
}

0 comments on commit 36191c0

Please sign in to comment.