change some code-blocks to runnableExamples and correct some errors in docs (#15900)

* original docs are wrong
* fix pathnorm
* Update lib/pure/pathnorm.nim

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
This commit is contained in:
flywind 2020-11-12 17:47:56 +08:00 • committed by GitHub
commit ef2677f5f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 57 deletions

View file

@ -100,15 +100,13 @@ proc addNormalizePath*(x: string; result: var string; state: var int;
if result == "" and x != "": result = "."
proc normalizePath*(path: string; dirSep = DirSep): string =
## Example:
##
## .. code-block:: nim
## assert normalizePath("./foo//bar/../baz") == "foo/baz"
##
##
runnableExamples:
when defined(posix):
doAssert normalizePath("./foo//bar/../baz") == "foo/baz"
## - Turns multiple slashes into single slashes.
## - Resolves '/foo/../bar' to '/bar'.
## - Removes './' from the path (but "foo/.." becomes ".")
## - Resolves `'/foo/../bar'` to `'/bar'`.
## - Removes `'./'` from the path, but `"foo/.."` becomes `"."`.
result = newStringOfCap(path.len)
var state = 0
addNormalizePath(path, result, state, dirSep)