From a2855ff136611cedfac668f685902e3567240b57 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 24 Feb 2010 21:23:37 -0600 Subject: tests for preserving comments --- t/003-comments.t | 38 ++++++++++++++++++++++++++++++++++++++ t/data/003/de.po | 22 ++++++++++++++++++++++ t/data/003/en.po | 27 +++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 t/003-comments.t create mode 100644 t/data/003/de.po create mode 100644 t/data/003/en.po diff --git a/t/003-comments.t b/t/003-comments.t new file mode 100644 index 0000000..529791e --- /dev/null +++ b/t/003-comments.t @@ -0,0 +1,38 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use File::Temp; +use File::Copy; +use Path::Class; + +use Locale::POFileManager; + +{ + my $dir = File::Temp->newdir; + my $from_dir = dir('t/data/003'); + my $tmpdir = dir($dir->dirname); + for my $file ($from_dir->children) { + copy($file->stringify, $dir->dirname); + } + + my $manager = Locale::POFileManager->new( + base_dir => $dir->dirname, + canonical_language => 'en', + ); + $manager->add_stubs; + + is($tmpdir->file('en.po')->slurp, $from_dir->file('en.po')->slurp, + "canonical file untouched"); + + my $expected = $from_dir->file("de.po")->slurp; + my $got = $tmpdir->file("de.po")->slurp; + my $fixed = substr $got, 0, length($expected), ''; + is($fixed, $expected, "original part of the file wasn't touched"); + is(substr($got, 0, 1, ''), "\n", "spacing newline added properly"); + is_deeply([sort split /\n\n/, $got], + [qq{msgid "quuux"}, qq{msgid "quux"}], + "added the correct stubs"); +} + +done_testing; diff --git a/t/data/003/de.po b/t/data/003/de.po new file mode 100644 index 0000000..6e82f0d --- /dev/null +++ b/t/data/003/de.po @@ -0,0 +1,22 @@ +msgid "" +msgstr "" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# erste Kapitel + +msgid "foo" +msgstr "oof" + +# Übersetzung für bar +msgid "bar" +msgstr "rab" + +# zweite Kapitel + +msgid "baz" +msgstr "zab" + + +# etwas zu machen diff --git a/t/data/003/en.po b/t/data/003/en.po new file mode 100644 index 0000000..825f817 --- /dev/null +++ b/t/data/003/en.po @@ -0,0 +1,27 @@ +msgid "" +msgstr "" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# first section + +msgid "foo" +msgstr "foo" + +msgid "quux" +msgstr "quux" + +# stuff for bar +msgid "bar" +msgstr "bar" + +# second section + +msgid "baz" +msgstr "baz" + +msgid "quuux" +msgstr "quuux" + +# stuff to do -- cgit v1.2.3