Skip to content

Commit 7592c0f

Browse files
committed
Improve test coverage.
1 parent 1006f2c commit 7592c0f

17 files changed

+582
-213
lines changed

include/tao/pegtl/contrib/input_with_depth.hpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace TAO_PEGTL_NAMESPACE
3333
--m_depth;
3434
}
3535

36-
depth_guard& operator=( depth_guard&& ) = delete;
37-
depth_guard& operator=( const depth_guard& ) = delete;
36+
void operator=( depth_guard&& ) = delete;
37+
void operator=( const depth_guard& ) = delete;
3838

3939
[[nodiscard]] std::size_t current_depth() const noexcept
4040
{
@@ -54,14 +54,6 @@ namespace TAO_PEGTL_NAMESPACE
5454
public:
5555
using Input::Input;
5656

57-
void restart() noexcept
58-
{
59-
if constexpr( internal::has_restart< Input > ) {
60-
Input::restart();
61-
}
62-
m_depth = 0;
63-
}
64-
6557
[[nodiscard]] internal::depth_guard make_depth_guard() noexcept
6658
{
6759
return internal::depth_guard( m_depth ); // NOLINT(google-readability-casting)

include/tao/pegtl/contrib/input_with_offset.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace TAO_PEGTL_NAMESPACE
5858
return m_offset;
5959
}
6060

61-
void direct_position() = delete;
61+
void direct_position() const = delete;
6262

6363
protected:
6464
offset_position_t m_offset;

include/tao/pegtl/debug/analyze_traits_impl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ namespace TAO_PEGTL_NAMESPACE
6666
: analyze_opt_traits<>
6767
{};
6868

69-
template< typename Name, std::size_t Count, typename Reference >
70-
struct analyze_traits< Name, internal::consume< Count, Reference > >
69+
template< typename Name, std::size_t Count >
70+
struct analyze_traits< Name, internal::consume< Count > >
7171
: std::conditional_t< ( Count > 0 ), analyze_any_traits<>, analyze_opt_traits<> >
7272
{};
7373

@@ -150,7 +150,7 @@ namespace TAO_PEGTL_NAMESPACE
150150

151151
template< typename Name, typename Head, typename... Rules >
152152
struct analyze_traits< Name, internal::rematch< Head, Rules... > >
153-
: analyze_traits< Name, typename internal::sor< Head, internal::sor< internal::seq< Rules, internal::consume< 1, void > >... > >::rule_t > // TODO: Correct (enough)?
153+
: analyze_traits< Name, typename internal::sor< Head, internal::sor< internal::seq< Rules, internal::consume< 1 > >... > >::rule_t > // TODO: Correct (enough)?
154154
{};
155155

156156
template< typename Name, std::size_t Cnt, typename... Rules >

include/tao/pegtl/internal/consume.hpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey
1+
// Copyright (c) 2017-2024 Dr. Colin Hirsch and Daniel Frey
22
// Distributed under the Boost Software License, Version 1.0.
33
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
44

@@ -13,32 +13,12 @@
1313
#include "../type_list.hpp"
1414

1515
#include "enable_control.hpp"
16-
#include "math_utility.hpp"
1716
#include "success.hpp"
1817

1918
namespace TAO_PEGTL_NAMESPACE::internal
2019
{
21-
template< std::size_t Count, typename Reference, typename = void >
22-
struct consume
23-
{
24-
using rule_t = consume;
25-
using subs_t = empty_list;
26-
27-
template< typename ParseInput >
28-
[[nodiscard]] static bool match( ParseInput& in ) noexcept
29-
{
30-
static_assert( is_divisible( sizeof( Reference ), sizeof( *in.current() ) ) );
31-
32-
if( in.size( Count ) >= Count ) {
33-
in.template consume< eol_unknown_tag >( Count );
34-
return true;
35-
}
36-
return false;
37-
}
38-
};
39-
4020
template< std::size_t Count >
41-
struct consume< Count, void, std::enable_if_t< ( Count > 0 ) > >
21+
struct consume
4222
{
4323
using rule_t = consume;
4424
using subs_t = empty_list;
@@ -54,13 +34,13 @@ namespace TAO_PEGTL_NAMESPACE::internal
5434
}
5535
};
5636

57-
template< typename Reference >
58-
struct consume< 0, Reference, void >
37+
template<>
38+
struct consume< 0 >
5939
: success
6040
{};
6141

62-
template< std::size_t Count, typename Reference >
63-
inline constexpr bool enable_control< consume< Count, Reference > > = false;
42+
template< std::size_t Count >
43+
inline constexpr bool enable_control< consume< Count > > = false;
6444

6545
} // namespace TAO_PEGTL_NAMESPACE::internal
6646

include/tao/pegtl/internal/input_with_funcs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
3232
[[nodiscard]] T peek_as( const std::size_t offset = 0 ) const noexcept
3333
{
3434
static_assert( sizeof( data_t ) == sizeof( T ) );
35-
return static_cast< T >( *this->current( offset ) );
35+
return static_cast< T >( peek( offset ) );
3636
}
3737

3838
[[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept

include/tao/pegtl/rules.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace TAO_PEGTL_NAMESPACE
3030
struct bof : internal::bof {};
3131
struct bol : internal::bol {};
3232
template< typename Left, typename Right > struct combine : internal::combine_traits< typename Left::rule_t, typename Right::rule_t >::rule_t {};
33-
template< std::size_t Count > struct consume : internal::consume< Count, void > {};
33+
template< std::size_t Count > struct consume : internal::consume< Count > {};
3434
template< template< typename... > class Control, typename... Rules > struct control : internal::control< Control, Rules... > {};
3535
template< typename... Rules > struct disable : internal::disable< Rules... > {};
3636
template< typename... Rules > struct enable : internal::enable< Rules... > {};

src/example/pegtl/coverage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ namespace coverage
242242
report( pair.first, pair.second );
243243
}
244244
}
245-
const double fraction = double( m_total_lines - m_problem_lines ) / double( m_total_lines );
246-
std::cout << "Summary for lines -- total " << m_total_lines << " problems " << m_problem_lines << " coverage " << fraction << std::endl;
247-
std::cout << "Summary for files -- total " << m_total_files << " problems " << m_problem_files << std::endl;
245+
const double fraction = 100.0 * double( m_total_lines - m_problem_lines ) / double( m_total_lines );
246+
std::cout << "Summary for lines -- total " << m_total_lines << " uncovered " << m_problem_lines << " coverage " << fraction << '%' << std::endl;
247+
std::cout << "Summary for files -- total " << m_total_files << " problematic " << m_problem_files << std::endl;
248248
}
249249

250250
void report( const std::string& name, const per_file_data& data )

src/test/pegtl/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ set(test_sources
4646
buffer_rule_is_buffer.cpp
4747
buffer_rule_require.cpp
4848
buffer_static_buffer.cpp
49+
buffer_text_buffer_input.cpp
4950
contrib_alphabet.cpp
5051
contrib_check_count.cpp
5152
contrib_check_depth.cpp
@@ -56,6 +57,7 @@ set(test_sources
5657
contrib_integer.cpp
5758
contrib_integer_convert.cpp
5859
contrib_integer_match.cpp
60+
contrib_integer_maximum.cpp
5961
contrib_iri.cpp
6062
contrib_json.cpp
6163
contrib_limit_count.cpp

src/test/pegtl/buffer_buffer_common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace TAO_PEGTL_NAMESPACE
6969
#if defined( __cpp_exceptions )
7070
TAO_PEGTL_TEST_THROWS( bc.require( 101 ) );
7171
TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) );
72+
TAO_PEGTL_TEST_THROWS( (void)bc.size( 100, 101 ) );
7273
#endif
7374

7475
TAO_PEGTL_TEST_ASSERT( !bc.empty() );
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2024 Dr. Colin Hirsch and Daniel Frey
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4+
5+
#include "test.hpp"
6+
7+
#include <tao/pegtl/buffer.hpp>
8+
9+
namespace TAO_PEGTL_NAMESPACE
10+
{
11+
template< typename ParseInput >
12+
void main_test( ParseInput& in )
13+
{
14+
in.require( 10 );
15+
const auto m = in.rewind_position();
16+
TAO_PEGTL_TEST_ASSERT( in.previous( m ) == in.current() );
17+
in.consume< any >( 6 );
18+
TAO_PEGTL_TEST_ASSERT( in.previous( m ) + 6 == in.current() );
19+
in.rewind_to_position( m );
20+
TAO_PEGTL_TEST_ASSERT( in.previous( m ) == in.current() );
21+
TAO_PEGTL_TEST_ASSERT( &in.current_position() == &in.direct_position() );
22+
TAO_PEGTL_TEST_ASSERT( in.direct_count() == in.current_position().count );
23+
TAO_PEGTL_TEST_ASSERT( in.direct_line() == in.current_position().line );
24+
TAO_PEGTL_TEST_ASSERT( in.direct_column() == in.current_position().column );
25+
in.consume< alpha >( 5 );
26+
const auto n = in.rewind_position();
27+
in.consume< eol >( 1 );
28+
TAO_PEGTL_TEST_ASSERT( in.direct_count() == 6 );
29+
TAO_PEGTL_TEST_ASSERT( in.direct_line() == 2 );
30+
TAO_PEGTL_TEST_ASSERT( in.direct_column() == 1 );
31+
const auto p = in.previous_position( n );
32+
TAO_PEGTL_TEST_ASSERT( p.count == 5 );
33+
TAO_PEGTL_TEST_ASSERT( p.line == 1 );
34+
TAO_PEGTL_TEST_ASSERT( p.column == 6 );
35+
}
36+
37+
void unit_test()
38+
{
39+
dynamic_text_cstring_input<> i1( 50, 10, "input\ndata" );
40+
main_test( i1 );
41+
dynamic_text_cstring_input< tao_buffer_eol, std::string > i2( "source", 50, 10, "input\ndata" );
42+
main_test( i2 );
43+
TAO_PEGTL_TEST_ASSERT( i2.direct_source() == "source" );
44+
}
45+
46+
} // namespace TAO_PEGTL_NAMESPACE
47+
48+
#include "main.hpp"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2024 Dr. Colin Hirsch and Daniel Frey
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4+
5+
#include <string_view>
6+
7+
#include "test.hpp"
8+
#include "test_utility.hpp"
9+
10+
#include <tao/pegtl/contrib/input_with_depth.hpp>
11+
12+
namespace TAO_PEGTL_NAMESPACE
13+
{
14+
void unit_test()
15+
{
16+
using input_t = input_with_depth< text_view_input< scan::lf > >;
17+
const std::string_view data = "test";
18+
input_t in( data );
19+
TAO_PEGTL_TEST_ASSERT( in.current() == data.data() );
20+
TAO_PEGTL_TEST_ASSERT( in.current_depth() == 0 );
21+
{
22+
const auto dg = in.make_depth_guard();
23+
TAO_PEGTL_TEST_ASSERT( in.current_depth() == 1 );
24+
in.consume< alpha >( 2 );
25+
TAO_PEGTL_TEST_ASSERT( in.current() == data.data() + 2 );
26+
}
27+
TAO_PEGTL_TEST_ASSERT( in.current() == data.data() + 2 );
28+
TAO_PEGTL_TEST_ASSERT( in.current_depth() == 0 );
29+
}
30+
31+
} // namespace TAO_PEGTL_NAMESPACE
32+
33+
#include "main.hpp"

src/test/pegtl/contrib_input_with_offset.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace TAO_PEGTL_NAMESPACE
2929
TAO_PEGTL_TEST_ASSERT( b );
3030
TAO_PEGTL_TEST_ASSERT( in.previous_position( r ).count == 46 );
3131
TAO_PEGTL_TEST_ASSERT( in.current_position().count == 49 );
32+
TAO_PEGTL_TEST_ASSERT( in.direct_offset() == count_position( 42 ) );
3233
}
3334

3435
void test_count_offset_source()
@@ -71,6 +72,7 @@ namespace TAO_PEGTL_NAMESPACE
7172
TAO_PEGTL_TEST_ASSERT( in.current_position().count == 107 );
7273
TAO_PEGTL_TEST_ASSERT( in.current_position().line == 201 );
7374
TAO_PEGTL_TEST_ASSERT( in.current_position().column == 4 );
75+
TAO_PEGTL_TEST_ASSERT( in.direct_offset() == text_position( 200, 300, 100 ) );
7476
}
7577

7678
void test_text_offset_source()

0 commit comments

Comments
 (0)