#* @test logical.vm This template is used for Velocity regression testing. If you alter this template make sure you change the corresponding comparison file so that the regression test doesn't fail incorrectly. *# #set($foo = 5) #if ($foo > 1) \$foo is greater then 1 #end #if ($foo < 10) \$foo is less than 10 #end #if ($foo >= 5) \$foo is great than or equal to 5 #end #if ($foo <= 5) \$foo is less than or equal to 5 #end #set($foo = false) #if (!($foo == true)) foo is false #end -- #set ($foo = 49/2) #set ($bar = 10) #if ($foo > $bar) \$foo is greater than \$bar #end #if ($foo >= $bar) \$foo is greater than or equal to \$bar #end #if ($bar < $foo) \$bar is less than \$foo #end #if ($bar <= $foo) \$bar is less than or equal to \$foo #end -- #set ($foo = 49/2) #set ($bar = 10) #if ($foo > $bar) \$foo is greater than \$bar #end #if ($foo >= $bar) \$foo is greater than or equal to \$bar #end #if ($bar < $foo) \$bar is less than \$foo #end #if ($bar <= $foo) \$bar is less than or equal to \$foo #end -- #set ($foo = 3) #set ($bar = 4) #if ($foo == $foo) \$foo is equal to \$foo #end #if ($foo != $bar) \$foo is not equal to \$bar #end -- #set ($foo = 888) #set ($bar = 1111) #set ($abc = $templatenumber1.AsNumber) #if ($templatenumber1 > $foo) \$templatenumber1 is greater than \$foo #end #if ($templatenumber1 >= $foo) \$templatenumber1 is greater than or equal to \$foo #end #if ($foo < $templatenumber1) \$foo is less than \$templatenumber1 #end #if ($foo <= $templatenumber1) \$foo is less than or equal to \$templatenumber1 #end -- #if ($bar > $templatenumber1) \$bar is greater than \$templatenumber1 #end #if ($bar >= $templatenumber1) \$bar is greater than or equal to \$templatenumber1 #end #if ($templatenumber1 < $bar) \$templatenumber1 is less than \$bar #end #if ($templatenumber1 <= $bar) \$templatenumber1 is less than or equal to \$bar #end -- #if ($abc == $templatenumber1) \$abc is equal to \$templatenumber1 #end #if ($templatenumber1 == $abc) \$templatenumber1 is equal to \$abc #end #if ($bar != $templatenumber1) \$bar is not equal to \$templatenumber1 #end #if ($templatenumber1 != $bar) \$templatenumber1 is not equal to \$bar #end -- #set($t = true) #set($f = false) Logical OR : #if($t || $f) right #else wrong #end #if( !($f || $t) ) wrong #else right #end #if( $null || $t ) right #else wrong #end #if( $t || $null ) right #else wrong #end #if( $f || $null) wrong #else right #end #if( $null || $null ) wrong #else right #end Logical AND : #if( $t && $t) right #else wrong #end #if( $f && $f ) wrong #else right #end #if( !($f && $f) ) right #else wrong #end #if( $t && $f ) wrong #else right #end #if( $t && $null ) wrong #else right #end #if( $null && $t ) wrong #else right #end #if( $f && $null ) wrong #else right #end #if( !($null && $null) ) right #else wrong #end ---------- equivalence ----------- #set($int = 1) #set($str = "str") #set($bool = true) #if( $int == $str) wrong #else right #end #if( $int == 1 ) right #else wrong #end #if ( $int == 2 ) wrong #else right #end #if( $str == 2 ) wrong #else right #end #if( $str == "str") right #else wrong #end #if( $str == $nonexistantreference ) wrong #else right #end #if( $str == $bool ) wrong #else right #end #if ($bool == true ) right #else wrong #end #if( $bool == false ) wrong #else right #end ----------- comparisons ----------- #set($int = 1) #set($str = "str") #set($bool = true) #if( $int > 0 ) right #else wrong #end #if( $str > 0 ) wrong #else right #end #if( $nonexistant > 0 ) wrong #else right #end #if( $int >= 0 ) right #else wrong #end #if( $str >= 0 ) wrong #else right #end #if( $nonexistant >= 0 ) wrong #else right #end #if( $int < 10 ) right #else wrong #end #if( $str < 10 ) wrong #else right #end #if( $nonexistant < 10 ) wrong #else right #end #if( $int <= 10 ) right #else wrong #end #if( $str <= 10 ) wrong #else right #end #if( $nonexistant <= 10 ) wrong #else right #end ---------------------- goofy but legal stuff ---------------------- #set($lala = ( false || true ) ) Should equal true : $lala #set($fofo = ( true && true ) ) Should equal true : $fofo #set($fofo = ( true && ( false || true ) ) ) Should equal true : $fofo #set($fofo = ( ($t || $f) && $t)) Should equal true : $fofo ---------------------- Compare String and StringBuffer ---------------------- #set($compClass = ($name == $name2)) This should be true: $compClass #set($compClass2 = ($name == $name3)) This should be false: $compClass2 #set($compClass3 = ($name != $name3)) This should be true: $compClass3 #set($x = !true) #if($x == false) right #else wrong #end #set($y = !$x) #if($y == true) right #else wrong #end Test to see if we can do logical assignment from any expression #set($val = (3 == 3)) #if($val == true) right #else wrong #end #set($val = (1 < 2)) #if( $val == true) right #else wrong #end #set($val = (1 <= 2)) #if( $val == true) right #else wrong #end #set($val = (7 > 2)) #if( $val == true) right #else wrong #end #set($val = (7 >= 2)) #if( $val == true) right #else wrong #end #set($val = ( 1 != 2)) #if( $val == true) right #else wrong #end ## check empty if statement is ok #if( true )#end