Skip to content

Commit 0b665b8

Browse files
committed
fix: remove unused API
1 parent b1cbacd commit 0b665b8

30 files changed

+303
-712
lines changed

src/any.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as t from './'
2+
import { expect } from 'chai'
3+
4+
describe(`t.any`, function() {
5+
it(`accepts anything`, function() {
6+
for (const value of [
7+
null,
8+
undefined,
9+
true,
10+
2,
11+
'foo',
12+
Symbol('foo'),
13+
{ foo: 'bar' },
14+
[],
15+
]) {
16+
t.any().assert(value)
17+
expect(t.any().accepts(value)).to.be.true
18+
expect([
19+
...t.any().errors(new t.Validation(value), [], value),
20+
]).to.deep.equal([])
21+
}
22+
})
23+
})

src/array.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as t from './'
2+
import { expect } from 'chai'
3+
4+
describe(`t.array`, function() {
5+
it(`accepts matching arrays`, function() {
6+
t.array(t.number()).assert([1, 2, 3])
7+
expect(t.array(t.number()).accepts([1, 2, 3])).to.be.true
8+
t.array(t.string()).assert(['foo', 'bar', 'baz'])
9+
expect(t.array(t.string()).accepts(['foo', 'bar', 'baz'])).to.be.true
10+
})
11+
it(`rejects non-arrays`, function() {
12+
expect(t.array(t.number()).accepts({ foo: 'bar' })).to.be.false
13+
expect(() => t.array(t.number()).assert({ foo: 'bar' })).to.throw(
14+
t.RuntimeTypeError,
15+
`Value must be an Array
16+
17+
Expected: Array<number>
18+
19+
Actual Value: {
20+
"foo": "bar"
21+
}
22+
23+
Actual Type: {
24+
foo: string
25+
}`
26+
)
27+
})
28+
it(`rejects nonmatching array elements`, function() {
29+
expect(t.array(t.number()).accepts([1, 'bar'])).to.be.false
30+
expect(() =>
31+
t.array(t.number()).assert([1, 'bar'], '', ['array'])
32+
).to.throw(
33+
t.RuntimeTypeError,
34+
`array[1] must be a number
35+
36+
Expected: number
37+
38+
Actual Value: "bar"
39+
40+
Actual Type: string`
41+
)
42+
expect(t.array(t.string()).accepts(['foo', 2])).to.be.false
43+
expect(() =>
44+
t.array(t.string()).assert(['foo', 2], '', ['array'])
45+
).to.throw(
46+
t.RuntimeTypeError,
47+
`array[1] must be a string
48+
49+
Expected: string
50+
51+
Actual Value: 2
52+
53+
Actual Type: number`
54+
)
55+
})
56+
})

src/boolean.spec.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import * as t from './'
2+
import { expect } from 'chai'
3+
4+
describe(`t.boolean`, function() {
5+
it(`accepts booleans`, function() {
6+
t.boolean().assert(true)
7+
t.boolean().assert(false)
8+
expect(t.boolean().accepts(true)).to.be.true
9+
expect(t.boolean().accepts(false)).to.be.true
10+
})
11+
it(`rejects everything else`, function() {
12+
expect(t.boolean().accepts(2)).to.be.false
13+
expect(() => t.boolean().assert(2)).to.throw(
14+
t.RuntimeTypeError,
15+
`Value must be true or false
16+
17+
Expected: boolean
18+
19+
Actual Value: 2
20+
21+
Actual Type: number`
22+
)
23+
expect(t.boolean().accepts('foo')).to.be.false
24+
expect(() => t.boolean().assert('foo')).to.throw(
25+
t.RuntimeTypeError,
26+
`Value must be true or false
27+
28+
Expected: boolean
29+
30+
Actual Value: "foo"
31+
32+
Actual Type: string`
33+
)
34+
expect(t.boolean().accepts([])).to.be.false
35+
expect(() => t.boolean().assert([])).to.throw(
36+
t.RuntimeTypeError,
37+
`Value must be true or false
38+
39+
Expected: boolean
40+
41+
Actual Value: []
42+
43+
Actual Type: Array`
44+
)
45+
})
46+
})
47+
48+
describe(`t.boolean(literal)`, function() {
49+
it(`accepts literal value`, function() {
50+
t.boolean(true).assert(true)
51+
t.boolean(false).assert(false)
52+
expect(t.boolean(true).accepts(true)).to.be.true
53+
expect(t.boolean(false).accepts(false)).to.be.true
54+
})
55+
it(`rejects everything else`, function() {
56+
expect(t.boolean(true).accepts(false)).to.be.false
57+
expect(t.boolean(false).accepts(true)).to.be.false
58+
expect(t.boolean(false).accepts(2)).to.be.false
59+
expect(t.boolean(false).accepts('foo')).to.be.false
60+
expect(t.boolean(false).accepts([])).to.be.false
61+
expect(() => t.boolean(true).assert(false)).to.throw(
62+
t.RuntimeTypeError,
63+
`Value must be true
64+
65+
Expected: true
66+
67+
Actual Value: false
68+
69+
Actual Type: boolean`
70+
)
71+
expect(() => t.boolean(false).assert(true)).to.throw(
72+
t.RuntimeTypeError,
73+
`Value must be false
74+
75+
Expected: false
76+
77+
Actual Value: true
78+
79+
Actual Type: boolean`
80+
)
81+
expect(() => t.boolean(true).assert(2)).to.throw(
82+
t.RuntimeTypeError,
83+
`Value must be true
84+
85+
Expected: true
86+
87+
Actual Value: 2
88+
89+
Actual Type: number`
90+
)
91+
expect(() => t.boolean(false).assert('foo')).to.throw(
92+
t.RuntimeTypeError,
93+
`Value must be false
94+
95+
Expected: false
96+
97+
Actual Value: "foo"
98+
99+
Actual Type: string`
100+
)
101+
})
102+
})

src/compareTypes.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ import SymbolLiteralType from './types/SymbolLiteralType'
1818
import SymbolType from './types/SymbolType'
1919
import TupleType from './types/TupleType'
2020
import UnionType from './types/UnionType'
21-
import VoidType from './types/VoidType'
2221
import Validation from './Validation'
2322
import RuntimeTypeError from './errorReporting/RuntimeTypeError'
24-
import './compareTypes'
2523

2624
export {
2725
Type,
@@ -44,7 +42,6 @@ export {
4442
SymbolType,
4543
TupleType,
4644
UnionType,
47-
VoidType,
4845
Validation,
4946
RuntimeTypeError,
5047
}

src/makeUnion.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/number.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as t from './'
2+
import { expect } from 'chai'
3+
4+
describe(`t.number`, function() {
5+
it(`accepts numbers`, function() {
6+
t.number().assert(5)
7+
t.number().assert(-2)
8+
})
9+
it(`rejects everything else`, function() {
10+
expect(() => t.number().assert(true)).to.throw(
11+
t.RuntimeTypeError,
12+
`Value must be a number
13+
14+
Expected: number
15+
16+
Actual Value: true
17+
18+
Actual Type: boolean`
19+
)
20+
expect(() => t.number().assert('foo')).to.throw(
21+
t.RuntimeTypeError,
22+
`Value must be a number
23+
24+
Expected: number
25+
26+
Actual Value: "foo"
27+
28+
Actual Type: string`
29+
)
30+
})
31+
})
32+
33+
describe(`t.number(literal)`, function() {
34+
it(`accepts literal value`, function() {
35+
t.number(2).assert(2)
36+
t.number(15).assert(15)
37+
})
38+
it(`rejects everything else`, function() {
39+
expect(() => t.number(2).assert(3)).to.throw(
40+
t.RuntimeTypeError,
41+
`Value must be exactly 2
42+
43+
Expected: 2
44+
45+
Actual Value: 3
46+
47+
Actual Type: number`
48+
)
49+
expect(() => t.number(2).assert('foo')).to.throw(
50+
t.RuntimeTypeError,
51+
`Value must be exactly 2
52+
53+
Expected: 2
54+
55+
Actual Value: "foo"
56+
57+
Actual Type: string`
58+
)
59+
})
60+
})

src/string.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as t from './'
2+
import { expect } from 'chai'
3+
4+
describe(`t.string`, function() {
5+
it(`accepts strings`, function() {
6+
t.string().assert('foo')
7+
t.string().assert('')
8+
})
9+
it(`rejects everything else`, function() {
10+
expect(() => t.string().assert(true)).to.throw(
11+
t.RuntimeTypeError,
12+
`Value must be a string
13+
14+
Expected: string
15+
16+
Actual Value: true
17+
18+
Actual Type: boolean`
19+
)
20+
expect(() => t.string().assert(2)).to.throw(
21+
t.RuntimeTypeError,
22+
`Value must be a string
23+
24+
Expected: string
25+
26+
Actual Value: 2
27+
28+
Actual Type: number`
29+
)
30+
})
31+
})
32+
33+
describe(`t.string(literal)`, function() {
34+
it(`accepts literal value`, function() {
35+
t.string('foo').assert('foo')
36+
t.string('').assert('')
37+
})
38+
it(`rejects everything else`, function() {
39+
expect(() => t.string('foo').assert('bar')).to.throw(
40+
t.RuntimeTypeError,
41+
`Value must be exactly "foo"
42+
43+
Expected: "foo"
44+
45+
Actual Value: "bar"
46+
47+
Actual Type: string`
48+
)
49+
expect(() => t.string('foo').assert(3)).to.throw(
50+
t.RuntimeTypeError,
51+
`Value must be exactly "foo"
52+
53+
Expected: "foo"
54+
55+
Actual Value: 3
56+
57+
Actual Type: number`
58+
)
59+
})
60+
})

0 commit comments

Comments
 (0)