diff --git a/tests/input.nim b/tests/input.nim new file mode 100644 index 00000000..f7a85619 --- /dev/null +++ b/tests/input.nim @@ -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 diff --git a/tests/tinput/tinput.nim b/tests/tinput/tinput.nim deleted file mode 100644 index 4a59b979..00000000 --- a/tests/tinput/tinput.nim +++ /dev/null @@ -1,45 +0,0 @@ -discard """ - exitcode: 0 - outputsub: get the next character. Reason -""" - -import std/parseopt -import ../../src/[constants, input, lstring] - -block: - var - userCommand: OptParser = initOptParser("ls -ab --foo --bar=20 file.txt") - conjCommands: bool = true - arguments: UserInput = getArguments(userCommand, conjCommands) - - echo arguments - assert arguments == initLimitedString(capacity = maxInputLength, - text = "ls -ab --foo --bar=20 file.txt"), "Failed to set the argumets." - - assert readInput() == initLimitedString(capacity = maxInputLength, text = "exit") - - assert readChar('c') == "c", "Failed to read a character from the input." - assert readChar('H') == "H", "Failed to read a upper character from the input." - -block: - var - inputString = initLimitedString(capacity = maxInputLength, text = "my text") - cursorPosition: Natural = 1 - deleteChar(inputString, cursorPosition) - assert inputString == "y text", "Failed to delete character from the input." - assert cursorPosition == 0, "Failed to get cursor position after deleting a character." - -block: - let inputString = initLimitedString(capacity = maxInputLength, - text = "my text") - var cursorPosition: Natural = 1 - moveCursor('D', cursorPosition, inputString) - assert cursorPosition == 0, "Failed to move the cursor back in the input." - -block: - var - inputString = initLimitedString(capacity = maxInputLength, text = "my text") - cursorPosition: Natural = 7 - updateInput(cursorPosition, inputString, false, "a") - assert inputString == "my texta", "Failed to insert a character at the end of the input." - assert cursorPosition == 8, "Failed to get the cursor position after inserting a character."