Skip to content

Commit

Permalink
X3: Added tests for non-movable and non default constructible types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kojoley committed Feb 7, 2019
1 parent 4496caf commit 5663d7d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/x3/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <cstring>
#include <functional>

#include "test.hpp"


namespace x3 = boost::spirit::x3;

int x = 0;
Expand Down Expand Up @@ -49,8 +52,21 @@ struct setnext
char& next;
};


struct stationary : boost::noncopyable
{
explicit stationary(int i) : val{i} {}
stationary& operator=(int i) { val = i; return *this; }

int val;
};


int main()
{
using spirit_test::test;
using spirit_test::test_attr;

using x3::int_;

{
Expand Down Expand Up @@ -80,5 +96,13 @@ int main()
BOOST_TEST(next == '1');
}

{ // ensure no unneded synthesization, copying and moving occured
auto p = '{' >> int_ >> '}';

stationary st { 0 };
BOOST_TEST(test_attr("{42}", p[([]{})], st));
BOOST_TEST_EQ(st.val, 42);
}

return boost::report_errors();
}
22 changes: 22 additions & 0 deletions test/x3/alternative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ BOOST_FUSION_ADAPT_STRUCT(di_include,

struct undefined {};


struct stationary : boost::noncopyable
{
explicit stationary(int i) : val{i} {}
// TODO: fix unneeded self move in alternative
stationary& operator=(stationary&&)
{ std::abort(); return *this; }
stationary& operator=(int i) { val = i; return *this; }

int val;
};


int
main()
{
Expand All @@ -50,6 +63,7 @@ main()
using boost::spirit::x3::unused_type;
using boost::spirit::x3::unused;
using boost::spirit::x3::omit;
using boost::spirit::x3::eps;


{
Expand Down Expand Up @@ -228,5 +242,13 @@ main()
BOOST_TEST(boost::get<char>(&boost::fusion::front(attr_)) == nullptr);
}

{ // ensure no unneded synthesization, copying and moving occured
auto p = '{' >> int_ >> '}';

stationary st { 0 };
BOOST_TEST(test_attr("{42}", p | eps | p, st));
BOOST_TEST_EQ(st.val, 42);
}

return boost::report_errors();
}
20 changes: 20 additions & 0 deletions test/x3/rule3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ struct f
}
};


struct stationary : boost::noncopyable
{
explicit stationary(int i) : val{i} {}
stationary& operator=(int i) { val = i; return *this; }

int val;
};


int main()
{
using spirit_test::test_attr;
Expand All @@ -36,6 +46,7 @@ int main()
using namespace boost::spirit::x3::ascii;
using boost::spirit::x3::rule;
using boost::spirit::x3::lit;
using boost::spirit::x3::int_;
using boost::spirit::x3::eps;
using boost::spirit::x3::unused_type;

Expand Down Expand Up @@ -79,5 +90,14 @@ int main()
BOOST_TEST(test("", r));
}

{ // ensure no unneded synthesization, copying and moving occured
auto a = rule<class a_r, stationary>{} = '{' >> int_ >> '}';
auto b = rule<class b_r, stationary>{} = a;

stationary st { 0 };
BOOST_TEST(test_attr("{42}", b, st));
BOOST_TEST_EQ(st.val, 42);
}

return boost::report_errors();
}

0 comments on commit 5663d7d

Please sign in to comment.