Skip to content

Commit

Permalink
test: test both number[] and never[]
Browse files Browse the repository at this point in the history
  • Loading branch information
crishoj committed Aug 7, 2024
1 parent 2acdb89 commit 0234d2b
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions tests/random/draw.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@ import * as _ from 'radashi'
import { expectTypeOf } from 'vitest'

describe('draw types', () => {
test('returns null given empty input', () => {
const list: unknown[] = []
const result = _.draw(list)
expect(result).toBeNull()
})
test('return type is null for empty array literal', () => {
test('return type with literal argument', () => {
expectTypeOf(_.draw([])).toBeNull()
})
test('return type is not null for non-empty array literal', () => {
expectTypeOf(_.draw([1, 2, 3])).toBeNumber()
})
test('return type is possibly null for mutable array variables', () => {
test('return type with mutable variable', () => {
const neverList: never[] = []
const emptyList: number[] = []
const filledList = [1, 2, 3]

expectTypeOf(_.draw(neverList)).toEqualTypeOf<null>()
expectTypeOf(_.draw(emptyList)).toEqualTypeOf<number | null>()
expectTypeOf(_.draw(filledList)).toEqualTypeOf<number | null>()
})
test('return type is possibly null for immutable empty array variables', () => {
test('return type with immutable variable', () => {
const neverList: never[] = [] as const
const emptyList: number[] = [] as const
// FIXME: Can be narrowed to `null`
const filledList = [1, 2, 3] as const

expectTypeOf(_.draw(neverList)).toBeNull()
// FIXME: Can this be narrowed to `null`?
expectTypeOf(_.draw(emptyList)).toEqualTypeOf<number | null>()
})
test('return type is not null for immutable non-empty array variables', () => {
const filledList = [1, 2, 4] as const
expectTypeOf(_.draw(filledList)).toEqualTypeOf<1 | 2 | 4>()
expectTypeOf(_.draw(filledList)).toEqualTypeOf<1 | 2 | 3>()
})
})

0 comments on commit 0234d2b

Please sign in to comment.