Skip to content

Commit

Permalink
tests: added unit test for getCompletionId procedure
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 176e0d27577a6744120038d6d050a18c39867243c21dca38a951d7cc5dbc9586
  • Loading branch information
thindil committed Jan 7, 2024
1 parent 87a9a43 commit 027db7e
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions tests/completion.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import std/[os, tables]
import utils/utils
import ../src/[aliases, completion, commandslist, db, lstring, resultcode]
import ../src/[aliases, completion, commandslist, constants, db, lstring, resultcode]
import norm/sqlite
import unittest2

Expand Down Expand Up @@ -45,21 +45,33 @@ suite "Unit tests for completion module":
check:
completions[0] == "something"

test "Getting the shell's completion ID":
checkpoint "Getting ID of an existing completion"
check:
getCompletionId(initLimitedString(capacity = 8, text = "delete 1"),
db).int == 1
checkpoint "Getting ID of a non-existing completion"
check:
getCompletionId(initLimitedString(capacity = 9, text = "delete 22"),
db).int == 0

test "Listing the defined commands' completions":
check:
listCompletion(initLimitedString(capacity = 4, text = "list"), db) == QuitSuccess

test "Deleting a command's completion":
checkpoint "Deleting an existing completion"
check:
deleteCompletion(initLimitedString(capacity = 8, text = "delete 1"), db) == QuitSuccess
deleteCompletion(initLimitedString(capacity = 8, text = "delete 1"),
db) == QuitSuccess
db.count(Completion) == 0
var completion = newCompletion(command = "ala", cType = custom,
cValues = "something")
db.insert(completion)
checkpoint "Deleting a non-existing completion"
check:
deleteCompletion(initLimitedString(capacity = 8, text = "delete 2"), db) == QuitFailure
deleteCompletion(initLimitedString(capacity = 8, text = "delete 2"),
db) == QuitFailure
db.count(Completion) == 1

test "Show a command's completion":
Expand All @@ -73,19 +85,23 @@ suite "Unit tests for completion module":
test "Exporting a command's completion":
checkpoint "Exporting an existing completion"
check:
exportCompletion(initLimitedString(capacity = 17, text = "export 1 test.txt"), db) == QuitSuccess
exportCompletion(initLimitedString(capacity = 17,
text = "export 1 test.txt"), db) == QuitSuccess
checkpoint "Exporting a non-existing completion"
check:
exportCompletion(initLimitedString(capacity = 17, text = "export 2 test.txt"), db) == QuitFailure
exportCompletion(initLimitedString(capacity = 17,
text = "export 2 test.txt"), db) == QuitFailure

test "Importing a command's completion":
checkpoint "Importing a new completion"
discard deleteCompletion(initLimitedString(capacity = 8, text = "delete 1"), db)
check:
importCompletion(initLimitedString(capacity = 15, text = "import test.txt"), db) == QuitSuccess
importCompletion(initLimitedString(capacity = 15,
text = "import test.txt"), db) == QuitSuccess
checkpoint "Importing an existing completion"
check:
importCompletion(initLimitedString(capacity = 15, text = "import test.txt"), db) == QuitFailure
importCompletion(initLimitedString(capacity = 15,
text = "import test.txt"), db) == QuitFailure

suiteTeardown:
closeDb(QuitSuccess.ResultCode, db)

0 comments on commit 027db7e

Please sign in to comment.