Skip to content

Commit

Permalink
test(string_t):allow larger numeric representation
Browse files Browse the repository at this point in the history
  • Loading branch information
rouson committed Jan 29, 2024
1 parent cc823d9 commit 68b3d37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/sourcery/sourcery_string_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
end procedure

module procedure from_real
integer, parameter :: sign_ = 1, decimal_ = 1, digits = precision(x) + 3, exponent_width = 4
character(len=sign_ + decimal_ + digits + exponent_width) characters
integer, parameter :: sign_ = 1, decimal_ = 1, digits = precision(x) + 6, exponent = 4
character(len=sign_ + decimal_ + digits + exponent) characters
write(characters, '(g0)') x
string = string_t(characters)
end procedure
Expand Down
10 changes: 8 additions & 2 deletions test/string_test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ 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
Expand All @@ -157,34 +158,39 @@ function supports_concatenation_operator() result(passed)

function constructs_from_default_integer() result(passed)
logical passed

associate(string => string_t(1234567890))
passed = adjustl(trim(string%string())) == "1234567890"
end associate
end function

function constructs_from_real() result(passed)
logical passed
associate(string => string_t(123456789E+09))
passed = adjustl(trim(string%string())) == "0.123456791E+18"

associate(string => string_t(-1.53018260E-15))
passed = adjustl(trim(string%string())) == "-0.153018260E-14"
end associate
end function

function extracts_file_base_name() result(passed)
logical passed

associate(string => string_t(" foo .bar.too "))
passed = string%base_name() == "foo .bar"
end associate
end function

function extracts_file_name_extension() result(passed)
logical passed

associate(string => string_t(" foo .bar.too "))
passed = string%file_extension() == "too"
end associate
end function

function concatenates_elements() result(passed)
logical passed

associate(elements => [string_t("foo"), string_t("bar")])
passed = .cat. elements == "foobar"
end associate
Expand Down

0 comments on commit 68b3d37

Please sign in to comment.