Skip to content

Commit

Permalink
Added basic unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiRegiani committed Mar 17, 2018
1 parent a9705ce commit d1468e1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
nimcache/
inim
inim_*
inim_*
test
8 changes: 4 additions & 4 deletions src/inim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var
indentationLevel = 0 # Current
buffer: File

proc getNimVersion(): string =
proc getNimVersion*(): string =
let (output, status) = execCmdEx("nim --version")
if status != 0:
echo "inim: Program \"nim\" not found in PATH"
Expand Down Expand Up @@ -69,7 +69,7 @@ proc showError(output: string) =
let pos = output.find(")") + 2
echo output[pos..^1].strip

proc endsWithIndentation(line: string): bool =
proc triggerIndentation*(line: string): bool =
if line.len > 0:
for trigger in indentationTriggers:
if line.strip().endsWith(trigger):
Expand All @@ -96,13 +96,13 @@ proc runForever() =
buffer.flushFile()

# Check for indentation
if myline.endsWithIndentation:
if myline.triggerIndentation:
indentationLevel += 1

# Don't run yet if still on indentation
if indentationLevel != 0:
# Skip indentation for first line
if myline.endsWithIndentation:
if myline.triggerIndentation:
tempIndentCode &= indentationSpaces.repeat(indentationLevel-1) & myline & "\n"
else:
tempIndentCode &= indentationSpaces.repeat(indentationLevel) & myline & "\n"
Expand Down
13 changes: 13 additions & 0 deletions tests/test.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import inim

doAssert(getNimVersion()[0..2] == "Nim")

doAssert(triggerIndentation("var") == true)
doAssert(triggerIndentation("var x:int") == false)
doAssert(triggerIndentation("var x:int = 10") == false)
doAssert(triggerIndentation("let") == true)
doAssert(triggerIndentation("const") == true)
doAssert(triggerIndentation("if foo == 1: ") == true)
doAssert(triggerIndentation("proc fooBar(a, b: string): int = ") == true)
doAssert(triggerIndentation("for i in 0..10:") == true)
doAssert(triggerIndentation("for i in 0..10") == false)
1 change: 1 addition & 0 deletions tests/test.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
switch("path", "$projectDir/../src")

0 comments on commit d1468e1

Please sign in to comment.