Algorithm-ToNumberMunger

 view release on metacpan or  search on metacpan

t/mungers-plan.t  view on Meta::CPAN

			mungers => {
				g => {
					munger => 'chain',
					from   => 'src',
					steps  => [ { op => 'trim' } ],
					then   => { munger => 'log' },
					into   => ['a'],
				}
			},
		);
	};
	like( $@, qr/does not support\s+multiple outputs/, 'chain-multi rejects a scalar-only terminal' );
}

# ---- a set with no mungers is all-raw --------------------------------------
{
	my $raw = $M->compile( tags => [qw(a b)] );
	is_deeply( $raw->apply_named( { a => 1, b => 2 } ), [ 1, 2 ], 'no-munger named' );
	is_deeply( $raw->apply_positional( [ 3, 4 ] ),      [ 3, 4 ], 'no-munger positional' );
}

# ---- compile-time coverage validation --------------------------------------
{
	# two mungers claim the same column
	eval {
		$M->compile(
			tags    => ['x'],
			mungers => {
				x => { munger => 'log' },
				g => {
					munger => 'datetime',
					format => $FMT,
					parts  => ['epoch'],
					into   => ['x']
				},
			},
		);
	};
	like( $@, qr/two mungers write column 'x'/, 'rejects overlapping claims' );

	# into names an unknown column
	eval {
		$M->compile(
			tags    => ['a'],
			mungers => {
				g => {
					munger => 'datetime',
					format => $FMT,
					parts  => ['epoch'],
					into   => ['nope']
				}
			},
		);
	};
	like( $@, qr/unknown column 'nope'/, 'rejects into on an unknown column' );

	# a key that is neither a tag nor an expander
	eval { $M->compile( tags => ['a'], mungers => { zzz => { munger => 'log' } } ) };
	like( $@, qr/is not a declared tag and has no 'into'/, 'rejects orphan key' );

	# parts / into length mismatch
	eval {
		$M->compile(
			tags    => [qw(a b)],
			mungers => {
				g => {
					munger => 'datetime',
					format => $FMT,
					parts  => [qw(sin_week cos_week)],
					into   => ['a']
				}
			},
		);
	};
	like( $@, qr/produces 2 value\(s\) but 'into' lists 1/, 'rejects parts/into arity mismatch' );

	# into on a munger that cannot fan out
	eval { $M->compile( tags => ['a'], mungers => { g => { munger => 'log', into => ['a'] } }, ); };
	like( $@, qr/does not support multiple outputs/, 'rejects into on a single-output munger' );

	# scalar build path refuses 'parts'
	eval { $M->build( { munger => 'datetime', format => $FMT, parts => ['epoch'] } ) };
	like( $@, qr/'parts' is for the multi-output form/, 'scalar datetime rejects parts without into' );
}

done_testing;



( run in 1.548 second using v1.01-cache-2.11-cpan-6aa56a78535 )