mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 16:23:04 +00:00
c++: style: improve tests
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Provide better assertions. Use them. Avoid useless Bison invocations.
This commit is contained in:
1
THANKS
1
THANKS
@@ -179,6 +179,7 @@ Wayne Green wayne@infosavvy.com
|
|||||||
Wei Song wsong83@gmail.com
|
Wei Song wsong83@gmail.com
|
||||||
Wojciech Polak polak@gnu.org
|
Wojciech Polak polak@gnu.org
|
||||||
Wolfgang S. Kechel wolfgang.kechel@prs.de
|
Wolfgang S. Kechel wolfgang.kechel@prs.de
|
||||||
|
Wolfgang Thaller wolfgang.thaller@gmx.net
|
||||||
Wolfram Wagner ww@mpi-sb.mpg.de
|
Wolfram Wagner ww@mpi-sb.mpg.de
|
||||||
Wwp subscript@free.fr
|
Wwp subscript@free.fr
|
||||||
xolodho xolodho@gmail.com
|
xolodho xolodho@gmail.com
|
||||||
|
|||||||
33
tests/c++.at
33
tests/c++.at
@@ -103,7 +103,7 @@ AT_KEYWORDS([variant])
|
|||||||
|
|
||||||
AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" %debug $1])
|
AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" %debug $1])
|
||||||
# Store strings and integers in a vector of strings.
|
# Store strings and integers in a vector of strings.
|
||||||
AT_DATA_GRAMMAR([list.y],
|
AT_DATA_GRAMMAR([list.yy],
|
||||||
[[%skeleton "lalr1.cc"
|
[[%skeleton "lalr1.cc"
|
||||||
%define api.value.type variant
|
%define api.value.type variant
|
||||||
%define parse.assert
|
%define parse.assert
|
||||||
@@ -142,24 +142,33 @@ exp: "int" { $$.push_back ($1); }
|
|||||||
]AT_YYERROR_DEFINE[
|
]AT_YYERROR_DEFINE[
|
||||||
]AT_YYLEX_DEFINE[
|
]AT_YYLEX_DEFINE[
|
||||||
|
|
||||||
|
template <typename Exp, typename Eff>
|
||||||
|
void assert_eq (const Exp& exp, const Eff& eff)
|
||||||
|
{
|
||||||
|
if (getenv ("DEBUG"))
|
||||||
|
std::cerr << "Assert: " << exp << " == " << eff << '\n';
|
||||||
|
if (exp != eff)
|
||||||
|
std::cerr << "Assertion failed: " << exp << " != " << eff << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using yy::parser;
|
using yy::parser;
|
||||||
// symbol_type: construction, accessor.
|
// symbol_type: construction, accessor.
|
||||||
{
|
{
|
||||||
parser::symbol_type s = parser::make_INT(12);
|
parser::symbol_type s = parser::make_INT (12);
|
||||||
std::cerr << s.value.as<int>() << '\n';
|
assert_eq (s.value.as<int> (), 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack_symbol_type: construction, accessor.
|
// stack_symbol_type: construction, accessor.
|
||||||
{
|
{
|
||||||
#if defined __cplusplus && 201103L <= __cplusplus
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
auto ss = parser::stack_symbol_type(1, parser::make_INT(123));
|
auto ss = parser::stack_symbol_type(1, parser::make_INT(123));
|
||||||
#else
|
#else
|
||||||
parser::symbol_type s = parser::make_INT(123);
|
parser::symbol_type s = parser::make_INT (123);
|
||||||
parser::stack_symbol_type ss(1, s);
|
parser::stack_symbol_type ss(1, s);
|
||||||
#endif
|
#endif
|
||||||
std::cerr << ss.value.as<int>() << '\n';
|
assert_eq (ss.value.as<int> (), 123);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pushing on the stack.
|
// Pushing on the stack.
|
||||||
@@ -170,7 +179,7 @@ int main()
|
|||||||
const int mucho = 1700;
|
const int mucho = 1700;
|
||||||
for (int i = 0; i < mucho; ++i)
|
for (int i = 0; i < mucho; ++i)
|
||||||
{
|
{
|
||||||
#if defined __cplusplus && 201103L <= __cplusplus
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
st.push(parser::stack_symbol_type{1, parser::make_INT (i)});
|
st.push(parser::stack_symbol_type{1, parser::make_INT (i)});
|
||||||
#else
|
#else
|
||||||
parser::symbol_type s = parser::make_INT (i);
|
parser::symbol_type s = parser::make_INT (i);
|
||||||
@@ -180,19 +189,17 @@ int main()
|
|||||||
}
|
}
|
||||||
for (int i = mucho - 1; 0 <= i; --i)
|
for (int i = mucho - 1; 0 <= i; --i)
|
||||||
{
|
{
|
||||||
assert (st[0].value.as<int>() == i);
|
assert_eq (st[0].value.as<int>(), i);
|
||||||
st.pop ();
|
st.pop ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
AT_BISON_CHECK([[-o list.cc list.yy]])
|
||||||
AT_FOR_EACH_CXX([
|
AT_FOR_EACH_CXX([
|
||||||
AT_FULL_COMPILE([list])
|
AT_COMPILE_CXX([list])
|
||||||
AT_PARSER_CHECK([./list], 0, [],
|
AT_PARSER_CHECK([./list])
|
||||||
[12
|
|
||||||
123
|
|
||||||
])
|
|
||||||
])
|
])
|
||||||
|
|
||||||
AT_BISON_OPTION_POPDEFS
|
AT_BISON_OPTION_POPDEFS
|
||||||
|
|||||||
Reference in New Issue
Block a user