244 lines
7 KiB
C++
244 lines
7 KiB
C++
|
#include "srd-preproc-cmd-common.hh"
|
||
|
|
||
|
|
||
|
class SRDPreprocCmdMacrosTest : public CppUnit::TestFixture
|
||
|
{
|
||
|
CPPUNIT_TEST_SUITE( SRDPreprocCmdMacrosTest );
|
||
|
|
||
|
CPPUNIT_TEST( testSetMacroEmpty );
|
||
|
CPPUNIT_TEST( testSetMacroMissingArgs );
|
||
|
CPPUNIT_TEST( testSetMacroExtraArgs );
|
||
|
CPPUNIT_TEST( testSetMacroBadName );
|
||
|
CPPUNIT_TEST( testSetMacroBadBody );
|
||
|
CPPUNIT_TEST( testSetMacroInvalidBody );
|
||
|
CPPUNIT_TEST( testSetMacroSuccess );
|
||
|
CPPUNIT_TEST( testSetMacroDuplicate );
|
||
|
|
||
|
CPPUNIT_TEST( testUnsetMacroNoArgs );
|
||
|
CPPUNIT_TEST( testUnsetMacro );
|
||
|
CPPUNIT_TEST( testUnsetMacroMissing );
|
||
|
CPPUNIT_TEST( testUnsetMacroMultiple );
|
||
|
|
||
|
CPPUNIT_TEST( testListMacros );
|
||
|
CPPUNIT_TEST( testListMacrosArgs );
|
||
|
|
||
|
CPPUNIT_TEST( testMacroBodyInnerList );
|
||
|
CPPUNIT_TEST( testMacroOutputInnerList );
|
||
|
|
||
|
CPPUNIT_TEST_SUITE_END( );
|
||
|
|
||
|
public:
|
||
|
void testSetMacroEmpty( );
|
||
|
void testSetMacroMissingArgs( );
|
||
|
void testSetMacroExtraArgs( );
|
||
|
void testSetMacroBadName( );
|
||
|
void testSetMacroBadBody( );
|
||
|
void testSetMacroInvalidBody( );
|
||
|
void testSetMacroSuccess( );
|
||
|
void testSetMacroDuplicate( );
|
||
|
|
||
|
void testUnsetMacroNoArgs( );
|
||
|
void testUnsetMacro( );
|
||
|
void testUnsetMacroMissing( );
|
||
|
void testUnsetMacroMultiple( );
|
||
|
|
||
|
void testListMacros( );
|
||
|
void testListMacrosArgs( );
|
||
|
|
||
|
void testMacroBodyInnerList( );
|
||
|
void testMacroOutputInnerList( );
|
||
|
};
|
||
|
CPPUNIT_TEST_SUITE_REGISTRATION( SRDPreprocCmdMacrosTest );
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testSetMacroEmpty( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process( "( -set-macro )" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
|
||
|
M_CKERR_( 0 , "not enough arguments" , 1 , 3 );
|
||
|
M_CKERR_( 1 , "previous error cause" , 1 , 14 );
|
||
|
CPPUNIT_ASSERT( check( "" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testSetMacroMissingArgs( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process( "( -set-macro a )" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
|
||
|
M_CKERR_( 0 , "invalid macro" , 1 , 3 );
|
||
|
M_CKERR_( 1 , "previous error cause" , 1 , 14 );
|
||
|
CPPUNIT_ASSERT( check( "" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testSetMacroExtraArgs( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process( "( -set-macro a ( () ) x )" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
|
||
|
M_CKERR_( 0 , "too many arguments" , 1 , 3 );
|
||
|
M_CKERR_( 1 , "previous error cause" , 1 , 23 );
|
||
|
CPPUNIT_ASSERT( check( "" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testSetMacroBadName( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process( "( -set-macro 1 ( () ) )" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
|
||
|
M_CKERR_( 0 , "word expected" , 1 , 3 );
|
||
|
M_CKERR_( 1 , "previous error cause" , 1 , 14 );
|
||
|
CPPUNIT_ASSERT( check( "" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testSetMacroBadBody( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process( "( -set-macro a x )" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
|
||
|
M_CKERR_( 0 , "invalid macro" , 1 , 3 );
|
||
|
M_CKERR_( 1 , "previous error cause" , 1 , 14 );
|
||
|
CPPUNIT_ASSERT( check( "" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testSetMacroInvalidBody( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process( "( -set-macro a ( nope ) )" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
|
||
|
M_CKERR_( 0 , "invalid macro" , 1 , 3 );
|
||
|
M_CKERR_( 1 , "previous error cause" , 1 , 14 );
|
||
|
CPPUNIT_ASSERT( check( "" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testSetMacroSuccess( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process(
|
||
|
"( -set-macro test ( -raw ( ((list)) ( (-raw -raw) $list ) ) ) )\n"
|
||
|
"(test $x $y $z (-set x 1))",
|
||
|
errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
|
||
|
CPPUNIT_ASSERT( check( "$x $y $z (-set x 1)" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testSetMacroDuplicate( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process(
|
||
|
"( -set-macro a (()) )\n"
|
||
|
"( -set-macro a (()) )" ,
|
||
|
errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
|
||
|
M_CKERR_( 0 , "duplicate macro" , 2 , 3 );
|
||
|
M_CKERR_( 1 , "previous error cause" , 2 , 14 );
|
||
|
CPPUNIT_ASSERT( check( "" , output ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testUnsetMacroNoArgs( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process( "( -unset-macro ) " , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
|
||
|
CPPUNIT_ASSERT( check( "" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testUnsetMacro( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process(
|
||
|
"( -set-macro a (()1) )\n"
|
||
|
"(a)\n"
|
||
|
"( -unset-macro a )\n"
|
||
|
"(a)" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
|
||
|
CPPUNIT_ASSERT( check( "1 (a)" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testUnsetMacroMissing( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process( "( -unset-macro a )(a)" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
|
||
|
CPPUNIT_ASSERT( check( "(a)" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testUnsetMacroMultiple( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process(
|
||
|
"( -set-macro a (()1) )\n"
|
||
|
"( -set-macro b (()2) )\n"
|
||
|
"( -set-macro c (()3) )\n"
|
||
|
"( -unset-macro a c d )\n"
|
||
|
"(a)(b)(c)\n" ,
|
||
|
errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
|
||
|
CPPUNIT_ASSERT( check( "(a) 2 (c)" , output ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testListMacros( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process(
|
||
|
"( -set x )\n"
|
||
|
"( -set-macro y ( ( ) ) )\n"
|
||
|
"( -set f (-raw (() ((-ls-macros))) ))\n"
|
||
|
"( -bless f )\n"
|
||
|
"( ( -ls-macros ) )\n"
|
||
|
"( -scope\n"
|
||
|
"( -unset-macro y )\n"
|
||
|
"( ( -ls-macros ) )\n"
|
||
|
")\n"
|
||
|
"($f)\n"
|
||
|
, errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
|
||
|
CPPUNIT_ASSERT( check( "( y ) ( ) ( y )" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testListMacrosArgs( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process(
|
||
|
"( -set-macro y ( ( ) ) )\n"
|
||
|
"( -ls-macros blah )\n"
|
||
|
, errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
|
||
|
M_CKERR_( 0 , "too many arguments" , 2 , 3 );
|
||
|
M_CKERR_( 1 , "previous error cause" , 2 , 14 );
|
||
|
CPPUNIT_ASSERT( check( "y" , output ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testMacroBodyInnerList( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process(
|
||
|
"( -set-macro x (-raw ( () -not-a-command ) ) )\n"
|
||
|
"( -set x (-raw ( () ) ) )\n"
|
||
|
"( -bless x )\n"
|
||
|
"( -set-macro y (-raw ( () $x ) ) )\n"
|
||
|
"(x)(y)" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
|
||
|
CPPUNIT_ASSERT( check( "-not-a-command (())" , output ) );
|
||
|
}
|
||
|
|
||
|
void SRDPreprocCmdMacrosTest::testMacroOutputInnerList( )
|
||
|
{
|
||
|
T_SRDErrors errors;
|
||
|
T_SRDList output( process(
|
||
|
"( -set-macro x (-raw ( () (-raw -not-a-command) ) ) )\n"
|
||
|
"( -set x (-raw ( () ) ) )\n"
|
||
|
"( -bless x )\n"
|
||
|
"( -set-macro y (-raw ( () (-raw $x ) ) ) )\n"
|
||
|
"(x)(y)" , errors ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
|
||
|
CPPUNIT_ASSERT( check( "-not-a-command (())" , output ) );
|
||
|
}
|