Fix keyboard_input SEGFAULT
This commit is contained in:
@@ -61,7 +61,7 @@ std::vector<Token> ParseKeyboardInputsToTokens( const std::string inputs )
|
||||
{
|
||||
std::vector<Token> tokens{};
|
||||
|
||||
for ( auto ch = inputs.begin(); ch != inputs.end(); ++ch )
|
||||
for ( auto ch = inputs.begin(), end = inputs.end(); ch != end; ++ch )
|
||||
{
|
||||
if ( const auto c = getNumberOrLetter( *ch ); c.has_value() )
|
||||
{
|
||||
@@ -84,6 +84,10 @@ std::vector<Token> ParseKeyboardInputsToTokens( const std::string inputs )
|
||||
if ( *ch == 'F' )
|
||||
{
|
||||
++ch;
|
||||
if ( ch == end )
|
||||
{
|
||||
break;
|
||||
}
|
||||
const auto token = getFunctionNumber( *ch );
|
||||
if ( token.has_value() )
|
||||
{
|
||||
|
||||
@@ -24,6 +24,8 @@ private slots:
|
||||
void Modifiers();
|
||||
|
||||
void functionKeys();
|
||||
|
||||
void shouldExitEarlyFunctionKey();
|
||||
};
|
||||
|
||||
const std::string alphabet = "abcdefghijklmnopqrstuvxyz";
|
||||
@@ -164,6 +166,25 @@ void ParserTest::functionKeys()
|
||||
QVERIFY( t == e );
|
||||
}
|
||||
|
||||
void ParserTest::shouldExitEarlyFunctionKey()
|
||||
{
|
||||
auto t = ParseKeyboardInputsToTokens( "asF" );
|
||||
auto e = std::vector<Token>( { Token::KEY_a, Token::KEY_s } );
|
||||
QVERIFY( t == e );
|
||||
|
||||
t = ParseKeyboardInputsToTokens( "asFs" );
|
||||
e = std::vector<Token>( { Token::KEY_a, Token::KEY_s } );
|
||||
QVERIFY( t == e );
|
||||
|
||||
t = ParseKeyboardInputsToTokens( "F" );
|
||||
e = std::vector<Token>( {} );
|
||||
QVERIFY( t == e );
|
||||
|
||||
t = ParseKeyboardInputsToTokens( "Fsdfg" );
|
||||
e = std::vector<Token>( {} );
|
||||
QVERIFY( t == e );
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN( ParserTest )
|
||||
|
||||
#include "tst_parsertest.moc"
|
||||
|
||||
Reference in New Issue
Block a user