-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
148 additions
and
105 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import * as $ from './index.js' | ||
|
||
test('array', () => { | ||
expect($.array($.unknown)({})).toEqual([{}, "expected array"]) | ||
expect($.array($.unknown)([])).toEqual([[], undefined]) | ||
expect($.array($.number)([1, 2, 3])).toEqual([[1, 2, 3], undefined]) | ||
expect($.array($.number)([1, '2', 3])).toEqual(['2', 'at index 1, expected number']) | ||
expect($.array($.unknown)({})).toEqual($.fail({}, 'expected array')) | ||
expect($.array($.unknown)([])).toEqual($.ok([])) | ||
expect($.array($.number)([1, 2, 3])).toEqual($.ok([1, 2, 3])) | ||
expect($.array($.number)([1, '2', 3])).toEqual($.fail('2', 'at index 1, expected number')) | ||
}) |
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,6 @@ | ||
import * as $ from './index.js' | ||
|
||
test('assert', () => { | ||
expect(() => $.assert($.number)('a')).toThrow('Invalid value expected number, got \'a\'.') | ||
expect(() => $.assert($.number, $.reasonWithoutReceived)('a')).toThrow('Invalid value expected number.') | ||
}) |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as $ from './index.js' | ||
|
||
test('bigint', () => { | ||
expect($.bigint(0n)).toEqual([0n, undefined]) | ||
expect($.bigint(1)).toEqual([1, 'expected bigint']) | ||
expect($.bigint(0n)).toEqual($.ok(0n)) | ||
expect($.bigint(1)).toEqual($.fail(1, 'expected bigint')) | ||
}) |
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,7 +1,7 @@ | ||
import * as $ from './index.js' | ||
|
||
test('boolean', () => { | ||
expect($.boolean(true)).toEqual([true, undefined]) | ||
expect($.boolean(false)).toEqual([false, undefined]) | ||
expect($.boolean(0)).toEqual([0, 'expected boolean']) | ||
expect($.boolean(true)).toEqual($.ok(true)) | ||
expect($.boolean(false)).toEqual($.ok(false)) | ||
expect($.boolean(0)).toEqual($.fail(0, 'expected 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
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,6 +1,6 @@ | ||
import * as $ from './index.js' | ||
|
||
test('defined', () => { | ||
expect($.defined(1)).toEqual([1, undefined]) | ||
expect($.defined(undefined)).toEqual([undefined, 'expected defined']) | ||
expect($.defined(1)).toEqual($.ok(1)) | ||
expect($.defined(undefined)).toEqual($.fail(undefined, 'expected defined')) | ||
}) |
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,10 +1,10 @@ | ||
import * as $ from './index.js' | ||
|
||
test('exact partial', () => { | ||
expect($.exactPartial({})({})).toEqual([{}, undefined]) | ||
expect($.exactPartial({})(undefined)).toEqual([undefined, 'expected object']) | ||
expect($.exactPartial({})({ a: 1 })).toEqual([{ a: 1 }, 'unexpected key a']) | ||
expect($.exactPartial({ a: $.number })({ a: 1 })).toEqual([{ a: 1 }, undefined]) | ||
expect($.exactPartial({ a: $.number })({ a: '1' })).toEqual(['1', 'at key a, expected number']) | ||
expect($.exactPartial({ a: $.number })({ a: undefined })).toEqual([{ a: undefined }, undefined]) | ||
expect($.exactPartial({})({})).toEqual($.ok({})) | ||
expect($.exactPartial({})(undefined)).toEqual($.fail(undefined, 'expected object')) | ||
expect($.exactPartial({})({ a: 1 })).toEqual($.fail({ a: 1 }, 'unexpected key a')) | ||
expect($.exactPartial({ a: $.number })({ a: 1 })).toEqual($.ok({ a: 1 })) | ||
expect($.exactPartial({ a: $.number })({ a: '1' })).toEqual($.fail('1', 'at key a, expected number')) | ||
expect($.exactPartial({ a: $.number })({ a: undefined })).toEqual($.ok({ a: undefined })) | ||
}) |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as $ from './index.js' | ||
|
||
test('false', () => { | ||
expect($.false(false)).toEqual([false, undefined]) | ||
expect($.false(true)).toEqual([true, 'expected false']) | ||
expect($.false(false)).toEqual($.ok(false)) | ||
expect($.false(true)).toEqual($.fail(true, 'expected 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import * as $ from './index.js' | ||
|
||
test('finite', () => { | ||
expect($.finite(1)).toEqual([1, undefined]) | ||
expect($.finite(Infinity)).toEqual([Infinity, 'expected finite number']) | ||
expect($.finite(NaN)).toEqual([NaN, 'expected finite number']) | ||
expect($.finite(1)).toEqual($.ok(1)) | ||
expect($.finite(Infinity)).toEqual($.fail(Infinity, 'expected finite number')) | ||
expect($.finite(NaN)).toEqual($.fail(NaN, 'expected finite number')) | ||
}) |
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
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,11 @@ | ||
import { ok, fail, type Refute } from './index.js' | ||
|
||
/** */ | ||
const is = | ||
<T>(a: T): Refute<T> => | ||
(value: unknown) => | ||
Object.is(value, a) ? | ||
ok(value as T) : | ||
fail(value, `expected ${a}`) | ||
|
||
export default is |
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
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
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,9 +1,9 @@ | ||
import * as $ from './index.js' | ||
|
||
test('partial', () => { | ||
expect($.partial({ a: $.number })(null)).toEqual([null, 'expected object']) | ||
expect($.partial({ a: $.number })({})).toEqual([{}, undefined]) | ||
expect($.partial({ a: $.number })({ b: 1 })).toEqual([{ b: 1 }, undefined]) | ||
expect($.partial({ a: $.number })({ a: '1' })).toEqual(['1', 'at key a, expected number']) | ||
expect($.partial({ a: $.number })({ a: 1, b: 2 })).toEqual([{ a: 1, b: 2 }, undefined]) | ||
expect($.partial({ a: $.number })(null)).toEqual($.fail(null, 'expected object')) | ||
expect($.partial({ a: $.number })({})).toEqual($.ok({})) | ||
expect($.partial({ a: $.number })({ b: 1 })).toEqual($.ok({ b: 1 })) | ||
expect($.partial({ a: $.number })({ a: '1' })).toEqual($.fail('1', 'at key a, expected number')) | ||
expect($.partial({ a: $.number })({ a: 1, b: 2 })).toEqual($.ok({ a: 1, b: 2 })) | ||
}) |
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
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,9 +1,9 @@ | ||
import * as $ from './index.js' | ||
|
||
test('record', () => { | ||
expect($.record($.string, $.number)(null)).toEqual([null, 'expected object']) | ||
expect($.record($.string, $.number)({})).toEqual([{}, undefined]) | ||
expect($.record($.string, $.number)({ a: 1 })).toEqual([{ a: 1 }, undefined]) | ||
expect($.record($.string, $.number)({ a: '1' })).toEqual(['1', 'at key a, expected number']) | ||
expect($.record($.regexp(/^[a-z]+$/), $.number)({ a1: '1' })).toEqual(['a1', 'key, expected to match /^[a-z]+$/.']) | ||
expect($.record($.string, $.number)(null)).toEqual($.fail(null, 'expected object')) | ||
expect($.record($.string, $.number)({})).toEqual($.ok({})) | ||
expect($.record($.string, $.number)({ a: 1 })).toEqual($.ok({ a: 1 })) | ||
expect($.record($.string, $.number)({ a: '1' })).toEqual($.fail('1', 'at key a, expected number')) | ||
expect($.record($.regexp(/^[a-z]+$/), $.number)({ a1: '1' })).toEqual($.fail('a1', 'key, expected to match /^[a-z]+$/.')) | ||
}) |
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,5 @@ | ||
import * as $ from './index.js' | ||
|
||
test('regexp', () => { | ||
expect($.regexp(/^foo/dy)('foo')).toEqual($.ok('foo')) | ||
}) |
Oops, something went wrong.