sfm-js/test-d/index.ts

31 lines
1 KiB
TypeScript
Raw Permalink Normal View History

/**
* Unit testing TypeScript types.
* with https://github.com/SamVerschueren/tsd
*/
import { expectType } from 'tsd';
2021-06-26 14:48:46 +00:00
import { NodeType, MfmUrl } from '../src';
import * as P from '../src/internal/core';
describe('#NodeType', () => {
2023-02-04 00:30:39 +00:00
test('returns node that has sprcified type', () => {
const x = null as unknown as NodeType<'url'>;
expectType<MfmUrl>(x);
2021-03-29 01:14:23 +00:00
});
});
describe('parser internals', () => {
test('seq', () => {
const first = null as unknown as P.Parser<'first'>;
const second = null as unknown as P.Parser<'second'>;
const third = null as unknown as P.Parser<'third' | 'third-second'>;
expectType<P.Parser<['first', 'second', 'third' | 'third-second']>>(P.seq(first, second, third));
});
test('alt', () => {
const first = null as unknown as P.Parser<'first'>;
const second = null as unknown as P.Parser<'second'>;
const third = null as unknown as P.Parser<'third' | 'third-second'>;
expectType<P.Parser<'first' | 'second' | 'third' | 'third-second'>>(P.alt([first, second, third]));
});
});