class TestCase::Operator::DefinedOr {
  
  use TestCase::Simple;
  
  static method defined_or : int () {
    
    {
      my $left = "true";
      my $right = "false";
      
      my $ret = $left // $right;
      
      unless ($ret == $left) {
        return 0;
      }
    }
    
    {
      my $left = (string)undef;
      my $right = "false";
      
      my $ret = $left // $right;
      
      unless ($ret == $right) {
        return 0;
      }
      
    }
    
    {
      my $ret = "true" // "false";
      
      unless ($ret eq "true") {
        return 0;
      }
    }
    
    {
      my $ret = (string)undef // "false";
      
      unless ($ret eq "false") {
        return 0;
      }
      
    }
    
    # https://github.com/yuki-kimoto/SPVM/issues/705
    {
      {
        my $simple = TestCase::Simple->new;
        $simple->{string_value} = $simple->{string_value} // "headers";
      }
      
      {
        my $simple = TestCase::Simple->new;
        my $tmp = ($simple->{string_value} = $simple->{string_value} // "headers");
        
        unless ($tmp eq "headers") {
          return 0;
        }
      }
    }
    
    {
      my $ret = (my $foo = Int->new(1)) // (my $bar = Int->new(2));
      
      unless ((int)$foo == 1) {
        return 0;
      }
      
    }
    
    {
      my $ret = (Int)undef // (my $bar = Int->new(2));
      
      unless ((int)$bar == 2) {
        return 0;
      }
      
    }
    
    return 1;
  }
  
}
