Astro-App-Satpass2

 view release on metacpan or  search on metacpan

t/format_template.t  view on Meta::CPAN

package main;

use 5.008;

use strict;
use warnings;

use Test2::V0;
use Astro::App::Satpass2::Format::Template;
use Astro::Coord::ECI 0.077;
use Astro::Coord::ECI::Moon 0.077;
use Astro::Coord::ECI::Sun 0.077;
use Astro::Coord::ECI::TLE 0.077 qw{ :constants };
use Astro::Coord::ECI::Utils 0.112 qw{ deg2rad greg_time_gm };
use Cwd ();
use Time::Local;

use lib qw{ inc };

use My::Module::Test::App;	# For environment clean-up.

{
    local $@ = undef;

    use constant HAVE_TLE_IRIDIUM	=> eval {
	require Astro::Coord::ECI::TLE::Iridium;
	Astro::Coord::ECI::TLE::Iridium->VERSION( 0.077 );
	1;
    } || 0;
}

use constant APRIL_FOOL_2023	=> greg_time_gm( 0, 0, 0, 1, 3, 2023 );
use constant FORMAT_VALUE	=> 'Astro::App::Satpass2::FormatValue';

my $mocker = setup_app_mocker;
my $app = Astro::App::Satpass2->new();

my $sta = Astro::Coord::ECI->new()->geodetic(
    deg2rad( 38.898748 ),
    deg2rad( -77.037684 ),
    16.68 / 1000,
)->set( name => '1600 Pennsylvania Ave NW Washington DC 20502' );
my $sun = Astro::Coord::ECI::Sun->new();
my $moon = Astro::Coord::ECI::Moon->new();
# The following TLE is from
# SPACETRACK REPORT NO. 3
# Models for Propagation of NORAD Element Sets
# Felix R. Hoots and Ronald L. Roehrich
# December 1980
# Compiled by TS Kelso
# 31 December 1988
# Obtained from celestrak.com
# NASA line added by T. R. Wyant
my ( $sat ) = Astro::Coord::ECI::TLE->parse( <<'EOD' );
None
1 88888U          80275.98708465  .00073094  13844-3  66816-4 0    8
2 88888  72.8435 115.9689 0086731  52.6988 110.5714 16.05824518  105
EOD

HAVE_TLE_IRIDIUM and $sat->rebless( 'iridium' );

my $ft = Astro::App::Satpass2::Format::Template->new(
    parent	=> $app,
)->gmt( 1 );

# Encapsulation violation. The _uniq() subroutine may be moved or
# retracted without notice of any kind.

is
    [ Astro::App::Satpass2::Format::Template::_uniq(
	    qw{ Able was I ere I saw Elba } ) ],
    [ qw{ Able was I ere saw Elba } ],
    'Check our implementation of uniq()';

ok $ft, 'Instantiate Astro::App::Satpass2::Format::Template';

sub april_fool {
    my ( undef, $hash ) = @_;
    $hash ||= {};
    $hash->{time} = APRIL_FOOL_2023;
    return $hash;
}

ok $ft->template( fubar => <<'EOD' ), 'Can set custom template';
Able was [% arg.0 %] ere [% arg.0 %] saw Elba
EOD

is $ft->template( 'fubar' ), <<'EOD', 'Can get same template back';
Able was [% arg.0 %] ere [% arg.0 %] saw Elba
EOD

is $ft->format(
    template	=> 'fubar',
    arg		=> [ 'I' ],
), <<'EOD', 'Can use custom template';
Able was I ere I saw Elba
EOD

is $ft->format(
    template	=> 'almanac',
    data	=> [ {
		almanac	=> {
		    description	=> 'Moon rise',
		    detail		=> 1,
		    event		=> 'horizon',
		},



( run in 0.966 second using v1.01-cache-2.11-cpan-99c4e6809bf )