1
0

test: scan

This commit is contained in:
2026-02-21 14:47:30 +02:00
parent 0f40f89cbb
commit 6a3a7541ea
6 changed files with 73 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
# Command
v 0.1 0.2 0.3
v 0.2 0.3 0.4
v 0.3 0.4 0.5
@@ -18,3 +19,8 @@ o test
f 4/3/2 5/2/1 6/1/2
g test
f 7/2/2 8/3/2 9/1/1
o
f 8/1/1 5/2/2 3/3/2
g
f 2/1/1 6/2/2 4/3/2
h this line is skipped

64
tests/unit/scan_test.cpp Normal file
View File

@@ -0,0 +1,64 @@
#include <filesystem>
#include <fstream>
#include <gtest/gtest.h>
#include "scan.hpp"
namespace {
std::filesystem::path test_data_path(const std::string &filename) {
const auto here = std::filesystem::path(__FILE__).parent_path();
return here.parent_path() / "data" / filename;
}
TEST(Scan, ReadsAllSupportedTypes) {
std::ifstream input(test_data_path("test-scan-1.txt"));
ASSERT_TRUE(input.is_open());
const auto result = wavefront::scan(input);
EXPECT_EQ(result.total_lines, 26u);
EXPECT_EQ(result.line_data.size(), 21u);
EXPECT_TRUE(result.category_map.contains("v"));
EXPECT_TRUE(result.category_map.contains("vn"));
EXPECT_TRUE(result.category_map.contains("vt"));
EXPECT_TRUE(result.category_map.contains("f"));
EXPECT_EQ(result.category_map.at("v").size(), 10u);
EXPECT_EQ(result.category_map.at("vn").size(), 4u);
EXPECT_EQ(result.category_map.at("vt").size(), 3u);
EXPECT_EQ(result.category_map.at("f").size(), 5u);
}
TEST(Scan, FiltersByObject) {
std::ifstream input(test_data_path("test-scan-1.txt"));
ASSERT_TRUE(input.is_open());
const auto result = wavefront::scan(input, {"test"});
EXPECT_EQ(result.category_map.at("f").size(), 4u);
EXPECT_EQ(result.category_map.at("f")[0], 19u);
EXPECT_EQ(result.category_map.at("f")[1], 21u);
}
TEST(Scan, FiltersByGroup) {
std::ifstream input(test_data_path("test-scan-1.txt"));
ASSERT_TRUE(input.is_open());
const auto result = wavefront::scan(input, {}, {"test"});
EXPECT_EQ(result.category_map.at("f").size(), 3u);
EXPECT_EQ(result.category_map.at("f")[0], 21u);
}
TEST(Scan, FiltersByObjectAndGroup) {
std::ifstream input(test_data_path("test-scan-1.txt"));
ASSERT_TRUE(input.is_open());
const auto result = wavefront::scan(input, {"test"}, {"test"});
EXPECT_EQ(result.category_map.at("f").size(), 3u);
EXPECT_EQ(result.category_map.at("f")[0], 21u);
}
}