File: 01_data.t

package info (click to toggle)
libfile-desktopentry-perl 0.22-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 196 kB
  • sloc: perl: 434; makefile: 2
file content (119 lines) | stat: -rw-r--r-- 3,107 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use strict;
use warnings;
use Test::More tests => 25;

use_ok('File::DesktopEntry');
$File::DesktopEntry::_locale = ''; # reset locale for testing

my $file = File::Spec->catfile(qw/t applications foo.desktop/);
my $entry = File::DesktopEntry->new($file);
is($$entry{file}, $file, 'new(FILE) works');

$entry = File::DesktopEntry->new_from_file($file);
is($$entry{file}, $file, 'new_from_file(FILE) works');

ok(! $$entry{groups}, 'no premature hashing');

is( $entry->get('Comment'),
       	'The best viewer for Foo objects available!',
	'get() works');

is( $entry->get('Comment[eo]'), 'Tekstredaktilo',
	'get() works with locale string' );

is( $entry->get('Comment[ja]'),
	"\x{30c6}\x{30ad}\x{30b9}\x{30c8}\x{30a8}\x{30c7}\x{30a3}\x{30bf}",
	'get() works with locale in utf8' );

is( $entry->get('Desktop Action Edit', 'Name'),
	'Foo Viewer (edit image)',
	'get() works with alternative group' );

is( $entry->get_value('Comment'),
       	'The best viewer for Foo objects available!',
	'get_value() works' );

is( $entry->get_value('Name', 'Desktop Action Edit'),
	'Foo Viewer (edit image)',
	'get_value() works with alternative group' );

is( $entry->get('Foo'), undef, 'Non-existing key');
is( $entry->get('Foo', 'Foo'), undef, 'Non-existing group');

my $buffer = <<EOF;
[Desktop Entry]
Name=Foo!
Type=Application

[Bar]
# Group with Bar data
baz=true
;
EOF

$entry = File::DesktopEntry->new_from_data($buffer);
#use Data::Dumper; warn Dumper $entry;
is($entry->get('Name'), 'Foo!', 'new_from_data() works');
is(scalar(@{$$entry{groups}}), 2, 'number of groups correct');
is($entry->text, $buffer, 'text() works');

my $i = 0;
for (
	['C' => ''],
	['lang_COUNTRY.enc@MOD' =>
		'lang_COUNTRY@MOD|lang_COUNTRY|lang@MOD|lang'],
	['lang_COUNTRY.enc' => 'lang_COUNTRY|lang'],
	['lang@MOD'         => 'lang@MOD|lang'],
	['lang'             => 'lang']
) {
	++$i;
	is( File::DesktopEntry::_parse_lang($$_[0]), $$_[1],
		"language parsing $i");
}
$entry->set('Name[nl]' => 'dus ja');
is($entry->get('Name[nl_BE]'), 'dus ja', 'language parsing in get()');

$entry->set('Name[C]' => 'Something new');
is($entry->get('Name[POSIX]'), 'Something new', 'Aliases for default locale');

$ENV{XDG_DATA_HOME} = 't';
$file = File::Spec->catfile(qw/t applications bar baz.desktop/);
$$entry{name} = 'bar-baz';
is($entry->_data_home_file, $file, 'correct file name generated');
rmdir( File::Spec->catdir(qw/t applications bar/) ); # clean up


$file = File::Spec->catfile('t', 'applications', 'bar.desktop');
$entry = File::DesktopEntry->new;
$entry->set(Type => 'Application', Name => 'Bar');
$entry->set('Some Action', Run => 'bar');
$entry->write($file);

$entry = File::DesktopEntry->new($file);
is($entry->text,
"[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=Bar

[Some Action]
Run=bar
",
'write/read');

unlink($file); # clean up

my $text =
"[Desktop Entry]
Version=1.0
Encoding=UTF-8
# the field below gives the name
Name=Bar

Type=Application
";
$entry = File::DesktopEntry->new(\$text);
$entry->set(Name => 'MyBar');
$text =~ s/Bar/MyBar/;
is($entry->text, $text, 'comments are preserved');