Skip to content

Commit

Permalink
tests: moved unit tests for input module
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 233a3d8883e9fdfaf918a9ce15535d21af698748faf09bb329834d8cb19631a6
  • Loading branch information
thindil committed Oct 17, 2023
1 parent e660deb commit e580fb3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
50 changes: 50 additions & 0 deletions tests/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import std/parseopt
import ../src/[constants, input, lstring]
import unittest2

suite "Unit tests for input module":

test "getArguments":
var
userCommand: OptParser = initOptParser("ls -ab --foo --bar=20 file.txt")
conjCommands: bool = true
arguments: UserInput = getArguments(userCommand, conjCommands)
check:
arguments == initLimitedString(capacity = maxInputLength,
text = "ls -ab --foo --bar=20 file.txt")

test "readInput":
echo "exit"
check:
readInput() == initLimitedString(capacity = maxInputLength, text = "exit")

test "readChar":
check:
readChar('c') == "c"
readChar('H') == "H"

test "deleteChar":
var
inputString = initLimitedString(capacity = maxInputLength, text = "my text")
cursorPosition: Natural = 1
deleteChar(inputString, cursorPosition)
check:
inputString == "y text"
cursorPosition == 0

test "moveCursor":
let inputString = initLimitedString(capacity = maxInputLength,
text = "my text")
var cursorPosition: Natural = 1
moveCursor('D', cursorPosition, inputString)
check:
cursorPosition == 0

test "updateInput":
var
inputString = initLimitedString(capacity = maxInputLength, text = "my text")
cursorPosition: Natural = 7
updateInput(cursorPosition, inputString, false, "a")
check:
inputString == "my texta"
cursorPosition == 8
45 changes: 0 additions & 45 deletions tests/tinput/tinput.nim

This file was deleted.

0 comments on commit e580fb3

Please sign in to comment.