2021-03-29 01:11:44 +00:00
|
|
|
/**
|
|
|
|
* 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';
|
2024-06-13 02:19:25 +00:00
|
|
|
import * as P from '../src/internal/core';
|
2021-03-29 01:11:44 +00:00
|
|
|
|
2021-03-30 01:02:22 +00:00
|
|
|
describe('#NodeType', () => {
|
2023-02-04 00:30:39 +00:00
|
|
|
test('returns node that has sprcified type', () => {
|
2021-03-30 01:02:22 +00:00
|
|
|
const x = null as unknown as NodeType<'url'>;
|
2021-03-29 01:11:44 +00:00
|
|
|
expectType<MfmUrl>(x);
|
2021-03-29 01:14:23 +00:00
|
|
|
});
|
2021-03-29 01:11:44 +00:00
|
|
|
});
|
2024-06-13 02:19:25 +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]));
|
|
|
|
});
|
|
|
|
});
|