gcc/fortran/
[official-gcc.git] / gcc / testsuite / gfortran.dg / minmax_char_1.f90
blob9e73e9850be47f66abf37c923c76bde247550e36
1 ! Tests for MIN and MAX intrinsics with character arguments
3 ! { dg-do run }
4 program test
5 character(len=3), parameter :: sp = "gee"
6 character(len=6), parameter :: tp = "crunch", wp = "flunch"
7 character(len=2), parameter :: up = "az", vp = "da"
9 character(len=3) :: s
10 character(len=6) :: t, w
11 character(len=2) :: u, v
12 s = "gee"
13 t = "crunch"
14 u = "az"
15 v = "da"
16 w = "flunch"
18 if (.not. equal(min("foo", "bar"), "bar")) call abort
19 if (.not. equal(max("foo", "bar"), "foo")) call abort
20 if (.not. equal(min("bar", "foo"), "bar")) call abort
21 if (.not. equal(max("bar", "foo"), "foo")) call abort
23 if (.not. equal(min("bar", "foo", sp), "bar")) call abort
24 if (.not. equal(max("bar", "foo", sp), "gee")) call abort
25 if (.not. equal(min("bar", sp, "foo"), "bar")) call abort
26 if (.not. equal(max("bar", sp, "foo"), "gee")) call abort
27 if (.not. equal(min(sp, "bar", "foo"), "bar")) call abort
28 if (.not. equal(max(sp, "bar", "foo"), "gee")) call abort
30 if (.not. equal(min("foo", "bar", s), "bar")) call abort
31 if (.not. equal(max("foo", "bar", s), "gee")) call abort
32 if (.not. equal(min("foo", s, "bar"), "bar")) call abort
33 if (.not. equal(max("foo", s, "bar"), "gee")) call abort
34 if (.not. equal(min(s, "foo", "bar"), "bar")) call abort
35 if (.not. equal(max(s, "foo", "bar"), "gee")) call abort
37 if (.not. equal(min("", ""), "")) call abort
38 if (.not. equal(max("", ""), "")) call abort
39 if (.not. equal(min("", " "), " ")) call abort
40 if (.not. equal(max("", " "), " ")) call abort
42 if (.not. equal(min(u,v,w), "az ")) call abort
43 if (.not. equal(max(u,v,w), "flunch")) call abort
44 if (.not. equal(min(u,vp,w), "az ")) call abort
45 if (.not. equal(max(u,vp,w), "flunch")) call abort
46 if (.not. equal(min(u,v,wp), "az ")) call abort
47 if (.not. equal(max(u,v,wp), "flunch")) call abort
48 if (.not. equal(min(up,v,w), "az ")) call abort
49 if (.not. equal(max(up,v,w), "flunch")) call abort
51 call foo("gee ","az ",s,t,u,v)
52 call foo("gee ","az ",s,t,u,v)
53 call foo("gee ","az ",s,t,u)
54 call foo("gee ","crunch",s,t)
56 contains
58 subroutine foo(res_max, res_min, a, b, c, d)
59 character(len=*) :: res_min, res_max
60 character(len=*), optional :: a, b, c, d
62 if (.not. equal(min(a,b,c,d), res_min)) call abort
63 if (.not. equal(max(a,b,c,d), res_max)) call abort
64 end subroutine foo
66 pure function equal(a,b)
67 character(len=*), intent(in) :: a, b
68 logical :: equal
70 equal = (len(a) == len(b)) .and. (a == b)
71 end function equal
73 end program test