Data-Random-String-Matches
view release on metacpan or search on metacpan
#!/usr/bin/env perl
use strict;
use warnings;
use IPC::Run3;
use File::Temp qw(tempfile);
use Test::Most;
# Check if bin/random-string exists
my $cli = 'bin/random-string';
unless (-f $cli) {
plan skip_all => "CLI script not found at $cli";
}
# Make sure it's executable
chmod 0755, $cli;
sub run_cli {
my @args = @_;
my ($out, $err);
eval {
run3([$^X, $cli, @args], \undef, \$out, \$err);
};
return {
stdout => $out // '',
stderr => $err // '',
exit => $? >> 8,
error => $@,
};
}
# Test basic generation
subtest 'Basic generation' => sub {
my $result = run_cli('\d{4}');
is($result->{exit}, 0, 'Exits successfully');
like($result->{stdout}, qr/^\d{4}$/, 'Generates 4 digits');
is($result->{stderr}, '', 'No error output');
};
# Test multiple generation
subtest 'Multiple generation' => sub {
my $result = run_cli('-c', '3', '\d{2}');
is($result->{exit}, 0, 'Exits successfully');
my @lines = split /\n/, $result->{stdout};
is(scalar @lines, 3, 'Generates 3 strings');
for my $line (@lines) {
like($line, qr/^\d{2}$/, "Line matches pattern: $line");
}
};
# Test custom separator
subtest 'Custom separator' => sub {
my $result = run_cli('-c', '3', '-S', ', ', '[A-Z]');
is($result->{exit}, 0, 'Exits successfully');
like($result->{stdout}, qr/^[A-Z], [A-Z], [A-Z]/, 'Uses custom separator');
};
# Test smart mode
subtest 'Smart mode' => sub {
my $result = run_cli('--smart', '[A-Z]{3}\d{4}');
is($result->{exit}, 0, 'Exits successfully');
like($result->{stdout}, qr/^[A-Z]{3}\d{4}$/, 'Smart mode works');
};
# Test help option
subtest 'Help option' => sub {
my $result = run_cli('--help');
like($result->{stdout}, qr/Usage:/, 'Shows usage');
( run in 0.827 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )