Skip to content

Commit

Permalink
feat(test_description): make contains_text generic
Browse files Browse the repository at this point in the history
This commit makes the test_description_t type's "contains_text"
binding generic with two corresponding specific (private)
type-bound functions: contains_string_t and the new
contains_characters.
  • Loading branch information
rouson committed Sep 7, 2024
1 parent bb774f2 commit 920cabf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/julienne/julienne_test_description_m.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ function test_function_i() result(passes)
procedure(test_function_i), pointer, nopass :: test_function_ => null()
contains
procedure run
procedure contains_text
generic :: contains_text => contains_string_t, contains_characters
procedure, private :: contains_string_t, contains_characters
generic :: operator(==) => equals
procedure, private :: equals
procedure, private :: equals
end type

interface test_description_t
Expand Down Expand Up @@ -58,14 +59,22 @@ impure elemental module function run(self) result(test_result)
type(test_result_t) test_result
end function

impure elemental module function contains_text(self, substring) result(match)
!! The result is .true. if the test description includes the value of substring
impure elemental module function contains_string_t(self, substring) result(match)
!! The result is .true. if the test description includes the value of substring
implicit none
class(test_description_t), intent(in) :: self
type(string_t), intent(in) :: substring
logical match
end function

impure elemental module function contains_characters(self, substring) result(match)
!! The result is .true. if the test description includes the value of substring
implicit none
class(test_description_t), intent(in) :: self
character(len=*), intent(in) :: substring
logical match
end function

elemental module function equals(lhs, rhs) result(lhs_eq_rhs)
!! The result is .true. if the components of the lhs & rhs are equal
implicit none
Expand Down
6 changes: 5 additions & 1 deletion src/julienne/julienne_test_description_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
test_result = test_result_t(self%description_, self%test_function_())
end procedure

module procedure contains_text
module procedure contains_string_t
match = index(self%description_%string(), substring%string()) /= 0
end procedure

module procedure contains_characters
match = index(self%description_%string(), substring) /= 0
end procedure

module procedure equals
lhs_eq_rhs = (lhs%description_ == rhs%description_) .and. associated(lhs%test_function_, rhs%test_function_)
end procedure
Expand Down

0 comments on commit 920cabf

Please sign in to comment.