Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a ?? prefix that only affects debug builds. #1

Merged
merged 4 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@ proc your_Very_Special_Proc(...){.uncommentWith: "!! ".}=
## >> echo "won't be uncommented"

```
### ?? prefix for debug builds
When the `??` prefix is used, the operators
will not be uncommented in **release** and **danger** builds.
Don't use it as an argument to the `uncommentWith` pragma.
```nim
proc your_proc_with_release_flag(...) =
## >> echo "hey!"
...
## ?? echo "won't be uncommented"

```
13 changes: 10 additions & 3 deletions src/uncomment.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import macros, strutils, sequtils

const uncommentPrefix {.strdefine.} = ">> "
const
uncommentPrefix {.strdefine.} = ">> "
uncommentPrefixDebug {.used.} = "?? "

proc unCommentResolver(prefix: string, body: NimNode) =
for i, node in body.pairs:
Expand All @@ -10,8 +12,13 @@ proc unCommentResolver(prefix: string, body: NimNode) =

for code in codes:
body[i].add:
if code.startswith prefix: parsestmt code[prefix.len..^1]
else: newCommentStmtNode(code)
when not defined(release) and not defined(danger):
if (code.startswith prefix) or (code.startswith uncommentPrefixDebug):
parsestmt code[prefix.len..^1]
else: newCommentStmtNode(code)
else:
if code.startswith prefix: parsestmt code[prefix.len..^1]
else: newCommentStmtNode(code)

elif body.len > 0:
unCommentResolver prefix, node
Expand Down
22 changes: 22 additions & 0 deletions tests/tdebug.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest
import uncomment


proc multilineDebug(res: var seq[string]){.uncomment.} =
## >> add(res, "Yay")
## >> add(res, "it works")
## ?? add(res, "even with `??` pref")
## >> add(res, "end")

# ------------------------------

test "?? in debug build":
var stemp: seq[string]

multilineDebug(stemp)
check stemp == [
"Yay",
"it works",
"even with `??` pref",
"end"
]
21 changes: 21 additions & 0 deletions tests/tdebugrelease.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest
import uncomment


proc multilineDebug(res: var seq[string]){.uncomment.} =
## >> add(res, "Yay")
## >> add(res, "it works")
## ?? add(res, "but without `??` pref")
## >> add(res, "end")

# ------------------------------

test "?? in release build":
var stemp: seq[string]

multilineDebug(stemp)
check stemp == [
"Yay",
"it works",
"end"
]
2 changes: 2 additions & 0 deletions tests/tdebugrelease.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
switch("path", "$projectDir/../src")
switch("define", "release")
4 changes: 3 additions & 1 deletion uncomment.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.0.2"
version = "0.0.3"
author = "hamidb80"
description = "uncomment the codes at the compile time"
license = "MIT"
Expand All @@ -10,6 +10,8 @@ srcDir = "src"
task test, "test the app":
exec "nim r ./tests/twith.nim"
exec "nim -d:uncommentPrefix=\"!! \" r tests/tcommon.nim"
exec "nim r ./tests/tdebug.nim"
exec "nim r ./tests/tdebugrelease.nim"

# Dependencies
requires "nim >= 1.4.8"