summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/select_char_1.f90
blob: 83c5268302c9ac1e743720de2358b592ed42298b (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
integer function char_select (s)
  character(len=*), intent(in) :: s

  select case(s)
    case ("foo")
      char_select = 1
    case ("bar", "gee")
      char_select = 2
    case ("111", "999")
      char_select = 3
    case ("1024", "1900")
      char_select = 4
    case ("12", "17890")
      char_select = 5
    case default
      char_select = -1
  end select
end function char_select

integer function char_select2 (s)
  character(len=*), intent(in) :: s

  char_select2 = -1
  select case(s)
    case ("foo")
      char_select2 = 1
    case ("bar", "gee")
      char_select2 = 2
    case ("111", "999")
      char_select2 = 3
    case ("1024", "1900")
      char_select2 = 4
    case ("12", "17890")
      char_select2 = 5
  end select
end function char_select2


program test
  interface
    integer function char_select (s)
      character(len=*), intent(in) :: s
    end function char_select
    integer function char_select2 (s)
      character(len=*), intent(in) :: s
    end function char_select2
  end interface

  if (char_select("foo") /= 1) call abort
  if (char_select("foo ") /= 1) call abort
  if (char_select("foo2 ") /= -1) call abort
  if (char_select("bar") /= 2) call abort
  if (char_select("gee") /= 2) call abort
  if (char_select("000") /= -1) call abort
  if (char_select("101") /= -1) call abort
  if (char_select("109") /= -1) call abort
  if (char_select("111") /= 3) call abort
  if (char_select("254") /= -1) call abort
  if (char_select("999") /= 3) call abort
  if (char_select("9989") /= -1) call abort
  if (char_select("1882") /= -1) call abort

  if (char_select2("foo") /= 1) call abort
  if (char_select2("foo ") /= 1) call abort
  if (char_select2("foo2 ") /= -1) call abort
  if (char_select2("bar") /= 2) call abort
  if (char_select2("gee") /= 2) call abort
  if (char_select2("000") /= -1) call abort
  if (char_select2("101") /= -1) call abort
  if (char_select2("109") /= -1) call abort
  if (char_select2("111") /= 3) call abort
  if (char_select2("254") /= -1) call abort
  if (char_select2("999") /= 3) call abort
  if (char_select2("9989") /= -1) call abort
  if (char_select2("1882") /= -1) call abort
end program test