Skip to content

Commit 8b19b35

Browse files
committed
improved documentation and added new test cases
1 parent b79da24 commit 8b19b35

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

doc/specs/stdlib_string_type.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ end program demo
19811981

19821982
Moves the allocation from `from` to `to`, consequently deallocating `from` in this process.
19831983
If `from` is not allocated before execution, `to` gets deallocated by the process.
1984-
An unallocated string is equivalent to an empty string.
1984+
An unallocated `string_type` instance is equivalent to an empty string.
19851985

19861986
#### Syntax
19871987

@@ -2005,25 +2005,25 @@ Pure Subroutine.
20052005
#### Example
20062006

20072007
```fortran
2008-
program demo
2008+
program demo_move
20092009
use stdlib_string_type, only : string_type, assignment(=), move
20102010
implicit none
2011-
type(string_type) :: from_string, to_string
2012-
character(len=:), allocatable :: from_char
2011+
type(string_type) :: from_string
2012+
character(len=:), allocatable :: from_char, to_char
20132013
20142014
from_string = "move this string"
20152015
from_char = "move this char"
20162016
! from_string <-- "move this string"
20172017
! from_char <-- "move this char"
2018-
! to_string <-- "" (unallocated)
2018+
! to_char <-- (unallocated)
20192019
2020-
call move(from_string, to_string)
2021-
! from_string <-- "" (unallocated)
2022-
! to_string <-- "move this string"
2020+
call move(from_string, to_char)
2021+
! from_string <-- ""
2022+
! to_char <-- "move this string"
20232023
2024-
call move(from_char, to_string)
2024+
call move(from_char, to_char)
20252025
! from_char <-- (unallocated)
20262026
! to_string <-- "move this char"
20272027
2028-
end program demo
2028+
end program demo_move
20292029
```

src/tests/string/test_string_intrinsic.f90

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,14 @@ subroutine test_iachar
464464
end subroutine test_iachar
465465

466466
subroutine test_move
467-
type(string_type) :: from_string
468-
type(string_type) :: to_string
469-
character(len=:), allocatable :: from_char
467+
type(string_type) :: from_string, to_string
468+
character(len=:), allocatable :: from_char, to_char
470469

471470
from_string = "Move This String"
472471
from_char = "Move This Char"
473472
call check(from_string == "Move This String" .and. to_string == "" .and. &
474-
& from_char == "Move This Char", "move: test_case 1")
473+
& from_char == "Move This Char" .and. .not. allocated(to_char), &
474+
& "move: test_case 1")
475475

476476
! string_type (allocated) --> string_type (not allocated)
477477
call move(from_string, to_string)
@@ -483,17 +483,27 @@ subroutine test_move
483483
& "move: test_case 3")
484484

485485
! string_type (allocated) --> character (not allocated)
486-
call move(to_string, from_char)
487-
call check(to_string == "" .and. from_char == "Move This String", "move: test_case 4")
486+
call move(to_string, to_char)
487+
call check(to_string == "" .and. to_char == "Move This String", "move: test_case 4")
488488

489489
! character (allocated) --> string_type (allocated)
490-
call move(from_char, from_string)
491-
call check(.not. allocated(from_char) .and. from_string == "Move This String", &
490+
call move(to_char, from_string)
491+
call check(.not. allocated(to_char) .and. from_string == "Move This String", &
492492
& "move: test_case 5")
493493

494+
from_char = "new char"
494495
! character (allocated) --> string_type (allocated)
495496
call move(from_char, from_string)
496-
call check(.not. allocated(from_char) .and. from_string == "", "move: test_case 6")
497+
call check(.not. allocated(from_char) .and. from_string == "new char", "move: test_case 6")
498+
499+
! character (unallocated) --> string_type (allocated)
500+
call move(from_char, from_string)
501+
call check(from_string == "", "move: test_case 7")
502+
503+
from_string = "moving to self"
504+
! string_type (allocated) --> string_type (allocated)
505+
call move(from_string, from_string)
506+
call check(from_string == "", "move: test_case 8")
497507

498508
end subroutine test_move
499509

0 commit comments

Comments
 (0)