]> git.proxmox.com Git - perlmod.git/blob - test.pl
add reference deserialization test data
[perlmod.git] / test.pl
1 #!/usr/bin/env perl
2
3 use v5.28.0;
4
5 use lib '.';
6 use RSPM::Bless;
7 use RSPM::Foo142;
8 use RSPM::Option;
9
10 STDOUT->autoflush;
11
12 my $v = RSPM::Bless->new("Hello");
13 $v->something();
14 $v->something_nonraw();
15 my ($a, $b, $c) = $v->multi_return();
16 say "Got ($a, $b, $c)";
17 my @ret = $v->multi_return();
18 say "Got: ".scalar(@ret)." values: @ret";
19
20 $v->another(54);
21
22 my $param = { a => 1 };
23 my $s = "Hello You";
24 print "These should be called with a valid substr:\n";
25 RSPM::Foo142::test(substr($s, 3, 3));
26 RSPM::Foo142::teststr(substr($s, 3, 3));
27 print "Parameter exists: " . (exists($param->{x}) ? "YES" : "NO") . "\n";
28 RSPM::Foo142::test($param->{x});
29 print "Was auto-vivified: " . (exists($param->{x}) ? "YES" : "NO") . "\n";
30 RSPM::Foo142::teststr($param->{x});
31
32 my $a = "Can I have some coffee please?\n";
33 print $a;
34 my $b = RSPM::Foo142::test_serde($a);
35 print $b;
36 my $c = RSPM::Foo142::test_serde($b);
37 print $c;
38
39 use utf8;
40 binmode STDOUT, ':utf8';
41 my $a = "Can I have some ☕ please?\n";
42 print $a;
43 my $b = RSPM::Foo142::test_serde($a);
44 print $b;
45 my $c = RSPM::Foo142::test_serde($b);
46 print $c;
47
48 sub to_string {
49 my ($param) = @_;
50
51 my $state = $param->{tristate};
52 $state = int($state) if defined($state);
53
54 my $a;
55 if (defined($state)) {
56 $a = $state ? "Some(true)" : "Some(false)";
57 } else {
58 $a = "None";
59 }
60
61 my $b = RSPM::Option::to_string($state);
62 my $c = RSPM::Option::struct_to_string({ 'tristate' => $state });
63
64 print "$a\n";
65 print "$b\n";
66 print "$c\n";
67 }
68
69 to_string({ 'tristate' => '0' });
70 to_string({ 'tristate' => '1' });
71 to_string({ 'tristate' => undef });
72
73 my $ref1 = { x => "x was stored" };
74 my $ref2 = RSPM::Foo142::test_refs({ copied => "copied string", reference => $ref1 });
75 print($ref1->{x}, "\n");
76 $ref2->{x} = "x was changed";
77 print($ref1->{x}, "\n");