-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(primitives): implement boolean type
- @tangdrew/primitives@0.4.3
- @tangdrew/primitives@0.4.2
- @tangdrew/primitives@0.4.1
- @tangdrew/primitives@0.4.0
- @tangdrew/primitives@0.2.1
- @tangdrew/primitives@0.2.0
- @tangdrew/primitives@0.1.1
- @tangdrew/primitives@0.1.0
- @tangdrew/fhir-types@0.3.4
- @tangdrew/fhir-types@0.3.3
- @tangdrew/fhir-types@0.3.2
- @tangdrew/fhir-types@0.3.1
- @tangdrew/fhir-types@0.3.0
- @tangdrew/fhir-ts-codegen@0.5.3
- @tangdrew/fhir-ts-codegen@0.5.2
- @tangdrew/fhir-ts-codegen@0.5.1
- @tangdrew/fhir-ts-codegen@0.5.0
- @tangdrew/fhir-ts-codegen@0.3.0
- @tangdrew/fhir-ts-codegen@0.2.3
- @tangdrew/fhir-ts-codegen@0.2.2
- @tangdrew/fhir-ts-codegen@0.2.1
- @tangdrew/fhir-ts-codegen@0.2.0
- @tangdrew/fhir-ts-codegen@0.1.1
- @tangdrew/fhir-ts-codegen@0.1.0
Showing
5 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Boolean FHIR Primitive Runtime Type | ||
*/ | ||
|
||
import { BooleanType, boolean } from "io-ts"; | ||
|
||
export { BooleanType as Boolean, boolean }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/** | ||
* FHIR Primitive Runtime Types | ||
*/ | ||
|
||
import { Boolean, boolean } from "./boolean"; | ||
|
||
export { Boolean, boolean }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Tests for Boolean Runtime Type | ||
*/ | ||
|
||
import { boolean } from "../src"; | ||
import { assertSuccess, assertFailure, assertStrictEqual } from "./helpers"; | ||
|
||
describe("boolean", () => { | ||
it("should succeed validating a valid value", () => { | ||
const T = boolean; | ||
assertSuccess(T.decode(true)); | ||
}); | ||
|
||
it("should return the same reference if validation succeeded and nothing changed", () => { | ||
const T = boolean; | ||
const value = false; | ||
assertStrictEqual(T.decode(value), value); | ||
}); | ||
|
||
it("should fail validating an invalid value", () => { | ||
const T = boolean; | ||
assertFailure(T.decode("abc"), [ | ||
'Invalid value "abc" supplied to : boolean' | ||
]); | ||
}); | ||
|
||
it("should type guard", () => { | ||
const T = boolean; | ||
expect(T.is(false)).toEqual(true); | ||
expect(T.is("b")).toEqual(false); | ||
expect(T.is(undefined)).toEqual(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Test helpers | ||
*/ | ||
|
||
import { PathReporter } from "io-ts/lib/PathReporter"; | ||
import * as t from "io-ts"; | ||
|
||
export const assertSuccess = <T>(validation: t.Validation<T>): void => { | ||
expect(validation.isRight()).toBe(true); | ||
}; | ||
|
||
export const assertFailure = <T>( | ||
validation: t.Validation<T>, | ||
descriptions: Array<string> | ||
): void => { | ||
expect(validation.isLeft()); | ||
expect(PathReporter.report(validation)).toEqual(descriptions); | ||
}; | ||
|
||
export const assertStrictEqual = <T>( | ||
validation: t.Validation<T>, | ||
value: any | ||
): void => { | ||
expect(validation.fold<any>(t.identity, t.identity)).toBe(value); | ||
}; | ||
|
||
export const assertDeepEqual = <T>( | ||
validation: t.Validation<T>, | ||
value: any | ||
): void => { | ||
expect(validation.fold<any>(t.identity, t.identity)).toEqual(value); | ||
}; |