aboutsummaryrefslogtreecommitdiffstats
path: root/testcases-case
blob: 4b9fc5e17244a9be39580f637234c9856a464b13 (plain)
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
1:
$cppawk '
#include <case.h>
BEGIN {
#if defined case_temps && defined case && defined of && \
    defined matching && defined cbreak && defined otherwise
  print 1
#endif
}'
:
1
--
2:
printf "%s\n" foo bar xyzzy x b | $cppawk '
#include <case.h>
{
   case ($0) {
     of ("foo")
       print "** foo case: fallthrough!"
       cfall;
     of ("bar", "xyzzy") {
       print "** bar/xyzzy case"
       cbreak;
     }
     matching (/x/)
       print "** /x/ case"
       cbreak;
     otherwise
       print "** default"
       cbreak;
   }
}'
:
** foo case: fallthrough!
** bar/xyzzy case
** bar/xyzzy case
** bar/xyzzy case
** /x/ case
** default
--
3:
$cppawk '
#include <case.h>
function f(arg, case_temps)
{
  case (arg) {
    of (1, 2, 3) cret(arg * 10)
    otherwise    cret(-arg)
  }
}

BEGIN { print f(1), f(2), f(3), f(4) }'
:
10 20 30 -4
--
4:
$cppawk '
#include <case.h>
function f(arg, case_temps, retval)
{
  retval = 0

  case (arg) {
    of ("alt")
      ++retval
      cfall
    mixed (("foo", "bar"), (/^abc/, /xyz$/))
      ++retval
      cbreak
    otherwise
      --retval
      cbreak
  }

  return retval
}

BEGIN { print f("alt"), f("foo"), f("bar"), f("abcde"), f("wxyz"), f("1abc2") }'
:
2 1 1 1 1 -1