corelib/tests/srd-lexer.cc
Emmanuel BENOîT 30d8d3057e Windows "compatibility"
* Makefile changes allowing for cross-compilation
* SRDData: had to rename an enum member from ERROR to ERR because
apparently creating a macro called ERROR is a thing in the windows
headers
* DynLib: ported
* Strings: fixes in toOSString, untested for now
* Fixes in some tests
* TODO list update
2018-06-17 12:39:02 +02:00

687 lines
18 KiB
C++

#include <ebcl/SRDText.hh>
#include <cppunit/extensions/HelperMacros.h>
using namespace ebcl;
class SRDLexerTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( SRDLexerTest );
CPPUNIT_TEST( testEmpty );
CPPUNIT_TEST( testList );
CPPUNIT_TEST( testString );
CPPUNIT_TEST( testStringUnterminatedEOL );
CPPUNIT_TEST( testStringUnterminatedEscEOL );
CPPUNIT_TEST( testStringUnterminatedEOI );
CPPUNIT_TEST( testStringUnterminatedEscEOI );
CPPUNIT_TEST( testStringUTF8Short );
CPPUNIT_TEST( testStringUTF8Long );
CPPUNIT_TEST( testStringUTF8BadCodepoint );
CPPUNIT_TEST( testStringUTF8BadHexa );
CPPUNIT_TEST( testStringUTF8BadSequence );
CPPUNIT_TEST( testStringUTF8ControlInSequence );
CPPUNIT_TEST( testStringUTF8EOSInSequence );
CPPUNIT_TEST( testStringUTF8EOLInSequence );
CPPUNIT_TEST( testStringUTF8EOIInSequence );
CPPUNIT_TEST( testCommentSLEmptyEOL );
CPPUNIT_TEST( testCommentSLEmptyEOI );
CPPUNIT_TEST( testCommentSLEOL );
CPPUNIT_TEST( testCommentSLEOI );
CPPUNIT_TEST( testCommentMLEmpty );
CPPUNIT_TEST( testCommentMLEmptyEOI );
CPPUNIT_TEST( testCommentMLEmptyUnterminated );
CPPUNIT_TEST( testCommentML );
CPPUNIT_TEST( testCommentMLEOI );
CPPUNIT_TEST( testCommentMLUnterminated );
CPPUNIT_TEST( testCommentMLNested );
CPPUNIT_TEST( testCommentMLNestedUnterminated );
CPPUNIT_TEST( testIntegers );
CPPUNIT_TEST( testFloatValid );
CPPUNIT_TEST( testFloatInvalid );
CPPUNIT_TEST( testWordValid );
CPPUNIT_TEST( testWordInvalid );
CPPUNIT_TEST( testVarValid );
CPPUNIT_TEST( testVarInvalid );
CPPUNIT_TEST( testBinaryEmpty );
CPPUNIT_TEST( testBinaryValid );
CPPUNIT_TEST( testBinaryBadDigit1 );
CPPUNIT_TEST( testBinaryBadDigit2 );
CPPUNIT_TEST( testBinaryBadDigit3 );
CPPUNIT_TEST( testBinaryUnterminated );
CPPUNIT_TEST_SUITE_END( );
T_String location = T_String( "test" );
public:
void testEmpty( );
void testList( );
void testString( );
void testStringUnterminatedEOL( );
void testStringUnterminatedEscEOL( );
void testStringUnterminatedEOI( );
void testStringUnterminatedEscEOI( );
void testStringUTF8Short( );
void testStringUTF8Long( );
void testStringUTF8BadCodepoint( );
void testStringUTF8BadHexa( );
void testStringUTF8BadSequence( );
void testStringUTF8ControlInSequence( );
void testStringUTF8EOSInSequence( );
void testStringUTF8EOLInSequence( );
void testStringUTF8EOIInSequence( );
void testCommentSLEmptyEOL( );
void testCommentSLEmptyEOI( );
void testCommentSLEOL( );
void testCommentSLEOI( );
void testCommentMLEmpty( );
void testCommentMLEmptyEOI( );
void testCommentMLEmptyUnterminated( );
void testCommentML( );
void testCommentMLEOI( );
void testCommentMLUnterminated( );
void testCommentMLNested( );
void testCommentMLNestedUnterminated( );
void testIntegers( );
void testFloatValid( );
void testFloatInvalid( );
void testWordValid( );
void testWordInvalid( );
void testVarValid( );
void testVarInvalid( );
void testBinaryEmpty( );
void testBinaryValid( );
void testBinaryBadDigit1( );
void testBinaryBadDigit2( );
void testBinaryBadDigit3( );
void testBinaryUnterminated( );
};
CPPUNIT_TEST_SUITE_REGISTRATION( SRDLexerTest );
/*----------------------------------------------------------------------------*/
#define M_TEST_(INPUT) \
T_SRDErrors errors; \
T_SRDList list( ([&]( ) \
{ \
T_SRDMemoryTarget mt( false ); \
mt.start( errors ); \
T_SRDLexer lexer( location , errors , mt ); \
char const* ptr = INPUT; \
while ( *ptr != 0 ) lexer.processCharacter( *ptr ++ ); \
lexer.processEnd( ); \
return mt.list( ); \
} )( ) );
#define M_CKLS_(SIZE) \
CPPUNIT_ASSERT_EQUAL( uint32_t( SIZE ) , list.size( ) )
#define M_CKTOK_(ITEM,TYPE,L,C) \
do { \
CPPUNIT_ASSERT( E_SRDTokenType::TYPE == \
list[ ITEM ].type( ) ); \
CPPUNIT_ASSERT( list[ ITEM ].hasLocation( ) ); \
CPPUNIT_ASSERT( location == \
list[ ITEM ].location( ).source( ) ); \
CPPUNIT_ASSERT_EQUAL( uint32_t( L ) , \
list[ ITEM ].location( ).line( ) ); \
CPPUNIT_ASSERT_EQUAL( size_t( C ) , \
list[ ITEM ].location( ).character( ) ); \
} while ( 0 )
#define M_CKERRS_( x ) \
CPPUNIT_ASSERT_EQUAL( uint32_t( x ) , errors.size( ) )
#define M_CKERR_(IDX,STR,L,C) \
do { \
auto const& _e( errors[ IDX ] ); \
CPPUNIT_ASSERT( T_String( STR ) == _e.error( ) ); \
CPPUNIT_ASSERT( location == _e.location( ).source( ) ); \
CPPUNIT_ASSERT_EQUAL( uint32_t( L ) , \
_e.location( ).line( ) ); \
CPPUNIT_ASSERT_EQUAL( size_t( C ) , \
_e.location( ).character( ) ); \
} while ( 0 )
#define M_PRINTERR_(IDX) \
do { \
auto const& _e( errors[ IDX ] ); \
char err[ _e.error( ).size( ) + 1 ]; \
err[ sizeof( err ) - 1 ] = 0; \
memcpy( err , _e.error( ).data( ) , \
sizeof( err ) - 1 ); \
printf( "ERR %s l. %u c. %lu\n" , err , \
_e.location( ).line( ) , \
_e.location( ).character( ) ); \
} while ( 0 )
/*----------------------------------------------------------------------------*/
void SRDLexerTest::testEmpty( )
{
M_TEST_( "" );
M_CKLS_( 0 );
M_CKERRS_( 0 );
}
/*----------------------------------------------------------------------------*/
void SRDLexerTest::testList( )
{
M_TEST_( "( )" );
M_CKERRS_( 0 );
M_CKLS_( 2 );
M_CKTOK_( 0 , START , 1 , 1 );
M_CKTOK_( 1 , END , 1 , 3 );
}
/*----------------------------------------------------------------------------*/
void SRDLexerTest::testString( )
{
M_TEST_( "\"test\\\\\\\"\\t\\n\\r\"" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "test\\\"\t\n\r" ) );
}
void SRDLexerTest::testStringUnterminatedEOL( )
{
M_TEST_( "\"test\\\\\\\"\\t\\n\\r\n" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "unterminated string" , 1 , 16 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "test\\\"\t\n\r" ) );
}
void SRDLexerTest::testStringUnterminatedEscEOL( )
{
M_TEST_( "\"test\\\\\\\"\\t\\n\\\n" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "unterminated string" , 1 , 15 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "test\\\"\t\n" ) );
}
void SRDLexerTest::testStringUnterminatedEOI( )
{
M_TEST_( "\"test\\\\\\\"\\t\\n\\r" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "unterminated string" , 1 , 16 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "test\\\"\t\n\r" ) );
}
void SRDLexerTest::testStringUnterminatedEscEOI( )
{
M_TEST_( "\"test\\\\\\\"\\t\\n\\" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "unterminated string" , 1 , 15 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "test\\\"\t\n" ) );
}
void SRDLexerTest::testStringUTF8Short( )
{
M_TEST_( "\"\\u20ac\"" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( "\xe2\x82\xac" ) );
}
void SRDLexerTest::testStringUTF8Long( )
{
M_TEST_( "\"\\U000020ac\"" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( "\xe2\x82\xac" ) );
}
void SRDLexerTest::testStringUTF8BadCodepoint( )
{
M_TEST_( "\"\\Uffffffff\"" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "invalid UTF-8 codepoint" , 1 , 11 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( ) );
}
void SRDLexerTest::testStringUTF8BadHexa( )
{
M_TEST_( "\"\\u20aw\"" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "invalid UTF-8 sequence" , 1 , 7 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( ) );
}
void SRDLexerTest::testStringUTF8BadSequence( )
{
M_TEST_( "\"\\u20-w\"" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "invalid UTF-8 sequence" , 1 , 6 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( "w" ) );
}
void SRDLexerTest::testStringUTF8ControlInSequence( )
{
M_TEST_( "\"\\u20\x01w\"" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "control character in UTF-8 sequence" , 1 , 6 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( "w" ) );
}
void SRDLexerTest::testStringUTF8EOSInSequence( )
{
M_TEST_( "\"\\u20\"" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "incomplete UTF-8 sequence" , 1 , 6 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( ) );
}
void SRDLexerTest::testStringUTF8EOLInSequence( )
{
M_TEST_( "\"\\u20\n" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "unterminated string" , 1 , 6 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( ) );
}
void SRDLexerTest::testStringUTF8EOIInSequence( )
{
M_TEST_( "\"\\u20" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "unterminated string" , 1 , 6 );
M_CKLS_( 1 );
M_CKTOK_( 0 , STRING , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( ) );
}
/*----------------------------------------------------------------------------*/
void SRDLexerTest::testCommentSLEmptyEOL( )
{
M_TEST_( "# \n" );
M_CKERRS_( 0 );
M_CKLS_( 0 );
}
void SRDLexerTest::testCommentSLEmptyEOI( )
{
M_TEST_( "# " );
M_CKERRS_( 0 );
M_CKLS_( 0 );
}
void SRDLexerTest::testCommentSLEOL( )
{
M_TEST_( "# test\n" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , COMMENT , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( "test" ) );
}
void SRDLexerTest::testCommentSLEOI( )
{
M_TEST_( "# test" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , COMMENT , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( ) == T_String( "test" ) );
}
/*----------------------------------------------------------------------------*/
void SRDLexerTest::testCommentMLEmpty( )
{
M_TEST_( "{ \n \n }\n" );
M_CKERRS_( 0 );
M_CKLS_( 0 );
}
void SRDLexerTest::testCommentMLEmptyEOI( )
{
M_TEST_( "{ \n \n }" );
M_CKERRS_( 0 );
M_CKLS_( 0 );
}
void SRDLexerTest::testCommentMLEmptyUnterminated( )
{
M_TEST_( "{ \n \n " );
M_CKERRS_( 1 );
M_CKERR_( 0 , "unterminated multi-line comment" , 3 , 2 );
M_CKLS_( 0 );
}
void SRDLexerTest::testCommentML( )
{
M_TEST_( "{ this is a\n test }\n" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , COMMENT , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "this is a\n test " ) );
}
void SRDLexerTest::testCommentMLEOI( )
{
M_TEST_( "{ this is a\n test }" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , COMMENT , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "this is a\n test " ) );
}
void SRDLexerTest::testCommentMLUnterminated( )
{
M_TEST_( "{ this is a\n test" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "unterminated multi-line comment" , 2 , 6 );
M_CKLS_( 1 );
M_CKTOK_( 0 , COMMENT , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "this is a\n test" ) );
}
void SRDLexerTest::testCommentMLNested( )
{
M_TEST_( "{ this { is a }\n test }" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , COMMENT , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "this { is a }\n test " ) );
}
void SRDLexerTest::testCommentMLNestedUnterminated( )
{
M_TEST_( "{ this { is a }\n test" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "unterminated multi-line comment" , 2 , 6 );
M_CKLS_( 1 );
M_CKTOK_( 0 , COMMENT , 1 , 1 );
CPPUNIT_ASSERT( list[ 0 ].stringValue( )
== T_String( "this { is a }\n test" ) );
}
/*----------------------------------------------------------------------------*/
void SRDLexerTest::testIntegers( )
{
M_TEST_(
"0 000 -0 1 -1 123 -123 5000000000 -5000000000 "
"1000000000000000000000000000000000000000000000 123"
);
M_CKERRS_( 1 );
M_CKERR_( 0 , "invalid integer value" , 1 , 93 );
M_CKLS_( 11 );
M_CKTOK_( 0 , INT , 1 , 1 );
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , list[ 0 ].longValue( ) );
M_CKTOK_( 1 , INT , 1 , 3 );
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , list[ 1 ].longValue( ) );
M_CKTOK_( 2 , INT , 1 , 7 );
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , list[ 2 ].longValue( ) );
M_CKTOK_( 3 , INT , 1 , 10 );
CPPUNIT_ASSERT_EQUAL( int64_t( 1 ) , list[ 3 ].longValue( ) );
M_CKTOK_( 4 , INT , 1 , 12 );
CPPUNIT_ASSERT_EQUAL( int64_t( -1 ) , list[ 4 ].longValue( ) );
M_CKTOK_( 5 , INT , 1 , 15 );
CPPUNIT_ASSERT_EQUAL( int64_t( 123 ) , list[ 5 ].longValue( ) );
M_CKTOK_( 6 , INT , 1 , 19 );
CPPUNIT_ASSERT_EQUAL( int64_t( -123 ) , list[ 6 ].longValue( ) );
M_CKTOK_( 7 , LONG , 1 , 24 );
CPPUNIT_ASSERT_EQUAL( int64_t( 5000000000 ) , list[ 7 ].longValue( ) );
M_CKTOK_( 8 , LONG , 1 , 35 );
CPPUNIT_ASSERT_EQUAL( int64_t( -5000000000 ) , list[ 8 ].longValue( ) );
M_CKTOK_( 9 , INT , 1 , 47 );
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , list[ 9 ].longValue( ) );
M_CKTOK_( 10 , INT , 1 , 94 );
CPPUNIT_ASSERT_EQUAL( int64_t( 123 ) , list[ 10 ].longValue( ) );
}
void SRDLexerTest::testFloatValid( )
{
M_TEST_(
"0.\n.0\n-0.\n-.0\n1.0\n-1.0\n1e0\n1e-0\n1e+0\n1.e0\n1.e+0\n"
"1.e-0\n1.0e0\n1.0e+0\n1.0e-0\n.1e1\n.1e+1\n.1e-1\n11.25e2\n"
"112500e-2\n11.25e+2"
);
M_CKERRS_( 0 );
M_CKLS_( 21 );
for ( int i = 0 ; i < 21 ; i ++ ) {
M_CKTOK_( i , FLOAT , i + 1 , 1 );
}
CPPUNIT_ASSERT_EQUAL( 0.0 , list[ 0 ].floatValue( ) );
CPPUNIT_ASSERT_EQUAL( 0.0 , list[ 1 ].floatValue( ) );
CPPUNIT_ASSERT_EQUAL( 0.0 , list[ 2 ].floatValue( ) );
CPPUNIT_ASSERT_EQUAL( 0.0 , list[ 3 ].floatValue( ) );
CPPUNIT_ASSERT_EQUAL( 1.0 , list[ 4 ].floatValue( ) );
CPPUNIT_ASSERT_EQUAL( -1.0 , list[ 5 ].floatValue( ) );
for ( int i = 6 ; i < 17 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( 1.0 , list[ i ].floatValue( ) );
}
CPPUNIT_ASSERT_EQUAL( .01 , list[ 17 ].floatValue( ) );
for ( int i = 18 ; i < 21 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( 1125.0 , list[ i ].floatValue( ) );
}
}
void SRDLexerTest::testFloatInvalid( )
{
M_TEST_(
".\n-.\n1e\n1e+\n1e-"
);
M_CKERRS_( 5 );
M_CKERR_( 0 , "fractional part expected" , 1 , 2 );
M_CKERR_( 1 , "fractional part expected" , 2 , 3 );
M_CKERR_( 2 , "exponent expected" , 3 , 3 );
M_CKERR_( 3 , "exponent expected" , 4 , 4 );
M_CKERR_( 4 , "exponent expected" , 5 , 4 );
M_CKLS_( 5 );
for ( int i = 0 ; i < 5 ; i ++ ) {
M_CKTOK_( i , FLOAT , i + 1 , 1 );
CPPUNIT_ASSERT_EQUAL( i < 2 ? 0.0 : 1.0 ,
list[ i ].floatValue( ) );
}
}
/*----------------------------------------------------------------------------*/
void SRDLexerTest::testWordValid( )
{
const char WORDS[5][7] = {
"word" , "-word" , "w12d" , "w-ord" , "-w-ord"
};
for ( int i = 0 ; i < 5 ; i ++ ) {
for ( int j = 0 ; j < 1 ; j ++ ) {
char buffer[ 12 ];
strcpy( buffer , WORDS[ i ] );
if ( j ) strcat( buffer , "\n" );
M_TEST_( buffer );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , WORD , 1 , 1 );
CPPUNIT_ASSERT( T_String::Pooled( WORDS[ i ] )
== list[ 0 ].stringValue( ) );
}
}
}
void SRDLexerTest::testWordInvalid( )
{
const char WORDS[4][8] = {
"12word" , "word.0" , "-word-" , "word\"\""
};
for ( int i = 0 ; i < 4 ; i ++ ) {
for ( int j = 0 ; j < 1 ; j ++ ) {
char buffer[ 12 ];
strcpy( buffer , WORDS[ i ] );
if ( j ) strcat( buffer , "\n" );
M_TEST_( buffer );
M_CKERRS_( 1 );
}
}
}
void SRDLexerTest::testVarValid( )
{
const char WORDS[3][7] = {
"word" , "w12d" , "w-ord"
};
for ( int i = 0 ; i < 3 ; i ++ ) {
for ( int j = 0 ; j < 1 ; j ++ ) {
char buffer[ 12 ] = { '$' , 0 };
strcat( buffer , WORDS[ i ] );
if ( j ) strcat( buffer , "\n" );
M_TEST_( buffer );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , VAR , 1 , 1 );
CPPUNIT_ASSERT( T_String::Pooled( WORDS[ i ] )
== list[ 0 ].stringValue( ) );
}
}
}
void SRDLexerTest::testVarInvalid( )
{
const char WORDS[5][8] = {
"-word" , "12word" , "word.0" , "-word-" , "word\"\""
};
for ( int i = 0 ; i < 5 ; i ++ ) {
for ( int j = 0 ; j < 1 ; j ++ ) {
char buffer[ 12 ] = { '$' , 0 };
strcat( buffer , WORDS[ i ] );
if ( j ) strcat( buffer , "\n" );
M_TEST_( buffer );
M_CKERRS_( 1 );
}
}
}
/*----------------------------------------------------------------------------*/
void SRDLexerTest::testBinaryEmpty( )
{
M_TEST_( "[]" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , BINARY , 1 , 1 );
CPPUNIT_ASSERT_EQUAL( size_t( 0 ) , list[ 0 ].binary( ).size( ) );
}
void SRDLexerTest::testBinaryValid( )
{
M_TEST_( "[ 12 34 ab CD ef56 ]" );
M_CKERRS_( 0 );
M_CKLS_( 1 );
M_CKTOK_( 0 , BINARY , 1 , 1 );
CPPUNIT_ASSERT_EQUAL( size_t( 6 ) , list[ 0 ].binary( ).size( ) );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0x12 ) , list[ 0 ].binary( )[ 0 ] );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0x34 ) , list[ 0 ].binary( )[ 1 ] );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0xab ) , list[ 0 ].binary( )[ 2 ] );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0xcd ) , list[ 0 ].binary( )[ 3 ] );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0xef ) , list[ 0 ].binary( )[ 4 ] );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0x56 ) , list[ 0 ].binary( )[ 5 ] );
}
void SRDLexerTest::testBinaryBadDigit1( )
{
M_TEST_( "[ nope 12 ]" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "invalid binary digit" , 1 , 3 );
M_CKLS_( 1 );
M_CKTOK_( 0 , BINARY , 1 , 1 );
CPPUNIT_ASSERT_EQUAL( size_t( 1 ) , list[ 0 ].binary( ).size( ) );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0x12 ) , list[ 0 ].binary( )[ 0 ] );
}
void SRDLexerTest::testBinaryBadDigit2( )
{
M_TEST_( "[ 1x 12 ]" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "invalid binary digit" , 1 , 4 );
M_CKLS_( 1 );
M_CKTOK_( 0 , BINARY , 1 , 1 );
CPPUNIT_ASSERT_EQUAL( size_t( 2 ) , list[ 0 ].binary( ).size( ) );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0x10 ) , list[ 0 ].binary( )[ 0 ] );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0x12 ) , list[ 0 ].binary( )[ 1 ] );
}
void SRDLexerTest::testBinaryBadDigit3( )
{
M_TEST_( "[ 12lolnopethiswontwork 34 ]" );
M_CKERRS_( 1 );
M_CKERR_( 0 , "invalid binary digit" , 1 , 5 );
M_CKLS_( 1 );
M_CKTOK_( 0 , BINARY , 1 , 1 );
CPPUNIT_ASSERT_EQUAL( size_t( 2 ) , list[ 0 ].binary( ).size( ) );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0x12 ) , list[ 0 ].binary( )[ 0 ] );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0x34 ) , list[ 0 ].binary( )[ 1 ] );
}
void SRDLexerTest::testBinaryUnterminated( )
{
M_TEST_( "[ 12 " );
M_CKERRS_( 1 );
M_CKERR_( 0 , "incomplete binary data" , 1 , 6 );
M_CKLS_( 1 );
M_CKTOK_( 0 , BINARY , 1 , 1 );
CPPUNIT_ASSERT_EQUAL( size_t( 1 ) , list[ 0 ].binary( ).size( ) );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0x12 ) , list[ 0 ].binary( )[ 0 ] );
}