Skip to content

Commit

Permalink
feat: added Never case
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekelly881 committed May 31, 2023
1 parent ebef847 commit f844074
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const go = (ast: AST.AST): Empty<any> => {
}

switch (ast._tag) {
case "NeverKeyword": throw new Error("cannot build an Empty for `never`")

case "Literal": return () => ast.literal
case "ObjectKeyword": return () => ({})
case "Tuple": {
Expand Down Expand Up @@ -86,6 +88,4 @@ const go = (ast: AST.AST): Empty<any> => {
case "AnyKeyword":
return () => undefined
}

throw new Error(`unhandled ${ast._tag}`)
}
5 changes: 2 additions & 3 deletions src/equivalence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const go = (ast: AST.AST): Equivalence<any> => {
}

switch (ast._tag) {
case "NeverKeyword": throw new Error("cannot build an Equivalence for `never`")

case "UndefinedKeyword":
case "UnknownKeyword":
case "VoidKeyword":
Expand Down Expand Up @@ -105,7 +107,4 @@ const go = (ast: AST.AST): Equivalence<any> => {
};
}
}

throw new Error(`unhandled ${ast._tag}`)

}
2 changes: 2 additions & 0 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const go = (ast: AST.AST, depthLimit = 10): Faker<any> => {
}

switch (ast._tag) {
case "NeverKeyword": throw new Error("cannot build a Faker for `never`")

case "Refinement": return go(ast.from, depthLimit)
case "Transform": return go(ast.to, depthLimit)
case "Declaration": return go(ast.type, depthLimit)
Expand Down
4 changes: 2 additions & 2 deletions src/semigroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const go = (ast: AST.AST): Semigroup<any> => {
}

switch (ast._tag) {
case "NeverKeyword": throw new Error("cannot build a Semigroup for `never`")

case "Literal":
case "ObjectKeyword":
case "BigIntKeyword":
Expand Down Expand Up @@ -116,6 +118,4 @@ const go = (ast: AST.AST): Semigroup<any> => {
}
}
}

throw new Error(`unhandled ${ast._tag}`)
}
6 changes: 6 additions & 0 deletions tests/empty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ describe("empty", () => {
})
})

it("never", () => {
expect(() => _.to(S.never)()).toThrowError(
new Error("cannot build an Empty for `never`")
);
});

it("custom empty", () => {
const schema = pipe(S.number, _.empty(() => 1))
expectEmptyValues(schema, 1, 1)
Expand Down
6 changes: 6 additions & 0 deletions tests/equivalence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ describe("equivalence", () => {
})
})

it("never", () => {
expect(() => _.to(S.never)()).toThrowError(
new Error("cannot build an Equivalence for `never`")
);
});

it("number/ ", () => {
const schema = pipe(S.number, S.nonNaN())
const eq = _.to(schema)()
Expand Down
6 changes: 6 additions & 0 deletions tests/faker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ describe("faker", () => {
generatesValidValue(schema)
});

it("never", () => {
expect(() => _.to(S.never)(F.faker)).toThrowError(
new Error("cannot build a Faker for `never`")
);
});

it("transform", () => {
const schema: S.Schema<string, readonly [string]> = pipe(
S.string,
Expand Down
6 changes: 6 additions & 0 deletions tests/semigroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ describe("semigroup", () => {
})
})

it("never", () => {
expect(() => _.to(S.never)()).toThrowError(
new Error("cannot build a Semigroup for `never`")
);
});

it("literal/ ", () => {
const schema = S.literal("a", "b")
const { combine } = _.to(schema)()
Expand Down

0 comments on commit f844074

Please sign in to comment.