# Stress for the command parser with the switch command


# A simple correct switch

echo Test 1.a: Passing "test" to the switch command

switch(test){
	case(text) echo Case label 1 : text
	case(test) echo Case label 2 : test
	default echo This is the default command
}

echo Test 1.a passed.

echo Test 1.b: Passing again "test" to the switch command ,but with spaces

switch(   test       ){
	case( text) echo Case label 1 : text
	case(      test      ){ echo Case label 2 : test; }
	default echo This is the default command
}

echo Test 1.b passed.

echo Test 2: Passing a strange empty string

switch(             \
					\
					\
					)
{
	case() {
			echo Executed correctly!
		# A comment
		# Another comment ; echo Executed \
correctly     ; #And yet another comment
	}
	case	\
		\
		\
	(Oops) echo Executed a forbidden command...
	default echo Wrong
}

echo Test 2 passed.

echo Test 3: Empty switches

switch(){}

echo Empty switch 1 OK

switch (\
)
{
}

echo Empty switch 2 OK

switch  (                              )        {                                            }

echo Empty switch 3 OK

echo Test 3 passed.

echo Test 4.a: With a tmp variable

%tmp = test_text

switch (%tmp)
{
	case (1) {
		echo It was 1... oops
		halt;
	}
	case (%tmp) {
		echo It was this = %tmp!
	}
	case () echo Wrong case!
	default {
		echo Default label
	}
}


echo Test 4.a passed.

echo Test 4.b: With a tmp variabl : execute the default

%tmp =

switch (%tmp)
{
	case (1) {
		echo It was 1... oops
		halt;
	}
	case (aaaa) { # do nothing ; }
	default {
		echo Default label
	}
}

echo Test 4.b passed.


echo Test 5: Now it should execute the default operation

switch
(        \
aax      \
)
{
	case (%tmp) {
		echo Oops...
		echo It was not this...
	}


	case () echo Wrong case!
	case
(            \
				aax \
x  )
		echo Oops...
	default {
		echo Default
		echo Executed
		echo Correctly
	}
}

echo Test 5 passed.

echo Test 6: Inside an if command

%tmp = 2

if(1 < %tmp)
{
	switch(%tmp)
	{
		case(1)halt;
		case(2)if(%tmp)echo OK!;
		case(3)halt;
		default halt;
	}
}

echo Test 6 passed.

echo Test 7: Now abort with an error related to the default label

switch(aa)
{
	default echo Executed the default...



	case(aa) echo The error is here...:) OK!
}
