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:
Fabian Ebner 2021-07-16 16:34:00 +02:00 committed by Wolfgang Bumiller
parent 4c9f6c51d7
commit 93eaead22a
4 changed files with 57 additions and 0 deletions

View File

@ -9,3 +9,6 @@ mod pkginline;
/// A test for blessed values.
mod bless;
/// Tests for `Option`.
mod option;

View 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
View File

@ -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 });

View File

@ -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