App-orgdaemon

 view release on metacpan or  search on metacpan

t/org2ical.t  view on Meta::CPAN

CALSCALE:GREGORIAN
PRODID:-//Slaven Rezic//NONSGML rezic.de org2ical 0.00//EN
BEGIN:VEVENT
UID:Blcatps/EWPbXGJBkLi7Iw\@example.org
DTSTART:99990101T000000
CREATED:19700101T000000Z
DTSTAMP:19700101T000000Z
LAST-MODIFIED:19700101T000000Z
SUMMARY:normal date
TRANSP:OPAQUE
DESCRIPTION:Initial details.\\n
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Reminder
TRIGGER:-PT30M
UID:ALARM-Blcatps/EWPbXGJBkLi7Iw\@example.org
END:VALARM
END:VEVENT
END:VCALENDAR
EOF
    }

    {
	my $success = run [@full_script, '--domain-id=example.org', "--todo-file=$dir/test.org", "--ics-file=$dir/test.ics"];
	ok $success, 'run on existing .ics file, no changes';
	my $ics_contents = slurp "$dir/test.ics";
	is $original_ics_contents, $ics_contents, 'no changes on 2nd run';
    }

    {
	open my $ofh, '>:encoding(utf-8)', "$dir/test.org" or die $!;
	print $ofh <<EOF;
* TODO normal date :tag: <9999-01-01 Fr 00:00>
  Changes details.
EOF
	close $ofh or die $!;
    }

    {
	my $success = run [@full_script, '--domain-id=example.org', "--todo-file=$dir/test.org", "--ics-file=$dir/test.ics"];
	ok $success, 'run on existing .ics file, with changes';
	my $ics_contents = slurp "$dir/test.ics";
	like $ics_contents, qr{Changes details}, 'details changed in ics file';
    }

    {
	open my $ofh, '>:encoding(utf-8)', "$dir/test.org" or die $!;
	print $ofh <<EOF;
* TODO normal date :tag: <9999-01-02 Fr 00:00>
  A new date.
EOF
	close $ofh or die $!;
    }

    {
	my $success = run [@full_script, '--debug', '--domain-id=example.org', "--todo-file=$dir/test.org", "--ics-file=$dir/test.ics"], '>', \my $stdout, '2>', \my $stderr;
	ok $success, 'run on existing .ics file, changed date';
	my $ics_contents = slurp "$dir/test.ics";
	isnt $original_ics_contents, $ics_contents, 'changes in ics file';
	if ($stderr !~ m{but no diff available}) {
	    like $stdout, qr{^--- org2ical.t-.*/test.ics}, 'looks like a diff header';
	    like $stdout, qr{^-UID:Blcatps/EWPbXGJBkLi7Iw\@example.org}m, 'an expected diff line';
	}
    }

    {
	open my $ofh, '>:encoding(utf-8)', "$dir/test.org" or die $!;
	print $ofh <<EOF;
* TODO normal date :positivetag: <9999-01-01 Fr 00:00>
  Changes details.
EOF
	close $ofh or die $!;
    }

    for my $def (
	[["--include-tags", "doesnotexist"], 0 ],
	[["--include-tags", "positivetag"], 1 ],
	[["--exclude-tags", "doesnotexist"], 1 ],
	[["--exclude-tags", "positivetag"], 0 ],
    ) {
	my($tag_options, $match) = @$def;
	unlink "$dir/test.ics";
	my $success = run [@full_script, "--todo-file=$dir/test.org", "--ics-file=$dir/test.ics", @$tag_options];
	ok $success, "run with @$tag_options";
	my $ics_contents = slurp "$dir/test.ics";
	if ($match) {
	    like $ics_contents, qr{BEGIN:VEVENT}, "match for '@$tag_options' expected";
	} else {
	    unlike $ics_contents, qr{BEGIN:VEVENT}, "no match for '@$tag_options' expected";
	}
    }

    {
	# geo:...
	for my $def (
	    ['[[geo:52.51451,13.35011?z=19]]', 'https://www.openstreetmap.org/?mlat=52.51451&mlon=13.35011#map=19/52.51451/13.35011'],
	    ["[[geo:52.51451,13.35011?z=19][Siegess\xe4ule Berlin]]", "https://www.openstreetmap.org/?mlat=52.51451&mlon=13.35011#map=19/52.51451/13.35011 (Siegess\xc3\xa4ule Berlin)"],
	    ['[[geo:-22.9680,-43.1748]]',      'https://www.openstreetmap.org/?mlat=-22.9680&mlon=-43.1748#map=15/-22.9680/-43.1748'], # negative lat/lon + missing zoom
	) {
	    my($geo_osm_link, $osm_url) = @$def;

	    {
		open my $ofh, '>:encoding(utf-8)', "$dir/test.org" or die $!;
		print $ofh <<EOF;
* TODO date with geo location <9999-01-01 Fr 00:00>
  Location: $geo_osm_link
EOF
		close $ofh or die $!;
	    }

	    {
		my $success = run [@full_script, '--domain-id=example.org', "--todo-file=$dir/test.org", "--ics-file=$dir/test.ics"];
		ok $success, 'org-mode file with geo location';
	    }

	    {
		my $ics_contents = slurp "$dir/test.ics";
		like $ics_contents, qr{\Q$osm_url}, 'found converted OSM URL';
	    }
	}
    }



( run in 1.749 second using v1.01-cache-2.11-cpan-39bf76dae61 )