use strict;

# tests for the correct expansion of SWITCH

package Fn_SWITCH;

use FoswikiFnTestCase;
our @ISA = qw( FoswikiFnTestCase );

use Foswiki;
use Error qw( :try );

sub new {
    my $self = shift()->SUPER::new( 'SWITCH', @_ );
    return $self;
}

#b postpone Fn_SWITCH::test_basics
sub test_basics {
    my $this = shift;
    my ($text, $result);


    $text = <<PONG;
%SWITCH{ "Fribble" equals1="Fribble" result1="hello"}%
PONG
    $result = $this->{test_topicObject}->expandMacros($text);
    $this->assert_equals( <<THIS, $result );
hello
THIS

    $text = <<PONG;
%SWITCH{ "Fribble" equals1="Fribbl" result1="hello" equals2="Fribble" result2="goodbye"}%
PONG
    $result = $this->{test_topicObject}->expandMacros($text);
    $this->assert_equals( <<THIS, $result );
goodbye
THIS

    $text = <<PONG;
%SWITCH{ "Fribbley" equals1="Fribbl" result1="hello" equals2="Fribble" result2="goodbye"}%
PONG
    $result = $this->{test_topicObject}->expandMacros($text);
    $this->assert_equals( <<THIS, $result );
Fribbley
THIS

    $text = <<PONG;
%SWITCH{ "Fribble" equals1="Fribbl" result1="hello" equals2="Fribble" result2="goodbye" default="DDD"}%
PONG
    $result = $this->{test_topicObject}->expandMacros($text);
    $this->assert_equals( <<THIS, $result );
goodbye
THIS

    $text = <<PONG;
%SWITCH{ "Fribblex" equals1="Fribbl" result1="hello" equals2="Fribble" result2="goodbye" default="DDD"}%
PONG
    $result = $this->{test_topicObject}->expandMacros($text);
    $this->assert_equals( <<THIS, $result );
DDD
THIS

}

sub test_if {
    my $this = shift;
    my ($text, $result);

    $text = <<'PONG';
%SWITCH{ "Fribble" if1="'Fribble' = '$switch'" result1="hello $switch"}%
PONG
    $result = $this->{test_topicObject}->expandMacros($text);
    $this->assert_equals( <<THIS, $result );
hello Fribble
THIS
}

sub test_resulteval {
    my $this = shift;
    my ($text, $result);

    $text = <<'PONG';
%SWITCH{ "FribbleFrotz" equals1="FribbleFrotz" result1="$percntSPACEOUT{\"$switch\"}$percnt"}%
PONG
    $result = $this->{test_topicObject}->expandMacros($text);
    $this->assert_equals( <<THIS, $result );
Fribble Frotz
THIS
}


1;

=head CUT







sub xtest_SWITCH {
    my $this = shift;

    my ($topicObject) =
      Foswiki::Func::readTopic( $this->{test_web}, "DeadHerring" );
    $topicObject->text( <<'SMELL');
%META:FORM{name="BleaghForm"}%
%META:FIELD{name="Wibble" title="Wobble" value="Woo"}%
SMELL
    $topicObject->save();

    my $text = <<PONG;
%SWITCH{ "Fribble" equals1="Fribble" result1="hello"}%
PONG
    my $result = $this->{test_topicObject}->expandMacros($text);
    $this->assert_equals( <<THIS, $result );
hello
THIS
    $topicObject->finish();
}

1;
