File: switch

package info (click to toggle)
kvirc2 2.1.3-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 16,308 kB
  • ctags: 9,533
  • sloc: cpp: 86,257; sh: 10,532; makefile: 631; perl: 419; ansic: 315; sed: 16
file content (162 lines) | stat: -rw-r--r-- 2,258 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# 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!
}