mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
Compare commits
64 Commits
v1.6.0
...
improvemen
| Author | SHA1 | Date | |
|---|---|---|---|
| d978e986de | |||
| 99d445bafe | |||
| 397cf21d18 | |||
| eb8f205300 | |||
| b618384054 | |||
| 4e4c3a6e02 | |||
| 0b3b719155 | |||
| 4bedc32b63 | |||
| 7822351a0b | |||
| a755f6c455 | |||
|
|
4db88c0490 | ||
| 8b72deb1ed | |||
| 672b89b213 | |||
| b9d2c2aad9 | |||
| 32cbfe1d17 | |||
| 848689451c | |||
| b7e5dd28b8 | |||
| e316558a7b | |||
| 1c6eacad30 | |||
| 5ac506d8f0 | |||
| 6e27f35209 | |||
| 49a3a20e68 | |||
| 1d0911ab3c | |||
| 7d3d02f11d | |||
| 17c21e260f | |||
| 2504c3574d | |||
| 0bd78120f3 | |||
| ed8f4e3147 | |||
| d4c9227830 | |||
| f232c7d995 | |||
| 14ccb88664 | |||
|
|
34833837ba | ||
| 5f27595ec1 | |||
| 65371d05f3 | |||
| 31b924736f | |||
| ffca94d47d | |||
| 7ba66ff99d | |||
| f1e127dd2b | |||
| 3e3eb1b61c | |||
| b9d8eb860e | |||
| 4139b50cd9 | |||
| 8924ad12e5 | |||
| 254bd24bbd | |||
| 55d1bbcf86 | |||
| 3e3c922624 | |||
| c0e6e56364 | |||
| 66f57ba66a | |||
| d37ec12bb5 | |||
| 9d7441b178 | |||
| dcf7e924ad | |||
| 41c4bf9d35 | |||
| 7b16f24d03 | |||
| 535138d9b8 | |||
| f106889ada | |||
| e7045ce437 | |||
| d86c8e9fe8 | |||
| c0ef691889 | |||
| 80c189f9c5 | |||
| 07373ea043 | |||
| 236b5da9c2 | |||
| a1f01ec5cb | |||
| cd6c2df359 | |||
| 9afe24785b | |||
| 479cf4bbe7 |
71
.github/workflows/coverage.yml
vendored
Normal file
71
.github/workflows/coverage.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
name: coverage-ci
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- feature/**
|
||||
- improvement/**
|
||||
- bugfix/**
|
||||
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- feature/**
|
||||
- improvement/**
|
||||
- bugfix/**
|
||||
|
||||
jobs:
|
||||
test_coverage:
|
||||
if: >-
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: "Coverage"
|
||||
|
||||
container:
|
||||
image: gcc:latest
|
||||
options: -v /usr/local:/host_usr_local
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- uses: friendlyanon/fetch-core-count@v1
|
||||
id: cores
|
||||
|
||||
- name: CMake
|
||||
run: echo "/host_usr_local/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install dependencies
|
||||
run: script/ci_install_deps.sh
|
||||
|
||||
- name: Install test coverage tools
|
||||
run: |
|
||||
apt update
|
||||
apt install -y gcovr lcov
|
||||
|
||||
- name: Configure
|
||||
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug -D CMAKE_CXX_FLAGS="-Wall -fprofile-arcs -ftest-coverage --coverage"
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build -j ${{steps.cores.outputs.count}}
|
||||
|
||||
- name: Run
|
||||
working-directory: build
|
||||
run: ctest --output-on-failure -j ${{steps.cores.outputs.count}}
|
||||
|
||||
- name: Generate coverage report
|
||||
run: |
|
||||
lcov -d . -c -o out.info --rc lcov_branch_coverage=1 --no-external
|
||||
lcov -e out.info '*include/ss*hpp' -o filtered.info
|
||||
|
||||
- name: Invoke coveralls
|
||||
uses: coverallsapp/github-action@v2
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
file: filtered.info
|
||||
format: lcov
|
||||
51
.github/workflows/single-header.yml
vendored
Normal file
51
.github/workflows/single-header.yml
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
name: single-header-ci
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- feature/**
|
||||
- improvement/**
|
||||
- bugfix/**
|
||||
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- feature/**
|
||||
- improvement/**
|
||||
- bugfix/**
|
||||
|
||||
jobs:
|
||||
single_header_tests:
|
||||
if: >-
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: "Single Header Test"
|
||||
|
||||
container:
|
||||
image: gcc:latest
|
||||
options: -v /usr/local:/host_usr_local
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- uses: friendlyanon/fetch-core-count@v1
|
||||
id: cores
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y git
|
||||
|
||||
- name: Single header update check
|
||||
run: |
|
||||
script/single_header_generator.py > tmp.hpp
|
||||
diff ssp.hpp tmp.hpp
|
||||
|
||||
- name: Single header compile check
|
||||
run: ./test/test_single_header.sh
|
||||
22
.github/workflows/ubuntu-latest-clang.yml
vendored
22
.github/workflows/ubuntu-latest-clang.yml
vendored
@@ -1,6 +1,8 @@
|
||||
name: ubuntu-latest-clang-ci
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
@@ -23,20 +25,22 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
version: [11, 10, 9, 8, 7]
|
||||
# cmake clang12 is not able to compile a simple test program.
|
||||
# /usr/bin/ld: cannot find -lunwind
|
||||
version: ['latest', '15', '14', '13', '11', '10', '9', '8', '7']
|
||||
type: [Release, Debug]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: Clang ${{ matrix.version }}
|
||||
name: "Clang ${{matrix.version}}: ${{matrix.type}}"
|
||||
|
||||
container:
|
||||
image: teeks99/clang-ubuntu:${{ matrix.version }}
|
||||
|
||||
image: silkeh/clang:${{matrix.version}}
|
||||
options: -v /usr/local:/host_usr_local
|
||||
|
||||
env:
|
||||
CC: clang-${{ matrix.version }}
|
||||
CXX: clang++-${{ matrix.version }}
|
||||
CC: clang
|
||||
CXX: clang++
|
||||
CXXFLAGS: -stdlib=libc++
|
||||
|
||||
steps:
|
||||
@@ -55,11 +59,11 @@ jobs:
|
||||
script/ci_install_deps.sh
|
||||
|
||||
- name: Configure
|
||||
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug
|
||||
run: cmake -S test -B build -DCMAKE_BUILD_TYPE=${{matrix.type}}
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build -j ${{ steps.cores.outputs.count }}
|
||||
run: cmake --build build -j ${{steps.cores.outputs.count}}
|
||||
|
||||
- name: Run
|
||||
working-directory: build
|
||||
run: ctest --output-on-failure -j ${{ steps.cores.outputs.count }}
|
||||
run: ctest --output-on-failure -j ${{steps.cores.outputs.count}}
|
||||
|
||||
16
.github/workflows/ubuntu-latest-gcc.yml
vendored
16
.github/workflows/ubuntu-latest-gcc.yml
vendored
@@ -1,6 +1,8 @@
|
||||
name: ubuntu-latest-gcc-ci
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
@@ -23,15 +25,15 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
version: [10, 9, 8]
|
||||
version: ['latest', '12', '11', '10', '9', '8']
|
||||
type: [Release, Debug]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: GCC ${{ matrix.version }}
|
||||
name: "GCC ${{matrix.version}}: ${{matrix.type}}"
|
||||
|
||||
container:
|
||||
image: gcc:${{ matrix.version }}
|
||||
|
||||
image: gcc:${{matrix.version}}
|
||||
options: -v /usr/local:/host_usr_local
|
||||
|
||||
steps:
|
||||
@@ -47,11 +49,11 @@ jobs:
|
||||
run: script/ci_install_deps.sh
|
||||
|
||||
- name: Configure
|
||||
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug
|
||||
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=${{matrix.type}}
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build -j ${{ steps.cores.outputs.count }}
|
||||
run: cmake --build build -j ${{steps.cores.outputs.count}}
|
||||
|
||||
- name: Run
|
||||
working-directory: build
|
||||
run: ctest --output-on-failure -j ${{ steps.cores.outputs.count }}
|
||||
run: ctest --output-on-failure -j ${{steps.cores.outputs.count}}
|
||||
|
||||
62
.github/workflows/ubuntu-latest-icc.yml
vendored
62
.github/workflows/ubuntu-latest-icc.yml
vendored
@@ -1,6 +1,8 @@
|
||||
name: ubuntu-latest-icc-ci
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
@@ -17,7 +19,7 @@ on:
|
||||
|
||||
env:
|
||||
LINUX_BASEKIT_URL: https://registrationcenter-download.intel.com/akdlm/irc_nas/17431/l_BaseKit_p_2021.1.0.2659_offline.sh
|
||||
LINUX_HPCKIT_URL:
|
||||
LINUX_HPCKIT_URL:
|
||||
https://registrationcenter-download.intel.com/akdlm/irc_nas/17427/l_HPCKit_p_2021.1.0.2684_offline.sh
|
||||
|
||||
jobs:
|
||||
@@ -27,6 +29,7 @@ jobs:
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
@@ -36,38 +39,39 @@ jobs:
|
||||
options: -v /usr/local:/host_usr_local
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: cache install
|
||||
id: cache-install
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
/opt/intel/oneapi/compiler
|
||||
key: >-
|
||||
install-${{ env.LINUX_HPCKIT_URL }}-
|
||||
${{ env.LINUX_CPP_COMPONENTS_WEB }}-
|
||||
compiler-${{ hashFiles('**/scripts/cache_exclude_linux.sh') }}
|
||||
- name: cache install
|
||||
id: cache-install
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
/opt/intel/oneapi/compiler
|
||||
key: >-
|
||||
install-${{env.LINUX_HPCKIT_URL}}-
|
||||
${{env.LINUX_CPP_COMPONENTS_WEB}}-
|
||||
compiler-${{hashFiles('**/scripts/cache_exclude_linux.sh')}}
|
||||
|
||||
- name: Install icc
|
||||
run: script/ci_install_icc.sh $LINUX_HPCKIT_URL $LINUX_CPP_COMPONENTS_WEB
|
||||
- name: Install icc
|
||||
run: >-
|
||||
script/ci_install_icc.sh $LINUX_HPCKIT_URL $LINUX_CPP_COMPONENTS_WEB
|
||||
|
||||
- name: CMake
|
||||
run: echo "/host_usr_local/bin" >> $GITHUB_PATH
|
||||
- name: CMake
|
||||
run: echo "/host_usr_local/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install dependencies
|
||||
run: script/ci_install_deps.sh
|
||||
- name: Install dependencies
|
||||
run: script/ci_install_deps.sh
|
||||
|
||||
- name: Configure
|
||||
run: >-
|
||||
source script/ci_setup_icc.sh &&
|
||||
cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug
|
||||
- name: Configure
|
||||
run: >-
|
||||
source script/ci_setup_icc.sh &&
|
||||
cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug
|
||||
|
||||
- name: Build
|
||||
run: >-
|
||||
source script/ci_setup_icc.sh &&
|
||||
cmake --build build -j ${{ steps.cores.outputs.count }}
|
||||
- name: Build
|
||||
run: >-
|
||||
source script/ci_setup_icc.sh &&
|
||||
cmake --build build -j ${{steps.cores.outputs.count}}
|
||||
|
||||
- name: Run
|
||||
working-directory: build
|
||||
run: ctest --output-on-failure -j ${{ steps.cores.outputs.count }}
|
||||
- name: Run
|
||||
working-directory: build
|
||||
run: ctest --output-on-failure -j ${{steps.cores.outputs.count}}
|
||||
|
||||
8
.github/workflows/win-msvc.yml
vendored
8
.github/workflows/win-msvc.yml
vendored
@@ -1,6 +1,8 @@
|
||||
name: win-msvc-ci
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
@@ -25,8 +27,6 @@ jobs:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
runs-on: ${{ matrix.config.os }}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -40,7 +40,9 @@ jobs:
|
||||
build: [Debug, Release]
|
||||
platform: [Win32, x64]
|
||||
|
||||
name: "${{matrix.config.vs}}:${{matrix.platform}}:${{matrix.build}}"
|
||||
runs-on: ${{matrix.config.os}}
|
||||
|
||||
name: "${{matrix.config.vs}}: ${{matrix.platform}}: ${{matrix.build}}"
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
|
||||
47
.github/workflows/win-msys2-clang.yml
vendored
47
.github/workflows/win-msys2-clang.yml
vendored
@@ -1,6 +1,8 @@
|
||||
name: win-msys2-clang-ci
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
@@ -21,57 +23,54 @@ jobs:
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||
|
||||
name: ${{ matrix.msystem }}
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
||||
matrix:
|
||||
include:
|
||||
os: [windows-2019, windows-latest]
|
||||
type: [Release, Debug]
|
||||
config:
|
||||
- msystem: "MINGW64"
|
||||
install: >-
|
||||
git mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
|
||||
git mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
|
||||
mingw-w64-x86_64-clang
|
||||
type: Release
|
||||
|
||||
- msystem: "MINGW32"
|
||||
install: >-
|
||||
git mingw-w64-i686-cmake mingw-w64-i686-ninja
|
||||
git mingw-w64-i686-cmake mingw-w64-i686-ninja
|
||||
mingw-w64-i686-clang
|
||||
type: Release
|
||||
- msystem: "MINGW64"
|
||||
install: >-
|
||||
git mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
|
||||
mingw-w64-x86_64-clang
|
||||
type: Debug
|
||||
- msystem: "MINGW32"
|
||||
install: >-
|
||||
git mingw-w64-i686-cmake mingw-w64-i686-ninja
|
||||
mingw-w64-i686-clang
|
||||
type: Debug
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
name: "${{matrix.config.msystem}}: ${{matrix.os}}: ${{matrix.type}}"
|
||||
|
||||
env:
|
||||
CMAKE_GENERATOR: Ninja
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
update: true
|
||||
msystem: ${{ matrix.msystem }}
|
||||
install: ${{ matrix.install }}
|
||||
msystem: ${{matrix.config.msystem}}
|
||||
install: ${{matrix.config.install}}
|
||||
|
||||
- name: Install dependencies
|
||||
run: script/ci_install_deps.sh
|
||||
|
||||
- name: Configure
|
||||
run: >-
|
||||
cmake -DCMAKE_CXX_COMPILER=clang++ -S test -B build
|
||||
-DCMAKE_BUILD_TYPE=Debug
|
||||
run: >-
|
||||
cmake -DCMAKE_CXX_COMPILER=clang++ -S test -B build
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.type}}
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build -j ${{ steps.cores.outputs.count }}
|
||||
run: cmake --build build -j ${{steps.cores.outputs.count}}
|
||||
|
||||
- name: Run
|
||||
working-directory: build
|
||||
run: ctest --output-on-failure -j ${{ steps.cores.outputs.count }}
|
||||
run: ctest --output-on-failure -j ${{steps.cores.outputs.count}}
|
||||
|
||||
43
.github/workflows/win-msys2-gcc.yml
vendored
43
.github/workflows/win-msys2-gcc.yml
vendored
@@ -1,6 +1,8 @@
|
||||
name: win-msys2-gcc-ci
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
@@ -21,55 +23,52 @@ jobs:
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||
|
||||
name: ${{ matrix.msystem }}
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
||||
matrix:
|
||||
include:
|
||||
os: [windows-2019, windows-latest]
|
||||
type: [Release, Debug]
|
||||
config:
|
||||
- msystem: "MINGW64"
|
||||
install: >-
|
||||
git mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
|
||||
git mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
|
||||
mingw-w64-x86_64-gcc
|
||||
type: Release
|
||||
- msystem: "MINGW32"
|
||||
install: >-
|
||||
git mingw-w64-i686-cmake mingw-w64-i686-ninja
|
||||
mingw-w64-i686-gcc
|
||||
type: Release
|
||||
- msystem: "MINGW64"
|
||||
install: >-
|
||||
git mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
|
||||
mingw-w64-x86_64-gcc
|
||||
type: Debug
|
||||
|
||||
- msystem: "MINGW32"
|
||||
install: >-
|
||||
git mingw-w64-i686-cmake mingw-w64-i686-ninja
|
||||
git mingw-w64-i686-cmake mingw-w64-i686-ninja
|
||||
mingw-w64-i686-gcc
|
||||
type: Debug
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
name: "${{matrix.config.msystem}}: ${{matrix.os}}: ${{matrix.type}}"
|
||||
|
||||
env:
|
||||
CMAKE_GENERATOR: Ninja
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
update: true
|
||||
msystem: ${{ matrix.msystem }}
|
||||
install: ${{ matrix.install }}
|
||||
msystem: ${{matrix.config.msystem}}
|
||||
install: ${{matrix.config.install}}
|
||||
|
||||
- name: Install dependencies
|
||||
run: script/ci_install_deps.sh
|
||||
|
||||
- name: Configure
|
||||
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug
|
||||
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=${{matrix.type}}
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build -j ${{ steps.cores.outputs.count }}
|
||||
run: cmake --build build -j ${{steps.cores.outputs.count}}
|
||||
|
||||
- name: Run
|
||||
working-directory: build
|
||||
run: ctest --output-on-failure -j ${{ steps.cores.outputs.count }}
|
||||
run: ctest --output-on-failure -j ${{steps.cores.outputs.count}}
|
||||
|
||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(
|
||||
ssp
|
||||
VERSION 1.5.0
|
||||
VERSION 1.6.1
|
||||
DESCRIPTION "csv parser"
|
||||
HOMEPAGE_URL "https://github.com/red0124/ssp"
|
||||
LANGUAGES CXX
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
```
|
||||
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://coveralls.io/github/red0124/ssp?branch=master)
|
||||
[](https://github.com/red0124/ssp/actions/workflows/single-header.yml)
|
||||
[](https://github.com/red0124/ssp/actions/workflows/ubuntu-latest-gcc.yml)
|
||||
[](https://github.com/red0124/ssp/actions/workflows/ubuntu-latest-clang.yml)
|
||||
[](https://github.com/red0124/ssp/actions/workflows/ubuntu-latest-icc.yml)
|
||||
[](https://github.com/red0124/ssp/actions/workflows/win-msys2-gcc.yml)
|
||||
[](https://github.com/red0124/ssp/actions/workflows/win-msys2-clang.yml)
|
||||
[](https://github.com/red0124/ssp/actions/workflows/win-msvc.yml)
|
||||
[](https://github.com/red0124/ssp/actions/workflows/win-msvc.yml)
|
||||
|
||||
A header only "csv" parser which is fast and versatile with modern C++ api. Requires compiler with C++17 support. [Can also be used to convert strings to specific types.](#the-converter)
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
namespace ss {
|
||||
|
||||
struct none {};
|
||||
|
||||
using string_range = std::pair<const char*, const char*>;
|
||||
@@ -24,61 +20,4 @@ inline void assert_throw_on_error_not_defined() {
|
||||
static_assert(!ThrowOnError, "cannot handle errors manually if "
|
||||
"'throw_on_error' is enabled");
|
||||
}
|
||||
|
||||
#if __unix__
|
||||
inline ssize_t get_line(char** lineptr, size_t* n, FILE* stream) {
|
||||
return getline(lineptr, n, stream);
|
||||
}
|
||||
#else
|
||||
using ssize_t = int64_t;
|
||||
inline ssize_t get_line(char** lineptr, size_t* n, FILE* stream) {
|
||||
size_t pos;
|
||||
int c;
|
||||
|
||||
if (lineptr == nullptr || stream == nullptr || n == nullptr) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
c = getc(stream);
|
||||
if (c == EOF) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*lineptr == nullptr) {
|
||||
*lineptr = static_cast<char*>(malloc(128));
|
||||
if (*lineptr == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
*n = 128;
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
while (c != EOF) {
|
||||
if (pos + 1 >= *n) {
|
||||
size_t new_size = *n + (*n >> 2);
|
||||
if (new_size < 128) {
|
||||
new_size = 128;
|
||||
}
|
||||
char* new_ptr = static_cast<char*>(
|
||||
realloc(static_cast<void*>(*lineptr), new_size));
|
||||
if (new_ptr == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
*n = new_size;
|
||||
*lineptr = new_ptr;
|
||||
}
|
||||
|
||||
(*lineptr)[pos++] = c;
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
c = getc(stream);
|
||||
}
|
||||
|
||||
(*lineptr)[pos] = '\0';
|
||||
return pos;
|
||||
}
|
||||
#endif
|
||||
|
||||
} /* ss */
|
||||
|
||||
@@ -379,7 +379,6 @@ private:
|
||||
return extract_tuple<Ts...>(elems);
|
||||
}
|
||||
|
||||
// do not know how to specialize by return type :(
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
||||
const split_data& elems, const std::tuple<Ts...>*) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "type_traits.hpp"
|
||||
#include <charconv>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <variant>
|
||||
#include <charconv>
|
||||
|
||||
#ifndef SSP_DISABLE_FAST_FLOAT
|
||||
#include <fast_float/fast_float.h>
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
// TODO try from_chars for integer conversions
|
||||
namespace ss {
|
||||
|
||||
////////////////
|
||||
@@ -42,17 +41,24 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
static_assert(!std::is_same_v<T, long double>,
|
||||
"Conversion to long double is disabled");
|
||||
|
||||
constexpr static auto buff_max = 64;
|
||||
char buff[buff_max];
|
||||
char short_buff[buff_max];
|
||||
size_t string_range = std::distance(begin, end);
|
||||
std::string long_buff;
|
||||
|
||||
char* buff;
|
||||
if (string_range > buff_max) {
|
||||
return std::nullopt;
|
||||
long_buff = std::string{begin, end};
|
||||
buff = long_buff.data();
|
||||
} else {
|
||||
buff = short_buff;
|
||||
buff[string_range] = '\0';
|
||||
std::copy_n(begin, string_range, buff);
|
||||
}
|
||||
|
||||
std::copy_n(begin, string_range, buff);
|
||||
buff[string_range] = '\0';
|
||||
|
||||
T ret;
|
||||
char* parse_end = nullptr;
|
||||
|
||||
@@ -60,8 +66,6 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
ret = std::strtof(buff, &parse_end);
|
||||
} else if constexpr (std::is_same_v<T, double>) {
|
||||
ret = std::strtod(buff, &parse_end);
|
||||
} else if constexpr (std::is_same_v<T, long double>) {
|
||||
ret = std::strtold(buff, &parse_end);
|
||||
}
|
||||
|
||||
if (parse_end != buff + string_range) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@ project(
|
||||
'cpp_std=c++17',
|
||||
'buildtype=debugoptimized',
|
||||
'wrap_mode=forcefallback'],
|
||||
version: '1.5.0',
|
||||
version: '1.6.1',
|
||||
meson_version:'>=0.54.0')
|
||||
|
||||
fast_float_dep = dependency('fast_float')
|
||||
|
||||
215
ssp.hpp
215
ssp.hpp
@@ -1,12 +1,12 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -1465,7 +1465,6 @@ public:
|
||||
#else
|
||||
#endif
|
||||
|
||||
// TODO try from_chars for integer conversions
|
||||
namespace ss {
|
||||
|
||||
////////////////
|
||||
@@ -1491,17 +1490,24 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
static_assert(!std::is_same_v<T, long double>,
|
||||
"Conversion to long double is disabled");
|
||||
|
||||
constexpr static auto buff_max = 64;
|
||||
char buff[buff_max];
|
||||
char short_buff[buff_max];
|
||||
size_t string_range = std::distance(begin, end);
|
||||
std::string long_buff;
|
||||
|
||||
char* buff;
|
||||
if (string_range > buff_max) {
|
||||
return std::nullopt;
|
||||
long_buff = std::string{begin, end};
|
||||
buff = long_buff.data();
|
||||
} else {
|
||||
buff = short_buff;
|
||||
buff[string_range] = '\0';
|
||||
std::copy_n(begin, string_range, buff);
|
||||
}
|
||||
|
||||
std::copy_n(begin, string_range, buff);
|
||||
buff[string_range] = '\0';
|
||||
|
||||
T ret;
|
||||
char* parse_end = nullptr;
|
||||
|
||||
@@ -1509,8 +1515,6 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
ret = std::strtof(buff, &parse_end);
|
||||
} else if constexpr (std::is_same_v<T, double>) {
|
||||
ret = std::strtod(buff, &parse_end);
|
||||
} else if constexpr (std::is_same_v<T, long double>) {
|
||||
ret = std::strtold(buff, &parse_end);
|
||||
}
|
||||
|
||||
if (parse_end != buff + string_range) {
|
||||
@@ -1522,195 +1526,16 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
|
||||
#endif
|
||||
|
||||
inline std::optional<short> from_char(char c) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
#if defined(__clang__) && defined(__MINGW32__) && !defined(__MINGW64__)
|
||||
#define MINGW32_CLANG
|
||||
#endif
|
||||
|
||||
// mingw32 clang does not support some of the builtin functions
|
||||
#if (defined(__clang__) || defined(__GNUC__) || defined(__GUNG__)) && \
|
||||
!defined(MINGW32_CLANG)
|
||||
////////////////
|
||||
// mul overflow detection
|
||||
////////////////
|
||||
template <typename T>
|
||||
bool mul_overflow(T& result, T operand) {
|
||||
return __builtin_mul_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool mul_overflow(int& result, int operand) {
|
||||
return __builtin_smul_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool mul_overflow(long& result, long operand) {
|
||||
return __builtin_smull_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool mul_overflow(long long& result, long long operand) {
|
||||
return __builtin_smulll_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool mul_overflow(unsigned int& result, unsigned int operand) {
|
||||
return __builtin_umul_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool mul_overflow(unsigned long& result, unsigned long operand) {
|
||||
return __builtin_umull_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool mul_overflow(unsigned long long& result,
|
||||
unsigned long long operand) {
|
||||
return __builtin_umulll_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
////////////////
|
||||
// addition overflow detection
|
||||
////////////////
|
||||
|
||||
template <typename T>
|
||||
inline bool add_overflow(T& result, T operand) {
|
||||
return __builtin_add_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool add_overflow(int& result, int operand) {
|
||||
return __builtin_sadd_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool add_overflow(long& result, long operand) {
|
||||
return __builtin_saddl_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool add_overflow(long long& result, long long operand) {
|
||||
return __builtin_saddll_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool add_overflow(unsigned int& result, unsigned int operand) {
|
||||
return __builtin_uadd_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool add_overflow(unsigned long& result, unsigned long operand) {
|
||||
return __builtin_uaddl_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool add_overflow(unsigned long long& result,
|
||||
unsigned long long operand) {
|
||||
return __builtin_uaddll_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
////////////////
|
||||
// substraction overflow detection
|
||||
////////////////
|
||||
template <typename T>
|
||||
inline bool sub_overflow(T& result, T operand) {
|
||||
return __builtin_sub_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool sub_overflow(int& result, int operand) {
|
||||
return __builtin_ssub_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool sub_overflow(long& result, long operand) {
|
||||
return __builtin_ssubl_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool sub_overflow(long long& result, long long operand) {
|
||||
return __builtin_ssubll_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
// Note: sub_overflow function should be unreachable for unsigned values
|
||||
template <>
|
||||
inline bool sub_overflow(unsigned int& result, unsigned int operand) {
|
||||
return __builtin_usub_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool sub_overflow(unsigned long& result, unsigned long operand) {
|
||||
return __builtin_usubl_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool sub_overflow(unsigned long long& result,
|
||||
unsigned long long operand) {
|
||||
return __builtin_usubll_overflow(result, operand, &result);
|
||||
}
|
||||
|
||||
template <typename T, typename F>
|
||||
bool shift_and_add_overflow(T& value, T digit, F add_last_digit_overflow) {
|
||||
if (mul_overflow<T>(value, 10) || add_last_digit_overflow(value, digit)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
|
||||
template <typename T, typename U>
|
||||
bool shift_and_add_overflow(T& value, T digit, U is_negative) {
|
||||
digit = (is_negative) ? -digit : digit;
|
||||
T old_value = value;
|
||||
value = 10 * value + digit;
|
||||
|
||||
T expected_old_value = (value - digit) / 10;
|
||||
if (old_value != expected_old_value) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_integral_v<T>, std::optional<T>> to_num(
|
||||
const char* begin, const char* end) {
|
||||
if (begin == end) {
|
||||
const char* const begin, const char* const end) {
|
||||
T ret;
|
||||
auto [ptr, ec] = std::from_chars(begin, end, ret);
|
||||
|
||||
if (ec != std::errc() || ptr != end) {
|
||||
return std::nullopt;
|
||||
}
|
||||
bool is_negative = false;
|
||||
if constexpr (std::is_signed_v<T>) {
|
||||
is_negative = *begin == '-';
|
||||
if (is_negative) {
|
||||
++begin;
|
||||
}
|
||||
}
|
||||
|
||||
#if (defined(__clang__) || defined(__GNUC__) || defined(__GUNG__)) && \
|
||||
!defined(MINGW32_CLANG)
|
||||
auto add_last_digit_overflow =
|
||||
(is_negative) ? sub_overflow<T> : add_overflow<T>;
|
||||
#else
|
||||
auto add_last_digit_overflow = is_negative;
|
||||
#endif
|
||||
|
||||
T value = 0;
|
||||
for (auto i = begin; i != end; ++i) {
|
||||
if (auto digit = from_char(*i);
|
||||
!digit || shift_and_add_overflow<T>(value, digit.value(),
|
||||
add_last_digit_overflow)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////
|
||||
@@ -2196,7 +2021,6 @@ private:
|
||||
return extract_tuple<Ts...>(elems);
|
||||
}
|
||||
|
||||
// do not know how to specialize by return type :(
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
||||
const split_data& elems, const std::tuple<Ts...>*) {
|
||||
@@ -2312,7 +2136,6 @@ private:
|
||||
|
||||
} /* ss */
|
||||
|
||||
// TODO add single header tests
|
||||
|
||||
namespace ss {
|
||||
|
||||
|
||||
@@ -275,3 +275,20 @@ TEST_CASE("extract test functions for std::variant") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("extract test with long number string") {
|
||||
{
|
||||
std::string string_num =
|
||||
std::string(20, '1') + "." + std::string(20, '2');
|
||||
|
||||
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, float, stof);
|
||||
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, double, stod);
|
||||
}
|
||||
|
||||
{
|
||||
std::string string_num =
|
||||
std::string(50, '1') + "." + std::string(50, '2');
|
||||
|
||||
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, double, stod);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ TEST_CASE(
|
||||
CHECK_FLOATING_CONVERSION(123.456, float);
|
||||
CHECK_FLOATING_CONVERSION(123.456, double);
|
||||
|
||||
CHECK_FLOATING_CONVERSION(69, float);
|
||||
CHECK_FLOATING_CONVERSION(69, double);
|
||||
CHECK_FLOATING_CONVERSION(59, float);
|
||||
CHECK_FLOATING_CONVERSION(59, double);
|
||||
|
||||
CHECK_FLOATING_CONVERSION(420., float);
|
||||
CHECK_FLOATING_CONVERSION(420., double);
|
||||
CHECK_FLOATING_CONVERSION(4210., float);
|
||||
CHECK_FLOATING_CONVERSION(4210., double);
|
||||
|
||||
CHECK_FLOATING_CONVERSION(0.123, float);
|
||||
CHECK_FLOATING_CONVERSION(0.123, double);
|
||||
@@ -130,3 +130,20 @@ TEST_CASE("extract test functions for std::variant without fast float") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("extract test with long number string without fast float") {
|
||||
{
|
||||
std::string string_num =
|
||||
std::string(20, '1') + "." + std::string(20, '2');
|
||||
|
||||
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, float, stof);
|
||||
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, double, stod);
|
||||
}
|
||||
|
||||
{
|
||||
std::string string_num =
|
||||
std::string(50, '1') + "." + std::string(50, '2');
|
||||
|
||||
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, double, stod);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef CMAKE_GITHUB_CI
|
||||
#include <doctest/doctest.h>
|
||||
@@ -75,6 +75,18 @@ struct unique_file_name {
|
||||
CHECK_LT(std::abs(t.value() - type(-input)), eps); \
|
||||
}
|
||||
|
||||
#define CHECK_FLOATING_CONVERSION_LONG_NUMBER(STRING_NUMBER, TYPE, CONVERTER) \
|
||||
{ \
|
||||
auto begin = STRING_NUMBER.c_str(); \
|
||||
auto end = begin + STRING_NUMBER.size(); \
|
||||
\
|
||||
auto number = ss::to_num<TYPE>(begin, end); \
|
||||
REQUIRE(number.has_value()); \
|
||||
\
|
||||
auto expected_number = CONVERTER(STRING_NUMBER); \
|
||||
CHECK_EQ(number.value(), expected_number); \
|
||||
}
|
||||
|
||||
#define CHECK_INVALID_CONVERSION(input, type) \
|
||||
{ \
|
||||
std::string s = input; \
|
||||
|
||||
@@ -897,7 +897,7 @@ void test_multiline_restricted() {
|
||||
out << "17,18,\"ju\\\n\\\n\\\n\\\\\n\nnk\"" << std::endl;
|
||||
out << "19,20,just strings" << std::endl;
|
||||
}
|
||||
auto bad_lines = 15;
|
||||
auto bad_lines = 19;
|
||||
auto num_errors = 0;
|
||||
|
||||
ss::parser<ss::multiline_restricted<2>, ss::quote<'"'>, ss::escape<'\\'>,
|
||||
@@ -1491,6 +1491,104 @@ TEST_CASE("parser test invalid header fields usage") {
|
||||
test_invalid_fields({"Int,String,Int", "1,hi,3"}, {"Int", "String", "Int"});
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
void test_invalid_rows_with_header() {
|
||||
unique_file_name f{"test_parser"};
|
||||
{
|
||||
std::ofstream out{f.name};
|
||||
out << "Int,String,Double" << std::endl;
|
||||
out << "1,line1,2.34" << std::endl;
|
||||
out << "2,line2" << std::endl;
|
||||
out << "3,line3,67.8" << std::endl;
|
||||
out << "4,line4,67.8,9" << std::endl;
|
||||
out << "5,line5,9.10" << std::endl;
|
||||
out << "six,line6,10.11" << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
ss::parser<Ts...> p{f.name};
|
||||
|
||||
p.use_fields("Int", "String", "Double");
|
||||
using data = std::tuple<int, std::string, double>;
|
||||
std::vector<data> i;
|
||||
|
||||
CHECK(p.valid());
|
||||
|
||||
while (!p.eof()) {
|
||||
try {
|
||||
const auto& t = p.template get_next<data>();
|
||||
if (p.valid()) {
|
||||
i.push_back(t);
|
||||
}
|
||||
} catch (const ss::exception&) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<data> expected = {{1, "line1", 2.34},
|
||||
{3, "line3", 67.8},
|
||||
{5, "line5", 9.10}};
|
||||
CHECK_EQ(i, expected);
|
||||
}
|
||||
|
||||
{
|
||||
ss::parser<Ts...> p{f.name};
|
||||
|
||||
p.use_fields("Double", "Int");
|
||||
using data = std::tuple<double, int>;
|
||||
std::vector<data> i;
|
||||
|
||||
CHECK(p.valid());
|
||||
|
||||
while (!p.eof()) {
|
||||
try {
|
||||
const auto& t = p.template get_next<data>();
|
||||
if (p.valid()) {
|
||||
i.push_back(t);
|
||||
}
|
||||
} catch (const ss::exception&) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<data> expected = {{2.34, 1}, {67.8, 3}, {9.10, 5}};
|
||||
CHECK_EQ(i, expected);
|
||||
}
|
||||
|
||||
{
|
||||
ss::parser<Ts...> p{f.name};
|
||||
|
||||
p.use_fields("String", "Double");
|
||||
using data = std::tuple<std::string, double>;
|
||||
std::vector<data> i;
|
||||
|
||||
CHECK(p.valid());
|
||||
|
||||
while (!p.eof()) {
|
||||
try {
|
||||
const auto& t = p.template get_next<data>();
|
||||
if (p.valid()) {
|
||||
i.push_back(t);
|
||||
}
|
||||
} catch (const ss::exception&) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<data> expected = {{"line1", 2.34},
|
||||
{"line3", 67.8},
|
||||
{"line5", 9.10},
|
||||
{"line6", 10.11}};
|
||||
CHECK_EQ(i, expected);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("parser test invalid rows with header") {
|
||||
test_invalid_rows_with_header();
|
||||
test_invalid_rows_with_header<ss::string_error>();
|
||||
test_invalid_rows_with_header<ss::throw_on_error>();
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
void test_ignore_empty_impl(const std::vector<X>& data) {
|
||||
unique_file_name f{"test_parser"};
|
||||
@@ -1543,6 +1641,7 @@ void test_ignore_empty(const std::vector<X>& data) {
|
||||
test_ignore_empty_impl<ss::throw_on_error>(data);
|
||||
}
|
||||
|
||||
// TODO test with different initial buffer sizes
|
||||
TEST_CASE("parser test various cases with empty lines") {
|
||||
test_ignore_empty({{1, 2, "x"}, {3, 4, "y"}, {9, 10, "v"}, {11, 12, "w"}});
|
||||
|
||||
@@ -1572,13 +1671,53 @@ TEST_CASE("parser test various cases with empty lines") {
|
||||
{9, 10, X::empty},
|
||||
{11, 12, X::empty}});
|
||||
|
||||
test_ignore_empty(
|
||||
{{1, 2, "x"}, {3, 4, X::empty}, {9, 10, X::empty}, {11, 12, X::empty}});
|
||||
test_ignore_empty({{1, 2, X::empty},
|
||||
{3, 4, X::empty},
|
||||
{5, 6, X::empty},
|
||||
{7, 8, X::empty},
|
||||
{9, 10, X::empty},
|
||||
{11, 12, X::empty},
|
||||
{13, 14, X::empty},
|
||||
{15, 16, X::empty},
|
||||
{17, 18, X::empty}});
|
||||
|
||||
test_ignore_empty(
|
||||
{{1, 2, X::empty}, {3, 4, X::empty}, {9, 10, X::empty}, {11, 12, "w"}});
|
||||
test_ignore_empty({{1, 2, X::empty},
|
||||
{3, 4, X::empty},
|
||||
{5, 6, X::empty},
|
||||
{7, 8, X::empty},
|
||||
{9, 10, X::empty},
|
||||
{11, 12, X::empty},
|
||||
{13, 14, X::empty},
|
||||
{15, 16, X::empty},
|
||||
{17, 18, "x"}});
|
||||
|
||||
test_ignore_empty({{11, 12, X::empty}});
|
||||
test_ignore_empty({{1, 2, "x"},
|
||||
{3, 4, X::empty},
|
||||
{9, 10, X::empty},
|
||||
{11, 12, X::empty}});
|
||||
|
||||
test_ignore_empty({});
|
||||
test_ignore_empty({{1, 2, "x"},
|
||||
{3, 4, X::empty},
|
||||
{3, 4, X::empty},
|
||||
{5, 6, X::empty},
|
||||
{7, 8, X::empty},
|
||||
{9, 10, X::empty},
|
||||
{11, 12, X::empty}});
|
||||
|
||||
test_ignore_empty({{1, 2, "x"},
|
||||
{3, 4, X::empty},
|
||||
{3, 4, X::empty},
|
||||
{5, 6, X::empty},
|
||||
{7, 8, X::empty},
|
||||
{9, 10, X::empty},
|
||||
{11, 12, "y"}});
|
||||
|
||||
test_ignore_empty({{1, 2, X::empty},
|
||||
{3, 4, X::empty},
|
||||
{9, 10, X::empty},
|
||||
{11, 12, "w"}});
|
||||
|
||||
test_ignore_empty({{11, 12, X::empty}});
|
||||
|
||||
test_ignore_empty({});
|
||||
}
|
||||
|
||||
@@ -775,6 +775,23 @@ TEST_CASE("splitter test resplit unterminated quote") {
|
||||
CHECK_EQ(words(vec), expected);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ss::converter<ss::quote<'"'>, ss::escape<'\\'>, ss::multiline> c;
|
||||
auto& s = c.splitter;
|
||||
auto vec = expect_unterminated_quote(s, R"("just\"some","ra)");
|
||||
std::vector<std::string> expected{"just\"some"};
|
||||
auto w = words(vec);
|
||||
w.pop_back();
|
||||
CHECK_EQ(w, expected);
|
||||
REQUIRE(s.unterminated_quote());
|
||||
{
|
||||
auto new_line = buff.append(R"(n,dom",str\"ings)");
|
||||
// invalid resplit size
|
||||
vec = c.resplit(new_line, 4);
|
||||
CHECK(!s.valid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("splitter test resplit unterminated quote with exceptions") {
|
||||
@@ -1040,47 +1057,57 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("splitter test invalid splits") {
|
||||
ss::converter<ss::string_error, ss::quote<'"'>, ss::trim<' '>,
|
||||
ss::escape<'\\'>>
|
||||
c;
|
||||
template <typename... Ts>
|
||||
void test_invalid_splits() {
|
||||
ss::converter<ss::quote<'"'>, ss::trim<' '>, ss::escape<'\\'>, Ts...> c;
|
||||
auto& s = c.splitter;
|
||||
|
||||
auto check_error_msg = [&] {
|
||||
if constexpr (ss::setup<Ts...>::string_error) {
|
||||
CHECK_FALSE(s.error_msg().empty());
|
||||
}
|
||||
};
|
||||
|
||||
// empty delimiter
|
||||
s.split(buff("some,random,strings"), "");
|
||||
CHECK_FALSE(s.valid());
|
||||
CHECK_FALSE(s.unterminated_quote());
|
||||
CHECK_FALSE(s.error_msg().empty());
|
||||
check_error_msg();
|
||||
|
||||
// mismatched delimiter
|
||||
s.split(buff(R"(some,"random,"strings")"));
|
||||
CHECK_FALSE(s.valid());
|
||||
CHECK_FALSE(s.unterminated_quote());
|
||||
CHECK_FALSE(s.error_msg().empty());
|
||||
check_error_msg();
|
||||
|
||||
// unterminated escape
|
||||
s.split(buff(R"(some,random,strings\)"));
|
||||
CHECK_FALSE(s.valid());
|
||||
CHECK_FALSE(s.unterminated_quote());
|
||||
CHECK_FALSE(s.error_msg().empty());
|
||||
check_error_msg();
|
||||
|
||||
// unterminated escape
|
||||
s.split(buff(R"(some,random,"strings\)"));
|
||||
CHECK_FALSE(s.valid());
|
||||
CHECK_FALSE(s.unterminated_quote());
|
||||
CHECK_FALSE(s.error_msg().empty());
|
||||
check_error_msg();
|
||||
|
||||
// unterminated quote
|
||||
s.split(buff("some,random,\"strings"));
|
||||
CHECK_FALSE(s.valid());
|
||||
CHECK(s.unterminated_quote());
|
||||
CHECK_FALSE(s.error_msg().empty());
|
||||
check_error_msg();
|
||||
|
||||
// invalid resplit
|
||||
char new_line[] = "some";
|
||||
c.resplit(new_line, strlen(new_line));
|
||||
CHECK_FALSE(s.valid());
|
||||
CHECK_FALSE(s.error_msg().empty());
|
||||
check_error_msg();
|
||||
}
|
||||
|
||||
TEST_CASE("splitter test invalid splits") {
|
||||
test_invalid_splits();
|
||||
test_invalid_splits<ss::string_error>();
|
||||
}
|
||||
|
||||
TEST_CASE("splitter test invalid splits with exceptions") {
|
||||
|
||||
Reference in New Issue
Block a user