1! RUN: %S/test_folding.sh %s %t %f18
2! Test character intrinsic function folding
3
4module character_intrinsic_tests
5  logical, parameter :: test_char1_ok1 = char(0_4, 1).EQ."�"
6  logical, parameter :: test_char1_ok2 = char(127_4, 1).EQ.""
7  logical, parameter :: test_char1_ok3 = char(97_4, 1).EQ."a"
8  logical, parameter :: test_char1_ok4 = .NOT.char(97_4, 1).EQ."b"
9  logical, parameter :: test_char1_ok5 = char(355_4, 1).EQ."c"
10  logical, parameter :: test_char1_ok6 = char(-61_1, 1).EQ.char(195_4, 1)
11
12  logical, parameter :: test_char2_ok1 = char(0_4, 2).EQ.2_"�"
13  logical, parameter :: test_char2_ok2 = char(127_4, 2).EQ.2_""
14  logical, parameter :: test_char2_ok3 = char(122_4, 2).EQ.2_"z"
15
16  logical, parameter :: test_char4_ok1 = char(0, 4).EQ.4_"�"
17  logical, parameter :: test_char4_ok2 = char(INT(12435, 4), 4).EQ.4_"ん"
18  logical, parameter :: test_char4_ok3 = char(354_4, 4).EQ.4_"Ţ"
19  logical, parameter :: test_char4_ok4 = char(-1_1, 4).EQ.char(x'ffffffff', 4)
20
21  character(kind=4, len=*), parameter :: c4aok(*) = char([97_4, 98_4, 99_4, 20320_4, 22909_4], 4)
22  logical, parameter :: test_char4_array = (c4aok(1).EQ.4_"a").AND.(c4aok(2).EQ.4_"b") &
23    .AND.(c4aok(3).EQ.4_"c").AND.(c4aok(4).EQ.4_"你").AND.(c4aok(5).EQ.4_"好")
24
25  logical, parameter :: test_achar4_ok1 = achar(0_4, 4).EQ.4_"�"
26  logical, parameter :: test_achar4_ok2 = achar(127_4, 4).EQ.4_""
27
28  character(kind=1, len=*), parameter :: c1aok(*) = achar([97_4, 0_4, 98_4], 1)
29  logical, parameter :: test_char1_array = (c1aok(1).EQ.1_"a").AND.(c1aok(2).EQ.1_"�") &
30    .AND.(c1aok(3).EQ.1_"b")
31
32
33  logical, parameter :: test_ichar1 = char(ichar("a")).EQ."a"
34  logical, parameter :: test_ichar2 = ichar(char(255)).EQ.255
35  logical, parameter :: test_ichar3 = ichar(char(-1_1), 1).EQ.-1_1
36  logical, parameter :: test_ichar4 = ichar(char(2147483647_4, 4), 4).EQ.2147483647_4
37  logical, parameter :: test_ichar5 = ichar(char(4294967295_8, 4), 8).EQ.4294967295_8
38  logical, parameter :: test_ichar6 = ichar(char(4294967296_8, 4), 8).EQ.0_8
39  logical, parameter :: test_iachar1 = achar(iachar("a")).EQ."a"
40  logical, parameter :: test_iachar2 = iachar(achar(22)).EQ.22
41  logical, parameter :: test_iachar3 = ichar(char(-2147483647_4, 4), 4).EQ.(-2147483647_4)
42  logical, parameter :: test_iachar5 = ichar(char(65535_4, 2), 4).EQ.65535_4
43  logical, parameter :: test_iachar6 = ichar(char(65536_4, 2), 4).EQ.0_4
44
45  ! Not yet recognized as intrinsic
46  !character(kind=1, len=1), parameter :: test_c1_new_line = new_line("a")
47
48  logical, parameter :: test_c1_adjustl1 = adjustl("  this is a test").EQ.("this is a test  ")
49  logical, parameter :: test_c1_adjustl2 = .NOT."  this is a test".EQ.("this is a test  ")
50  logical, parameter :: test_c1_adjustl3 = adjustl("").EQ.("")
51  logical, parameter :: test_c1_adjustl4 = adjustl("that").EQ.("that")
52  logical, parameter :: test_c1_adjustl5 = adjustl("that ").EQ.("that ")
53  logical, parameter :: test_c1_adjustl6 = adjustl(" that ").EQ.("that  ")
54  logical, parameter :: test_c1_adjustl7 = adjustl("    ").EQ.("    ")
55  character(kind=1, len=*), parameter :: c1_adjustl8(*) = adjustl(["  this is a test", " that is a test "])
56  logical, parameter :: test_c1_adjustl8 = (c1_adjustl8(1).EQ.1_"this is a test  ").AND.(c1_adjustl8(2).EQ.1_"that is a test  ")
57
58  logical, parameter :: test_c4_adjustr1 = adjustr(4_"  你好吗 ? ").EQ.(4_"   你好吗 ?")
59  logical, parameter :: test_c4_adjustr2 = .NOT.(4_"  你好吗 ? ").EQ.(4_"  你好吗 ?")
60  logical, parameter :: test_c4_adjustr3 = adjustr(4_"").EQ.(4_"")
61  logical, parameter :: test_c4_adjustr4 = adjustr(4_"   ").EQ.(4_"   ")
62  logical, parameter :: test_c4_adjustr5 = adjustr(4_"你 好吗?").EQ.(4_"你 好吗?")
63  logical, parameter :: test_c4_adjustr6 = adjustr(4_" 你好吗?").EQ.(4_" 你好吗?")
64  logical, parameter :: test_c4_adjustr7 = adjustr(4_" 你好吗? ").EQ.(4_"  你好吗?")
65  character(kind=4, len=*), parameter :: c4_adjustr8(*) = adjustr([4_"  你 好吗?%%% ", 4_"你a好b 吗c?   "])
66  logical, parameter :: test_c4_adjustr8 = (c4_adjustr8(1).EQ.4_"   你 好吗?%%%").AND.(c4_adjustr8(2).EQ.4_"   你a好b 吗c?")
67
68  integer, parameter :: ck = selected_char_kind('DEFAuLT  ')
69  character(kind=ck, len=*), parameter :: cks = 'DEFAULT'
70  character(len=1), parameter :: ds = ' '
71  logical, parameter :: test_selected_char_kind = kind(ds).eq.kind(cks)
72  logical, parameter :: test_c1_new_line1 = ichar(new_line(1_"a"), 4).EQ.10_4
73  logical, parameter :: test_c2_new_line1 = ichar(new_line(2_"z"), 4).EQ.10_4
74  logical, parameter :: test_c4_new_line1 = ichar(new_line(4_" 你好吗? "), 4).EQ.10_4
75  character(kind=1, len=10) s1(10,10)
76  character(kind=2, len=10) s2(10,10)
77  character(kind=4, len=10) s4(10,10)
78  logical, parameter :: test_c1_new_line2 = kind(new_line(s1)).EQ.1_4
79  logical, parameter :: test_c2_new_line2 = kind(new_line(s2)).EQ.2_4
80  logical, parameter :: test_c4_new_line2 = kind(new_line(s4)).EQ.4_4
81  logical, parameter :: test_c1_new_line3 = len(new_line(s1)).EQ.1_4
82  logical, parameter :: test_c2_new_line3 = len(new_line(s2)).EQ.1_4
83  logical, parameter :: test_c4_new_line3 = len(new_line(s4)).EQ.1_4
84  logical, parameter :: test_c1_new_line4 = rank(new_line(s1)).EQ.0_4
85  logical, parameter :: test_c2_new_line4 = rank(new_line(s2)).EQ.0_4
86  logical, parameter :: test_c4_new_line4 = rank(new_line(s4)).EQ.0_4
87
88  logical, parameter :: test_c1_index1 = index("  this is a test", "this is a test") .EQ. 3
89  logical, parameter :: test_c1_index2 = index("  this is a test", "this is not a test") .EQ. 0
90  logical, parameter :: test_c1_index3 = index("ABBA", "A") .EQ. 1
91  logical, parameter :: test_c1_index4 = index("ABBA", "A", back=.true.) .EQ. 4
92  logical, parameter :: test_c4_index1 = index(4_"  this is a test", 4_"this is a test") .EQ. 3
93  logical, parameter :: test_c4_index2 = index(4_"  this is a test", 4_"this is not a test") .EQ. 0
94  logical, parameter :: test_c4_index3 = index(4_"ABBA", 4_"A") .EQ. 1
95  logical, parameter :: test_c4_index4 = index(4_"ABBA", 4_"A", back=.true.) .EQ. 4
96  logical, parameter :: test_c1_scan1 = scan("ABBA", "ACD") .EQ. 1
97  logical, parameter :: test_c1_scan2 = scan("ABBA", "ACD", back=.true.) .EQ. 4
98  logical, parameter :: test_c1_scan3 = scan("ABBA", "E") .EQ. 0
99  logical, parameter :: test_c1_scan4 = scan("ABBA", "") .EQ. 0
100  logical, parameter :: test_c1_scan5 = scan("", "FG") .EQ. 0
101  logical, parameter :: test_c1_scan6 = scan("", "") .EQ. 0
102  logical, parameter :: test_c4_scan1 = scan(4_"ABBA", 4_"ACD") .EQ. 1
103  logical, parameter :: test_c4_scan2 = scan(4_"ABBA", 4_"ACD", back=.true.) .EQ. 4
104  logical, parameter :: test_c4_scan3 = scan(4_"ABBA", 4_"E") .EQ. 0
105  logical, parameter :: test_c4_scan4 = scan(4_"ABBA", 4_"") .EQ. 0
106  logical, parameter :: test_c4_scan5 = scan(4_"", 4_"FG") .EQ. 0
107  logical, parameter :: test_c4_scan6 = scan(4_"", 4_"") .EQ. 0
108  logical, parameter :: test_c1_verify1 = verify("ABBA", "ACD") .EQ. 2
109  logical, parameter :: test_c1_verify2 = verify("ABBA", "ACD", back=.true.) .EQ. 3
110  logical, parameter :: test_c1_verify3 = verify("ABBA", "E") .EQ. 1
111  logical, parameter :: test_c1_verify4 = verify("ABBA", "") .EQ. 1
112  logical, parameter :: test_c1_verify4a = verify("ABBA", "", back=.true.) .EQ. 4
113  logical, parameter :: test_c1_verify5 = verify("", "FG") .EQ. 0
114  logical, parameter :: test_c1_verify6 = verify("", "") .EQ. 0
115  logical, parameter :: test_c4_verify1 = verify(4_"ABBA", 4_"ACD") .EQ. 2
116  logical, parameter :: test_c4_verify2 = verify(4_"ABBA", 4_"ACD", back=.true.) .EQ. 3
117  logical, parameter :: test_c4_verify3 = verify(4_"ABBA", 4_"E") .EQ. 1
118  logical, parameter :: test_c4_verify4 = verify(4_"ABBA", 4_"") .EQ. 1
119  logical, parameter :: test_c4_verify4a = verify(4_"ABBA", 4_"", back=.true.) .EQ. 4
120  logical, parameter :: test_c4_verify5 = verify(4_"", 4_"FG") .EQ. 0
121  logical, parameter :: test_c4_verify6 = verify(4_"", 4_"") .EQ. 0
122
123  logical, parameter :: test_c1_len_trim1 = len_trim("this is a test  ") .EQ. 14
124  logical, parameter :: test_c1_len_trim2 = len_trim("this is a test") .EQ. 14
125  logical, parameter :: test_c1_len_trim3 = len_trim("  this is a test") .EQ. 16
126  logical, parameter :: test_c1_len_trim4 = len_trim("") .EQ. 0
127  logical, parameter :: test_c4_len_trim1 = len_trim(4_"this is a test  ") .EQ. 14
128  logical, parameter :: test_c4_len_trim2 = len_trim(4_"this is a test") .EQ. 14
129  logical, parameter :: test_c4_len_trim3 = len_trim(4_"  this is a test") .EQ. 16
130  logical, parameter :: test_c4_len_trim4 = len_trim(4_"") .EQ. 0
131
132  logical, parameter :: test_c1_repeat1 = repeat('ab', 2) .eq. 'abab'
133  logical, parameter :: test_c1_repeat2 = repeat('ab', 0) .eq. ''
134  logical, parameter :: test_c1_repeat3 = repeat('', 99) .eq. ''
135  logical, parameter :: test_c4_repeat1 = repeat(4_'ab', 2) .eq. 4_'abab'
136  logical, parameter :: test_c4_repeat2 = repeat(4_'ab', 0) .eq. 4_''
137  logical, parameter :: test_c4_repeat3 = repeat(4_'', 99) .eq. 4_''
138
139  logical, parameter :: test_c1_trim1 = trim('ab') .eq. 'ab'
140  logical, parameter :: test_c1_trim2 = trim('ab  ') .eq. 'ab'
141  logical, parameter :: test_c1_trim3 = trim('  ab  ') .eq. '  ab'
142  logical, parameter :: test_c1_trim4 = trim('  ') .eq. ''
143  logical, parameter :: test_c1_trim5 = trim('') .eq. ''
144  logical, parameter :: test_c4_trim1 = trim(4_'ab') .eq. 4_'ab'
145  logical, parameter :: test_c4_trim2 = trim(4_'ab  ') .eq. 4_'ab'
146  logical, parameter :: test_c4_trim3 = trim(4_'  ab  ') .eq. 4_'  ab'
147  logical, parameter :: test_c4_trim4 = trim(4_'  ') .eq. 4_''
148  logical, parameter :: test_c4_trim5 = trim(4_'') .eq. 4_''
149end module
150