mirror of
https://git.proxmox.com/git/perlmod
synced 2025-10-04 20:11:21 +00:00
test for broken undef detection
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
4c9f6c51d7
commit
93eaead22a
@ -9,3 +9,6 @@ mod pkginline;
|
||||
|
||||
/// A test for blessed values.
|
||||
mod bless;
|
||||
|
||||
/// Tests for `Option`.
|
||||
mod option;
|
||||
|
19
perlmod-test/src/option.rs
Normal file
19
perlmod-test/src/option.rs
Normal file
@ -0,0 +1,19 @@
|
||||
#[perlmod::package(name = "RSPM::Option", lib = "perlmod_test")]
|
||||
mod export {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct WithOption {
|
||||
tristate: Option<bool>,
|
||||
}
|
||||
|
||||
#[export]
|
||||
pub fn to_string(tristate: Option<bool>) -> String {
|
||||
format!("{:?}", tristate)
|
||||
}
|
||||
|
||||
#[export]
|
||||
pub fn struct_to_string(with_option: WithOption) -> String {
|
||||
format!("{:?}", with_option.tristate)
|
||||
}
|
||||
}
|
26
test.pl
26
test.pl
@ -5,6 +5,7 @@ use v5.28.0;
|
||||
use lib '.';
|
||||
use RSPM::Bless;
|
||||
use RSPM::Foo142;
|
||||
use RSPM::Option;
|
||||
|
||||
my $v = RSPM::Bless->new("Hello");
|
||||
$v->something();
|
||||
@ -40,3 +41,28 @@ my $b = RSPM::Foo142::test_serde($a);
|
||||
print $b;
|
||||
my $c = RSPM::Foo142::test_serde($b);
|
||||
print $c;
|
||||
|
||||
sub to_string {
|
||||
my ($param) = @_;
|
||||
|
||||
my $state = $param->{tristate};
|
||||
$state = int($state) if defined($state);
|
||||
|
||||
my $a;
|
||||
if (defined($state)) {
|
||||
$a = $state ? "Some(true)" : "Some(false)";
|
||||
} else {
|
||||
$a = "None";
|
||||
}
|
||||
|
||||
my $b = RSPM::Option::to_string($state);
|
||||
my $c = RSPM::Option::struct_to_string({ 'tristate' => $state });
|
||||
|
||||
print "$a\n";
|
||||
print "$b\n";
|
||||
print "$c\n";
|
||||
}
|
||||
|
||||
to_string({ 'tristate' => '0' });
|
||||
to_string({ 'tristate' => '1' });
|
||||
to_string({ 'tristate' => undef });
|
||||
|
@ -19,3 +19,12 @@ Can I have some coffee please?
|
||||
Can I have some ☕ please?
|
||||
Can I have some ☕ please?
|
||||
Can I have some ☕ please?
|
||||
Some(false)
|
||||
Some(false)
|
||||
Some(false)
|
||||
Some(true)
|
||||
Some(true)
|
||||
Some(true)
|
||||
None
|
||||
None
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user