-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
CommonTests.kt
64 lines (55 loc) · 2.14 KB
/
CommonTests.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import com.linuxcommandlibrary.shared.CommandElement
import com.linuxcommandlibrary.shared.getCommandList
import com.linuxcommandlibrary.shared.getHtmlFileName
import com.linuxcommandlibrary.shared.getSortPriority
import com.linuxcommandlibrary.shared.search
import databases.BasicCategory
import databases.Command
import databases.CommandSection
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class CommonTests {
@Test
fun testCommandListElements() {
val command = "ps ax | grep firefox"
val elements = command.getCommandList("ps,grep")
assertTrue(elements.count { it is CommandElement.Man } == 2)
}
@Test
fun testCommandListSearch() {
val commands = listOf(
Command(0, 0, "img2webp", "convert image to webp"),
Command(0, 0, "optipng", "convert"),
Command(0, 0, "thumbnail", "take png and do something"),
Command(0, 0, "Pngcheck", "print detailed"),
Command(0, 0, "png", "png"),
)
val filteredCommands = commands.search("png")
assert(filteredCommands.size == 4)
assertEquals(filteredCommands[0].name, "png")
assertEquals(filteredCommands[1].name, "Pngcheck")
assertEquals(filteredCommands[2].name, "optipng")
assertEquals(filteredCommands[3].name, "thumbnail")
}
@Test
fun testBasicCategory() {
val category = BasicCategory(0L, 0L, "Users & Groups 2")
assertEquals(category.getHtmlFileName(), "usersgroups")
}
@Test
fun testSectionSorting() {
val sections = listOf(
CommandSection(0L, "SEE ALSO", "", 0L),
CommandSection(0L, "RANDOM", "", 0L),
CommandSection(0L, "TLDR", "", 0L),
CommandSection(0L, "AUTHOR", "", 0L),
CommandSection(0L, "SYNOPSIS", "", 0L),
).sortedBy { it.getSortPriority() }
assertEquals("TLDR", sections[0].title)
assertEquals("SYNOPSIS", sections[1].title)
assertEquals("RANDOM", sections[2].title)
assertEquals("SEE ALSO", sections[3].title)
assertEquals("AUTHOR", sections[4].title)
}
}