Skip to content

Commit 10100ee

Browse files
committed
feat(string,test_dia): get_string_with_str, .also.
This commit 1. Adds test_diagnosis_t operator(.also.) synonym for .and. 2. Adds specific type-bound procedure get_string_with_character_key corresponding to get_json_value generic binding.
1 parent a8a6d9b commit 10100ee

5 files changed

Lines changed: 23 additions & 25 deletions

File tree

src/julienne/julienne_string_m.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module julienne_string_m
2626
generic :: operator(/=) => string_t_ne_string_t, string_t_ne_character, character_ne_string_t
2727
generic :: operator(==) => string_t_eq_string_t, string_t_eq_character, character_eq_string_t
2828
generic :: assignment(= ) => assign_string_t_to_character, assign_character_to_string_t
29-
generic :: get_json_value => get_string_with_string_key &
29+
generic :: get_json_value => get_string_with_string_key, get_string_with_character_key &
3030
,get_character_with_string_key, get_character_with_character_key &
3131
,get_string_t_array_with_character_key, get_string_t_array_with_string_t_key &
3232
,get_real, get_real_with_character_key &
@@ -36,7 +36,7 @@ module julienne_string_m
3636
,get_integer, get_integer_with_character_key &
3737
,get_double_precision, get_double_precision_with_character_key &
3838
,get_double_precision_array, get_double_precision_array_with_character_key
39-
procedure, private :: get_string_with_string_key
39+
procedure, private :: get_string_with_string_key, get_string_with_character_key
4040
procedure, private :: get_character_with_string_key, get_character_with_character_key
4141
procedure, private :: get_string_t_array_with_character_key, get_string_t_array_with_string_t_key
4242
procedure, private :: get_real, get_real_with_character_key
@@ -272,7 +272,7 @@ elemental module function get_string_with_string_key(self, key, mold) result(val
272272
type(string_t) :: value_
273273
end function
274274

275-
elemental module function get_string_with_character_key(self, key, mold) result(value_)
275+
pure module function get_string_with_character_key(self, key, mold) result(value_)
276276
implicit none
277277
class(string_t), intent(in) :: self, mold
278278
character(len=*), intent(in) :: key

src/julienne/julienne_test_diagnosis_m.F90

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module julienne_test_diagnosis_m
1515
public :: julienne_assert
1616
public :: operator(.all.)
1717
public :: operator(.and.)
18+
public :: operator(.also.)
1819
public :: operator(.approximates.)
1920
public :: operator(.isAtLeast.)
2021
public :: operator(.isAtMost.)
@@ -181,16 +182,20 @@ pure module function aggregate_rank15_diagnosis(diagnoses) result(diagnosis)
181182
#endif
182183
end interface
183184

184-
interface operator(.and.)
185+
interface operator(.also.)
185186

186-
elemental module function and(lhs, rhs) result(diagnosis)
187+
elemental module function also(lhs, rhs) result(diagnosis)
187188
implicit none
188189
type(test_diagnosis_t), intent(in) :: lhs, rhs
189190
type(test_diagnosis_t) diagnosis
190191
end function
191192

192193
end interface
193194

195+
interface operator(.and.)
196+
module procedure also
197+
end interface
198+
194199
interface operator(.approximates.)
195200

196201
elemental module function approximates_real(actual, expected) result(operands)

src/julienne/julienne_test_diagnosis_s.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
implicit none
1111
contains
1212

13-
module procedure and
13+
module procedure also
1414
diagnosis = .all. ([lhs,rhs])
1515
end procedure
1616

src/julienne_m.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module julienne_m
1414
,julienne_assert &
1515
,operator(.all.) &
1616
,operator(.and.) &
17+
,operator(.also.) &
1718
,operator(.approximates.) &
1819
,operator(.equalsExpected.) &
1920
,operator(.isAtLeast.) &

test/modules/string_test_m.F90

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module string_test_m
1717
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
1818
,diagnosis_function_i &
1919
#endif
20+
,operator(.equalsExpected.) &
21+
,operator(.also.) &
2022
,operator(.cat.) &
2123
,operator(.csv.) &
2224
,operator(.sv.)
@@ -209,32 +211,22 @@ function extracts_character_value() result(test_diagnosis)
209211
type(test_diagnosis_t) test_diagnosis
210212

211213
associate(line => string_t('"foo" : "bar"'), line_with_comma => string_t('"foo" : "bar",'))
212-
associate(json_values => [ &
213-
line%get_json_value(key="foo" , mold="") &
214-
,line%get_json_value(key=string_t("foo"), mold="") &
215-
,line_with_comma%get_json_value(key="foo" , mold="") &
216-
,line_with_comma%get_json_value(key=string_t("foo"), mold="") &
217-
])
218-
test_diagnosis = test_diagnosis_t( &
219-
test_passed = all(json_values == "bar") &
220-
,diagnostics_string = "expected bar; actual " // .csv. json_values &
221-
)
222-
end associate
214+
test_diagnosis = (line%get_json_value( key= "foo" , mold="") .equalsExpected. "bar") &
215+
.also. (line_with_comma%get_json_value(key= "foo" , mold="") .equalsExpected. "bar") &
216+
.also. (line%get_json_value( key=string_t("foo"), mold="") .equalsExpected. "bar") &
217+
.also. (line_with_comma%get_json_value(key=string_t("foo"), mold="") .equalsExpected. "bar")
223218
end associate
224219
end function
225220

226221
function extracts_string_value() result(test_diagnosis)
227222
type(test_diagnosis_t) test_diagnosis
228223

229-
associate(line => string_t('"foo" : "bar"'))
230-
associate(json_value => line%get_json_value(key=string_t("foo"), mold=string_t("")))
231-
test_diagnosis = test_diagnosis_t( &
232-
test_passed = json_value == "bar", &
233-
diagnostics_string = "expected 'bar', actual " // json_value &
234-
)
235-
end associate
224+
associate(line => string_t('"foo" : "bar"'), line_with_comma => string_t('"foo" : "bar",'))
225+
test_diagnosis = (line%get_json_value( key= "foo" , mold=string_t("")) .equalsExpected. "bar") &
226+
.also. (line_with_comma%get_json_value(key= "foo" , mold=string_t("")) .equalsExpected. "bar") &
227+
.also. (line%get_json_value( key=string_t("foo"), mold=string_t("")) .equalsExpected. "bar") &
228+
.also. (line_with_comma%get_json_value(key=string_t("foo"), mold=string_t("")) .equalsExpected. "bar")
236229
end associate
237-
238230
end function
239231

240232
function extracts_integer_value() result(test_diagnosis)

0 commit comments

Comments
 (0)