Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CMake with GoogleTest on multiple platforms

on:
pull_request:
branches: "*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install compiler
id: install_cc
uses: rlalik/setup-cpp-compiler@master
with:
compiler: latest

- name: Configure CMake
run: >
cmake -B build
-DCMAKE_CXX_COMPILER=${{ steps.install_cc.outputs.cxx }}
-DCMAKE_C_COMPILER=${{ steps.install_cc.outputs.cc }}
-DCMAKE_BUILD_TYPE=Debug
-S ${{ github.workspace }}

- name: Build
run: cmake --build build --parallel

- name: Test
working-directory: build
run: ctest --output-on-failure
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ project (multini)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(${PROJECT_NAME} INTERFACE
multini.hh
)
target_include_directories(${PROJECT_NAME} INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)

# Check if cmake is being used directly or via add_subdirectory
if(NOT MULTINI_TESTS AND CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MULTINI_TESTS ON)
endif()

if (MULTINI_TESTS)

include(FetchContent)
FetchContent_Declare(
googletest
Expand All @@ -21,8 +35,11 @@ add_executable (multini_tests multini_tests.cc multini.hh)

target_link_libraries(
multini_tests
${PROJECT_NAME}
GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(multini_tests)

endif()
5 changes: 5 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"name": "windows",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/build"
},
{
"name": "linux",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build"
}
]
}
26 changes: 13 additions & 13 deletions multini.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public:
}

private:
static auto countPrefix(const std::string_view& sv, char ch)
{
return std::ranges::distance(sv
| std::views::take_while([ch](char c) { return c == ch; }));
}

static auto countSuffix(const std::string_view& sv, char ch)
{
return std::ranges::distance(sv
| std::views::reverse
| std::views::take_while([ch](char c) { return c == ch; }));
}

class Line {
public:
Line(const std::string_view& line, int lineNum = 0, ErrorBag* errors = nullptr)
Expand Down Expand Up @@ -121,19 +134,6 @@ private:
});
}

static auto countPrefix(const std::string_view& sv, char ch)
{
return std::ranges::distance(sv
| std::views::take_while([ch](char c) { return c == ch; }));
}

static auto countSuffix(const std::string_view& sv, char ch)
{
return std::ranges::distance(sv
| std::views::reverse
| std::views::take_while([ch](char c) { return c == ch; }));
}

ErrorBag mErrors {};
std::multimap<std::string, std::map<std::string, std::string>> mSections {};
};
Expand Down