-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_test.F90
695 lines (623 loc) · 27.7 KB
/
string_test.F90
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt
#include "language-support.F90"
module string_test_m
use assert_m, only : assert
use iso_c_binding, only : c_bool
use julienne_m, only : &
test_t &
,test_result_t &
,test_description_t &
,test_description_substring &
,string_t &
,operator(.cat.) &
,operator(.csv.) &
,operator(.sv.)
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
use julienne_m, only : test_function_i
#endif
implicit none
private
public :: string_test_t
type, extends(test_t) :: string_test_t
contains
procedure, nopass :: subject
procedure, nopass :: results
end type
contains
pure function subject() result(specimen)
character(len=:), allocatable :: specimen
specimen = "The string_t type"
end function
function results() result(test_results)
type(test_result_t), allocatable :: test_results(:)
type(test_description_t), allocatable :: test_descriptions(:)
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t &
(string_t("is_allocated() result .true. if & only if the string_t component(s) is/are allocated"), check_allocation), &
test_description_t &
(string_t('supporting operator(==) for string_t and character operands'), supports_equivalence_operator), &
test_description_t &
(string_t('supporting operator(/=) for string_t and character operands'), supports_non_equivalence_operator), &
test_description_t &
(string_t('supporting operator(//) for string_t and character operands'), supports_concatenation_operator), &
test_description_t &
(string_t('assigning a string_t object to a character variable'), assigns_string_t_to_character), &
test_description_t &
(string_t('assigning a character variable to a string_t object'), assigns_character_to_string_t), &
test_description_t &
(string_t('constructing from a default integer'), constructs_from_default_integer), &
test_description_t &
(string_t('constructing from a default real value'), constructs_from_default_real), &
test_description_t &
(string_t('constructing from a double-precision value'), constructs_from_double_precision), &
test_description_t &
(string_t('constructing from a default-kind logical value'), constructs_from_default_logical), &
test_description_t &
(string_t('constructing from a logical(c_bool) value'), constructs_from_logical_c_bool), &
test_description_t &
(string_t('constructing from a default-precision complex value'), constructs_from_default_complex), &
test_description_t &
(string_t('constructing from a double-precision complex value'), constructs_from_double_precision_complex), &
test_description_t &
(string_t('supporting unary operator(.cat.) for array arguments'), concatenates_elements), &
test_description_t &
(string_t("extracting a key string from a colon-separated key/value pair"), extracts_key), &
test_description_t &
(string_t("extracting a real value from a colon-separated key/value pair"), extracts_real_value), &
test_description_t &
(string_t("extracting a double-precision value from a colon-separated key/value pair"), extracts_double_precision_value), &
test_description_t &
(string_t("extracting a string value from a colon-separated key/value pair"), extracts_string_value), &
test_description_t &
(string_t("extracting a string value from a colon-separated key/value pair"), extracts_character_value), &
test_description_t &
(string_t("extracting a logical value from a colon-separated key/value pair"), extracts_logical_value), &
test_description_t &
(string_t("extracting an integer array value from a colon-separated key/value pair"), extracts_integer_array_value), &
test_description_t &
(string_t("extracting a string_t array value from a colon-separated key/value pair"), extracts_string_array_value), &
test_description_t &
(string_t("extracting an real array value from a colon-separated key/value pair"), extracts_real_array_value), &
test_description_t &
(string_t("extracting a double-precision array value from a colon-separated key/value pair"), extracts_dp_array_value), &
test_description_t &
(string_t("extracting an integer value from a colon-separated key/value pair"), extracts_integer_value), &
test_description_t &
(string_t('extracting a file base name'), extracts_file_base_name), &
test_description_t &
(string_t('extracting a file name extension'), extracts_file_name_extension), &
test_description_t &
(string_t('constructing a bracketed string'), brackets_strings), &
test_description_t &
(string_t('constructing (comma-)separated values from character or string_t arrays'), constructs_separated_values) &
]
#else
! Work around missing Fortran 2008 feature: associating a procedure actual argument with a procedure pointer dummy argument:
procedure(test_function_i), pointer :: &
check_allocation_ptr, supports_equivalence_ptr, supports_non_equivalence_ptr, supports_concatenation_ptr, &
assigns_string_ptr, assigns_character_ptr, constructs_from_integer_ptr, constructs_from_default_real_ptr, constructs_from_double_precision_ptr, &
constructs_from_default_logical_ptr, constructs_from_logical_c_bool_ptr, constructs_from_default_complex_ptr, &
constructs_from_double_precision_complex_ptr, &
concatenates_ptr, extracts_key_ptr, extracts_real_ptr, extracts_string_ptr, extracts_logical_ptr, extracts_integer_array_ptr, &
extracts_real_array_ptr, extracts_integer_ptr, extracts_file_base_ptr, extracts_file_name_ptr, &
extracts_string_array_ptr, &
extracts_character_ptr, extracts_double_precision_value_ptr, extracts_dp_array_value_ptr, &
brackets_strings_ptr, constructs_separated_values_ptr
check_allocation_ptr => check_allocation
supports_equivalence_ptr => supports_equivalence_operator
supports_non_equivalence_ptr => supports_non_equivalence_operator
supports_concatenation_ptr => supports_concatenation_operator
assigns_string_ptr => assigns_string_t_to_character
assigns_character_ptr => assigns_character_to_string_t
constructs_from_integer_ptr => constructs_from_default_integer
constructs_from_double_precision_ptr => constructs_from_double_precision
constructs_from_default_real_ptr => constructs_from_default_real
constructs_from_default_logical_ptr => constructs_from_default_logical
constructs_from_logical_c_bool_ptr => constructs_from_logical_c_bool
constructs_from_default_complex_ptr => constructs_from_default_complex
constructs_from_double_precision_complex_ptr => constructs_from_double_precision_complex
concatenates_ptr => concatenates_elements
extracts_key_ptr => extracts_key
extracts_real_ptr => extracts_real_value
extracts_double_precision_value_ptr => extracts_double_precision_value
extracts_string_ptr => extracts_string_value
extracts_character_ptr => extracts_character_value
extracts_logical_ptr => extracts_logical_value
extracts_integer_array_ptr => extracts_integer_array_value
extracts_string_array_ptr => extracts_string_array_value
extracts_real_array_ptr => extracts_real_array_value
extracts_dp_array_value_ptr => extracts_dp_array_value
extracts_integer_ptr => extracts_integer_value
extracts_file_base_ptr => extracts_file_base_name
extracts_file_name_ptr => extracts_file_name_extension
brackets_strings_ptr => brackets_strings
constructs_separated_values_ptr => constructs_separated_values
test_descriptions = [ &
test_description_t( &
string_t("is_allocated() result .true. if & only if the string_t component(s) is/are allocated"), check_allocation_ptr), &
test_description_t(string_t('supporting operator(==) for string_t and character operands'), supports_equivalence_ptr), &
test_description_t( &
string_t('supporting operator(/=) for string_t and character operands'), supports_non_equivalence_ptr), &
test_description_t( &
string_t('supporting operator(//) for string_t and character operands'), supports_concatenation_ptr), &
test_description_t(string_t('assigning a string_t object to a character variable'), assigns_string_ptr), &
test_description_t(string_t('assigning a character variable to a string_t object'), assigns_character_ptr), &
test_description_t(string_t('constructing from a default integer'), constructs_from_integer_ptr), &
test_description_t(string_t('constructing from a default real value'), constructs_from_default_real_ptr), &
test_description_t(string_t('constructing from a double-precision value'), constructs_from_double_precision_ptr), &
test_description_t(string_t('constructing from a default-kind logical value'), constructs_from_default_logical_ptr), &
test_description_t(string_t('constructing from a logical(c_bool) value'), constructs_from_logical_c_bool_ptr), &
test_description_t(string_t('constructing from a default-precision complex value'), constructs_from_default_complex_ptr), &
test_description_t(string_t('constructing from a double-precision complex value'), constructs_from_double_precision_complex_ptr), &
test_description_t(string_t('supporting unary operator(.cat.) for array arguments'), concatenates_ptr), &
test_description_t(string_t("extracting a key string from a colon-separated key/value pair"), extracts_key_ptr), &
test_description_t(string_t("extracting a real value from a colon-separated key/value pair"), extracts_real_ptr), &
test_description_t( &
string_t("extracting a double-precision value from a colon-separated key/value pair"), extracts_double_precision_value_ptr),&
test_description_t(string_t("extracting a string value from a colon-separated key/value pair"), extracts_string_ptr), &
test_description_t(string_t("extracting a character value from a colon-separated key/value pair"), extracts_character_ptr), &
test_description_t(string_t("extracting a logical value from a colon-separated key/value pair"), extracts_logical_ptr), &
test_description_t( &
string_t("extracting an integer array value from a colon-separated key/value pair"), extracts_integer_array_ptr), &
test_description_t( &
string_t("extracting an string array value from a colon-separated key/value pair"), extracts_string_array_ptr), &
test_description_t( &
string_t("extracting an real array value from a colon-separated key/value pair"), extracts_real_array_ptr), &
test_description_t( &
string_t("extracting an double-precision array value from a colon-separated key/value pair"), extracts_dp_array_value_ptr), &
test_description_t(string_t("extracting an integer value from a colon-separated key/value pair"), extracts_integer_ptr), &
test_description_t(string_t('extracting a file base name'), extracts_file_base_ptr), &
test_description_t(string_t('extracting a file name extension'), extracts_file_name_ptr), &
test_description_t(string_t('constructing a bracketed string'), brackets_strings_ptr),&
test_description_t(string_t('constructing (comma-)separated values from string_t arrays'), constructs_separated_values_ptr) &
]
#endif
test_descriptions = pack(test_descriptions, &
index(subject(), test_description_substring) /= 0 .or. &
test_descriptions%contains_text(string_t(test_description_substring)))
test_results = test_descriptions%run()
end function
pure function check_allocation() result(passed)
type(string_t) :: scalar_not_allocated, scalar_allocated, array_allocated(2), array_not_allocated(2)
logical passed
scalar_allocated = string_t("")
array_allocated = [string_t("yada yada"), string_t("blah blah blah")]
passed = (.not. any([scalar_not_allocated%is_allocated(), array_not_allocated%is_allocated()])) .and. &
(all([scalar_allocated%is_allocated(), array_allocated%is_allocated()]))
end function
function extracts_key() result(passed)
logical passed
#ifndef _CRAYFTN
associate(line => string_t('"foo" : "bar"'))
passed = line%get_json_key() == string_t("foo")
end associate
#else
block
type(string_t) line
line = string_t('"foo" : "bar"')
passed = line%get_json_key() == string_t("foo")
end block
#endif
end function
function extracts_double_precision_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate(line => string_t('"pi" : 3.141592653589793D0'))
passed = line%get_json_value(key="pi", mold=0.D0) == 3.141592653589793D0
end associate
#else
block
type(string_t) line
line = string_t('"pi" : 3.141592653589793D0')
passed = line%get_json_value(key="pi", mold=0.D0) == 3.141592653589793D0
end block
#endif
end function
function extracts_real_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate(line => string_t('"pi" : 3.14159'))
passed = line%get_json_value(key=string_t("pi"), mold=1.) == 3.14159
end associate
#else
block
type(string_t) line
line = string_t('"pi" : 3.14159')
passed = line%get_json_value(key=string_t("pi"), mold=1.) == 3.14159
end block
#endif
end function
function extracts_character_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate(line => string_t('"foo" : "bar"'), line_with_comma => string_t('"foo" : "bar",'))
passed = line%get_json_value(key=string_t("foo"), mold="") == "bar" .and. &
line%get_json_value(key="foo" , mold="") == "bar" .and. &
line_with_comma%get_json_value(key=string_t("foo"), mold="") == "bar" .and. &
line_with_comma%get_json_value(key="foo" , mold="") == "bar"
end associate
#else
block
type(string_t) line, line_with_comma
line = string_t('"foo" : "bar"')
line_with_comma = string_t('"foo" : "bar",')
passed = line%get_json_value(key=string_t("foo"), mold="") == "bar" .and. &
line%get_json_value(key="foo" , mold="") == "bar" .and. &
line_with_comma%get_json_value(key=string_t("foo"), mold="") == "bar" .and. &
line_with_comma%get_json_value(key="foo" , mold="") == "bar"
end block
#endif
end function
function extracts_string_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate(line => string_t('"foo" : "bar"'))
passed = line%get_json_value(key=string_t("foo"), mold=string_t("")) == string_t("bar")
end associate
#else
block
type(string_t) line
line = string_t('"foo" : "bar"')
passed = line%get_json_value(key=string_t("foo"), mold=string_t("")) == string_t("bar")
end block
#endif
end function
function extracts_integer_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate(line => string_t('"an integer" : 99'))
passed = line%get_json_value(key=string_t("an integer"), mold=0) == 99
end associate
#else
block
type(string_t) line
line = string_t('"an integer" : 99')
passed = line%get_json_value(key=string_t("an integer"), mold=0) == 99
end block
#endif
end function
function extracts_logical_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate( &
key_true_pair => string_t('"yada yada" : true'), &
key_false_pair => string_t('"blah blah" : false'), &
trailing_comma => string_t('"trailing comma" : true,') &
)
associate( &
true => key_true_pair%get_json_value(key=string_t("yada yada"), mold=.true.), &
false => key_false_pair%get_json_value(key=string_t("blah blah"), mold=.true.), &
true_too => trailing_comma%get_json_value(key=string_t("trailing comma"), mold=.true.) &
)
passed = true .and. true_too .and. .not. false
end associate
end associate
#else
block
type(string_t) key_true_pair, key_false_pair, trailing_comma
logical true, false, true_too
key_true_pair = string_t('"yada yada" : true')
key_false_pair = string_t('"blah blah" : false')
trailing_comma = string_t('"trailing comma" : true,')
true = key_true_pair%get_json_value(key=string_t("yada yada"), mold=.true.)
false = key_false_pair%get_json_value(key=string_t("blah blah"), mold=.true.)
true_too = trailing_comma%get_json_value(key=string_t("trailing comma"), mold=.true.)
passed = true .and. true_too .and. .not. false
end block
#endif
end function
function extracts_string_array_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate(key_string_array_pair => string_t('"lead singer" : ["stevie", "ray", "vaughn"],'))
associate(string_array => key_string_array_pair%get_json_value(key="lead singer", mold=[string_t::]))
#ifndef __GFORTRAN__
associate(string_array_ => key_string_array_pair%get_json_value(key=string_t("lead singer"), mold=[string_t::]))
#endif
passed = all(string_array == [string_t("stevie"), string_t("ray"), string_t("vaughn")])
#ifndef __GFORTRAN__
& .and. all(string_array_ == [string_t("stevie"), string_t("ray"), string_t("vaughn")])
end associate
#endif
end associate
end associate
#else
block
type(string_t) key_string_array_pair
type(string_t), allocatable :: string_array(:)
key_string_array_pair = string_t('"lead singer" : ["ella", "fitzgerald"],')
string_array = key_string_array_pair%get_json_value(key=string_t("lead singer"), mold=[string_t::])
passed = all(string_array == [string_t("ella"), string_t("fitzgerald")])
end block
#endif
end function
function extracts_integer_array_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate(key_integer_array_pair => string_t('"some key" : [1, 2, 3],'))
associate(integer_array => key_integer_array_pair%get_json_value(key=string_t("some key"), mold=[integer::]))
passed = all(integer_array == [1, 2, 3])
end associate
end associate
#else
block
type(string_t) key_integer_array_pair
integer, allocatable :: integer_array(:)
key_integer_array_pair = string_t('"some key" : [1, 2, 3],')
integer_array = key_integer_array_pair%get_json_value(key=string_t("some key"), mold=[integer::])
passed = all(integer_array == [1, 2, 3])
end block
#endif
end function
function extracts_real_array_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate(key_real_array_pair => string_t('"a key" : [1., 2., 4.],'))
associate(real_array => key_real_array_pair%get_json_value(key=string_t("a key"), mold=[real::]))
passed = all(real_array == [1., 2., 4.])
end associate
end associate
#else
block
type(string_t) key_real_array_pair
real, allocatable :: real_array(:)
key_real_array_pair = string_t('"a key" : [1., 2., 4.],')
real_array = key_real_array_pair%get_json_value(key=string_t("a key"), mold=[real::])
passed = all(real_array == [1., 2., 4.])
end block
#endif
end function
function extracts_dp_array_value() result(passed)
logical passed
#ifndef _CRAYFTN
associate(key_dp_array_pair => string_t('"a key" : [1.D0, 2.D0, 4.D0],'))
associate(dp_array => key_dp_array_pair%get_json_value(key=string_t("a key"), mold=[double precision::]))
passed = all(dp_array == [1.D0, 2.D0, 4.D0])
end associate
end associate
#else
block
type(string_t) key_dp_array_pair
double precision, allocatable :: dp_array(:)
key_dp_array_pair = string_t('"a key" : [1., 2., 4.],')
dp_array = key_dp_array_pair%get_json_value(key=string_t("a key"), mold=[double precision::])
passed = all(dp_array == [1D0, 2D0, 4D0])
end block
#endif
end function
function supports_equivalence_operator() result(passed)
logical passed
passed = &
string_t("abcdefg") == string_t("abcdefg") .and. &
string_t("xyz pdq") == "xyz pdq" .and. &
"123.456" == string_t("123.456")
end function
function supports_non_equivalence_operator() result(passed)
logical passed
passed = &
string_t("abcdefg") /= string_t("xyz pdq") .and. &
string_t("xyz pdq") /= "abcdefg" .and. &
"123.456" /= string_t("456.123")
end function
function assigns_string_t_to_character() result(passed)
logical passed
character(len=:), allocatable :: lhs
associate(rhs => string_t("ya don't say"))
lhs = rhs
passed = lhs == rhs
end associate
end function
function assigns_character_to_string_t() result(passed)
logical passed
character(len=*), parameter :: rhs = "well, alrighty then"
type(string_t) lhs
lhs = rhs
passed = lhs == rhs
end function
function supports_concatenation_operator() result(passed)
logical passed
character(len=*), parameter :: prefix = "foo", postfix="bar"
#ifndef _CRAYFTN
associate(infix => string_t(" yada yada "))
passed = prefix // infix // postfix == prefix // infix%string() // postfix
end associate
#else
block
type(string_t) infix
infix = string_t(" yada yada ")
passed = prefix // infix // postfix == prefix // infix%string() // postfix
end block
#endif
end function
function constructs_from_default_integer() result(passed)
logical passed
#ifndef _CRAYFTN
associate(string => string_t(1234567890))
passed = adjustl(trim(string%string())) == "1234567890"
end associate
#else
block
type(string_t) string
string = string_t(1234567890)
passed = adjustl(trim(string%string())) == "1234567890"
end block
#endif
end function
function constructs_from_default_real() result(passed)
logical passed
real, parameter :: real_value = -1./1024. ! use a negative power of 2 an exactly representable rational number
real read_value
character(len=:), allocatable :: character_representation
#ifndef _CRAYFTN
associate(string => string_t(real_value))
character_representation = string%string()
read(character_representation, *) read_value
passed = read_value == real_value
end associate
#else
block
type(string_t) string
string = string_t(real_value)
character_representation = string%string()
read(character_representation, *) read_value
passed = read_value == real_value
end block
#endif
end function
function constructs_from_double_precision() result(passed)
logical passed
double precision, parameter :: real_value = -1./1024. ! use a negative power of 2 an exactly representable rational number
real read_value
character(len=:), allocatable :: character_representation
#ifndef _CRAYFTN
associate(string => string_t(real_value))
character_representation = string%string()
read(character_representation, *) read_value
passed = read_value == real_value
end associate
#else
block
type(string_t) string
string = string_t(real_value)
character_representation = string%string()
read(character_representation, *) read_value
passed = read_value == real_value
end block
#endif
end function
function constructs_from_default_complex() result(passed)
logical passed
complex, parameter :: z = (-1.23456789E-11, -9.87654321E-11)
complex read_value
character(len=:), allocatable :: character_representation
#ifndef _CRAYFTN
associate(string => string_t(z))
character_representation = string%string()
read(character_representation, *) read_value
passed = read_value == z
end associate
#else
block
type(string_t) string
string = string_t(z)
character_representation = string%string()
read(character_representation, *) read_value
passed = read_value == z
end block
#endif
end function
function constructs_from_double_precision_complex() result(passed)
logical passed
complex(kind(1D0)), parameter :: z = (-1.234567890123456789D-11, -9.87654320123456789D-11)
complex(kind(1D0)) read_value
character(len=:), allocatable :: character_representation
#ifndef _CRAYFTN
associate(string => string_t(z))
character_representation = string%string()
read(character_representation, *) read_value
passed = read_value == z
end associate
#else
block
type(string_t) string
string = string_t(z)
character_representation = string%string()
read(character_representation, *) read_value
passed = read_value == z
end block
#endif
end function
function constructs_from_default_logical() result(passed)
logical passed
#ifndef _CRAYFTN
associate(true => string_t(.true.), false => string_t(.false.))
passed = true%string() == "T" .and. false%string() == "F"
end associate
#else
block
type(string_t) true, false
true = string_t(.true.)
false = string_t(.false.)
passed = string%string() == "T" .and. false%string() == "F"
end block
#endif
end function
function constructs_from_logical_c_bool() result(passed)
logical passed
#ifndef _CRAYFTN
associate(true => string_t(.true._c_bool), false => string_t(.false._c_bool))
passed = true%string() == "T" .and. false%string() == "F"
end associate
#else
block
type(string_t) true, false
true = string_t(.true._c_bool)
false = string_t(.false._c_bool)
passed = string%string() == "T" .and. false%string() == "F"
end block
#endif
end function
function extracts_file_base_name() result(passed)
logical passed
#ifndef _CRAYFTN
associate(string => string_t(" foo .bar.too "))
passed = string%base_name() == "foo .bar"
end associate
#else
block
type(string_t) string
string = string_t(" foo .bar.too ")
passed = string%base_name() == "foo .bar"
end block
#endif
end function
function extracts_file_name_extension() result(passed)
logical passed
#ifndef _CRAYFTN
associate(string => string_t(" foo .bar.too "))
passed = string%file_extension() == "too"
end associate
#else
block
type(string_t) string
string = string_t(" foo .bar.too ")
passed = string%file_extension() == "too"
end block
#endif
end function
function concatenates_elements() result(passed)
logical passed
passed = (.cat. [string_t("foo"), string_t("bar")]) == "foobar"
end function
function brackets_strings() result(passed)
logical passed
#ifdef __GFORTRAN__
type(string_t), allocatable :: array(:)
array = string_t(["do", "re", "mi"])
#endif
associate( &
scalar => string_t("do re mi") &
#ifndef __GFORTRAN__
,array => string_t(["do", "re", "mi"]) &
#endif
)
passed = &
scalar%bracket() == string_t("[do re mi]") &
.and. all(array%bracket() == [string_t("[do]"), string_t("[re]"), string_t("[mi]")]) &
.and. all(array%bracket('"') == [string_t('"do"'), string_t('"re"'), string_t('"mi"')]) &
.and. all(array%bracket("{","}") == [string_t('{do}'), string_t('{re}'), string_t('{mi}')])
end associate
end function
function constructs_separated_values() result(passed)
logical passed
passed = &
"a,bc,def" == .csv. [string_t("a"), string_t("bc"), string_t("def")] &
.and. "abc,def" == .csv. ["abc", "def"] &
.and. "do|re|mi" == (string_t(["do", "re", "mi"]) .sv. "|" ) &
.and. "dore|mi" == (([string_t("dore"), string_t("mi")]) .sv. string_t("|")) &
.and. "do|re|mi" == ( ["do", "re", "mi"] .sv. "|" ) &
.and. "do|re|mi" == ( ["do", "re", "mi"] .sv. string_t("|"))
end function
end module string_test_m