package TestCase::Switch {
  
  # Switch - nest
  sub switch_nest : int () {
    my $success1 : int;
    switch (3) {
      case 1:
        $success1 = 0;
        last;
      case 3:
        switch (5) {
          case 2:
            $success1 = 0;
            last;
          case 5:
            $success1 = 1;
            last;
          case 6:
            $success1 = 0;
            last;
          default:
            $success1 = 0;
            last;
        }
        last;
      case 10000:
        $success1 = 0;
        last;
      default:
    }
    
    return $success1;
  }
  
  # Switch - lookup switch
  sub switch_lookup_switch : int () {
    my $success1 : int;
    switch (1) {
      case 1:
        $success1 = 1;
        last;
      case 3:
        $success1 = 0;
        last;
      case 10000:
        $success1 = 0;
        last;
      default:
    }
    my $success2 : int;
    switch (3) {
      case 1:
        $success2 = 0;
        last;
      case 3:
        $success2 = 1;
        last;
      case 10000:
        $success2 = 0;
        last;
      default:
    }
    my $success3 : int;
    switch (10000) {
      case 3:
        $success3 = 0;
        last;
      case 1:
        $success3 = 0;
        last;
      case 10000:
        $success3 = 1;
        last;
      default:
    }
    my $success4 : int;
    switch (2) {
      case 1:
        last;
      case 3:
        last;
      case 10000:
        last;
      default:
        $success4 = 1;
    }
    
    if ($success1) {
      if ($success2) {
        if ($success3) {
          if ($success4) {
            return 1;
          }
        }
      }
    }
    return 0;
  }
  
  # Switch - table switch
  sub switch_table_switch : int () {
    my $success1 : int;
    
    switch(3) {
      case 3:
        $success1 = 1;
        last;
      case 4:
        $success1 = 0;
        last;
      case 5:
        $success1 = 0;
        last;
      default:
    }

    my $success2 : int;
    switch(4) {
      case 3:
        $success2 = 0;
        last;
      case 4:
        $success2 = 1;
        last;
      case 5:
        $success2 = 0;
        last;
      default:
    }
    my $success3 : int;
    switch(10) {
      case 3:
        $success3 = 0;
        last;
      case 4:
        $success3 = 0;
        last;
      case 5:
        $success3 = 0;
        last;
      default:
        $success3 = 1;
    }
    
    if ($success1) {
      if ($success2) {
        if ($success3) {
          return 1;
        }
      }
    }
    
    return 0;
  }
}
