Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116/** Tests for function arity wrappers. @module */
import { describe, expect, expectTypeOf, it,} from '@monochromatic-dev/module-test/ts';
import { binary, unary,} from '@monochromatic-dev/module-function-arity';
await describe({ name: 'function-arity', children: [ describe({ name: unary.name, children: [ it({ name: 'forwards only first positional argument', fn: async () => { /** Radix presence values observed by wrapped parser. */ const observedRadixPresence: string[] = []; /** Parser that records whether iterator index reaches radix. */ const parseWithObservedRadix = ( value: string, radix?: number, ): number => { observedRadixPresence.push((radix === undefined) ? 'missing' : 'present',); return Number.parseInt( value, radix, ); };
/** Parsed values through unary wrapper. */ const parsed = ['10', '10', '10',].map(unary(parseWithObservedRadix,),);
expect(parsed,).toEqual([10, 10, 10,],); expect(observedRadixPresence,).toEqual(['missing', 'missing', 'missing',],); }, },), it({ name: 'preserves unary type shape', fn: async () => { /** Parser used for type inference. */ const parseWithOptionalRadix = ( value: string, radix?: number, ): number => Number.parseInt( value, radix, );
expectTypeOf(unary(parseWithOptionalRadix,),).toEqualTypeOf<( argument: string, ) => number>(); expectTypeOf(unary(Number.parseInt,),).toEqualTypeOf<( argument: string, ) => number>(); }, },), ], },), describe({ name: binary.name, children: [ it({ name: 'forwards only first two positional arguments', fn: async () => { /** Source collection presence values observed by wrapped renderer. */ const observedCollectionPresence: string[] = []; /** Renderer that records whether iterator source collection reaches callback. */ const renderWithObservedCollection = ( value: string, index: number, collection?: readonly string[], ): string => { observedCollectionPresence.push((collection === undefined) ? 'missing' : 'present',); return `${index}:${value}`; };
/** Rendered values through binary wrapper. */ const rendered = ['a', 'b',].map(binary(renderWithObservedCollection,),);
expect(rendered,).toEqual(['0:a', '1:b',],); expect(observedCollectionPresence,).toEqual(['missing', 'missing',],); }, },), it({ name: 'preserves binary type shape', fn: async () => { /** Renderer used for type inference. */ const renderWithOptionalCollection = ( value: string, index: number, _collection?: readonly string[], ): string => `${index}:${value}`;
expectTypeOf(binary(renderWithOptionalCollection,),).toEqualTypeOf<( firstArgument: string, secondArgument: number, ) => string>(); }, },), ], },), ],},);