Cover the pacman -Q output parser: simple lines, hyphenated names, empty lines and empty input. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
48 lines
1.4 KiB
C++
48 lines
1.4 KiB
C++
#include "pacman-manager.h"
|
|
#include <cassert>
|
|
#include <iostream>
|
|
|
|
static void testParseInstalledOutput_parsesSimpleLines() {
|
|
std::string output = "firefox 128.0\nvim 9.1.0000\n";
|
|
auto pkgs = PacmanManager::parseInstalledOutput(output);
|
|
|
|
assert(pkgs.size() == 2);
|
|
assert(pkgs[0].name == "firefox");
|
|
assert(pkgs[0].version == "128.0");
|
|
assert(pkgs[0].installed);
|
|
assert(pkgs[1].name == "vim");
|
|
assert(pkgs[1].version == "9.1.0000");
|
|
}
|
|
|
|
static void testParseInstalledOutput_keepsHyphensInNames() {
|
|
// Hyphenated package names must not be split on the dash (python-pip, not python)
|
|
std::string output = "python-pip 24.0-1\n";
|
|
auto pkgs = PacmanManager::parseInstalledOutput(output);
|
|
|
|
assert(pkgs.size() == 1);
|
|
assert(pkgs[0].name == "python-pip");
|
|
assert(pkgs[0].version == "24.0-1");
|
|
}
|
|
|
|
static void testParseInstalledOutput_skipsEmptyLines() {
|
|
std::string output = "firefox 128.0\n\nvim 9.1.0000\n";
|
|
auto pkgs = PacmanManager::parseInstalledOutput(output);
|
|
|
|
assert(pkgs.size() == 2);
|
|
}
|
|
|
|
static void testParseInstalledOutput_emptyInput() {
|
|
auto pkgs = PacmanManager::parseInstalledOutput("");
|
|
assert(pkgs.empty());
|
|
}
|
|
|
|
int main() {
|
|
testParseInstalledOutput_parsesSimpleLines();
|
|
testParseInstalledOutput_keepsHyphensInNames();
|
|
testParseInstalledOutput_skipsEmptyLines();
|
|
testParseInstalledOutput_emptyInput();
|
|
|
|
std::cout << "All pacman-manager tests passed." << std::endl;
|
|
return 0;
|
|
}
|