Skip to content

Commit

Permalink
fix autotype custom attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZ3ro authored and phoerious committed Mar 4, 2018
1 parent d3a8051 commit 5f9f276
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/autotype/AutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,14 +659,15 @@ bool AutoType::checkSyntax(const QString& string)
QString delay = "DELAY=\\d+";
QString beep = "BEEP\\s\\d+\\s\\d+";
QString vkey = "VKEY(?:-[EN]X)?\\s\\w+";
QString customAttributes = "S:(?:[^\\{\\}])+";

// these chars aren't in parentheses
QString shortcutKeys = "[\\^\\%~\\+@]";
// a normal string not in parentheses
QString fixedStrings = "[^\\^\\%~\\+@\\{\\}]*";

QRegularExpression autoTypeSyntax("^(?:" + shortcutKeys + "|" + fixedStrings + "|\\{(?:" + normalCommands + "|" + specialLiterals +
"|" + functionKeys + "|" + numpad + "|" + delay + "|" + beep + "|" + vkey + ")\\})*$",
"|" + functionKeys + "|" + numpad + "|" + delay + "|" + beep + "|" + vkey + ")\\}|\\{" + customAttributes + "\\})*$",
QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = autoTypeSyntax.match(string);
return match.hasMatch();
Expand Down
45 changes: 27 additions & 18 deletions tests/TestAutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,32 +273,41 @@ void TestAutoType::testGlobalAutoTypeRegExp()
void TestAutoType::testAutoTypeSyntaxChecks()
{
// Huge sequence
QCOMPARE(true, AutoType::checkSyntax("{word 23}{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{SUBTRACT}~+%@fixedstring"));
QVERIFY(AutoType::checkSyntax("{word 23}{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{SUBTRACT}~+%@fixedstring"));

QCOMPARE(true, AutoType::checkSyntax("{NUMPAD1 3}"));
QVERIFY(AutoType::checkSyntax("{NUMPAD1 3}"));

QCOMPARE(true, AutoType::checkSyntax("{BEEP 3 3}"));
QCOMPARE(false, AutoType::checkSyntax("{BEEP 3}"));
QVERIFY(AutoType::checkSyntax("{S:SPECIALTOKEN}"));
QVERIFY(AutoType::checkSyntax("{S:SPECIAL TOKEN}"));
QVERIFY(AutoType::checkSyntax("{S:SPECIAL_TOKEN}"));
QVERIFY(AutoType::checkSyntax("{S:SPECIAL-TOKEN}"));
QVERIFY(AutoType::checkSyntax("{S:SPECIAL:TOKEN}"));
QVERIFY(AutoType::checkSyntax("{S:SPECIAL_TOKEN}{ENTER}"));
QVERIFY(AutoType::checkSyntax("{S:FOO}{S:HELLO WORLD}"));
QVERIFY(!AutoType::checkSyntax("{S:SPECIAL_TOKEN{}}"));

QCOMPARE(true, AutoType::checkSyntax("{VKEY 0x01}"));
QCOMPARE(true, AutoType::checkSyntax("{VKEY VK_LBUTTON}"));
QCOMPARE(true, AutoType::checkSyntax("{VKEY-EX 0x01}"));
QVERIFY(AutoType::checkSyntax("{BEEP 3 3}"));
QVERIFY(!AutoType::checkSyntax("{BEEP 3}"));

QVERIFY(AutoType::checkSyntax("{VKEY 0x01}"));
QVERIFY(AutoType::checkSyntax("{VKEY VK_LBUTTON}"));
QVERIFY(AutoType::checkSyntax("{VKEY-EX 0x01}"));
// Bad sequence
QCOMPARE(false, AutoType::checkSyntax("{{{}}{}{}}{{}}"));
QVERIFY(!AutoType::checkSyntax("{{{}}{}{}}{{}}"));
// Good sequence
QCOMPARE(true, AutoType::checkSyntax("{{}{}}{}}{{}"));
QCOMPARE(true, AutoType::checkSyntax("{]}{[}{[}{]}"));
QCOMPARE(true, AutoType::checkSyntax("{)}{(}{(}{)}"));
QVERIFY(AutoType::checkSyntax("{{}{}}{}}{{}"));
QVERIFY(AutoType::checkSyntax("{]}{[}{[}{]}"));
QVERIFY(AutoType::checkSyntax("{)}{(}{(}{)}"));
// High DelAY / low delay
QCOMPARE(true, AutoType::checkHighDelay("{DelAY 50000}"));
QCOMPARE(false, AutoType::checkHighDelay("{delay 50}"));
QVERIFY(AutoType::checkHighDelay("{DelAY 50000}"));
QVERIFY(!AutoType::checkHighDelay("{delay 50}"));
// Slow typing
QCOMPARE(true, AutoType::checkSlowKeypress("{DelAY=50000}"));
QCOMPARE(false, AutoType::checkSlowKeypress("{delay=50}"));
QVERIFY(AutoType::checkSlowKeypress("{DelAY=50000}"));
QVERIFY(!AutoType::checkSlowKeypress("{delay=50}"));
// Many repetition / few repetition / delay not repetition
QCOMPARE(true, AutoType::checkHighRepetition("{LEFT 50000000}"));
QCOMPARE(false, AutoType::checkHighRepetition("{SPACE 10}{TAB 3}{RIGHT 50}"));
QCOMPARE(false, AutoType::checkHighRepetition("{delay 5000000000}"));
QVERIFY(AutoType::checkHighRepetition("{LEFT 50000000}"));
QVERIFY(!AutoType::checkHighRepetition("{SPACE 10}{TAB 3}{RIGHT 50}"));
QVERIFY(!AutoType::checkHighRepetition("{delay 5000000000}"));
}

void TestAutoType::testAutoTypeEffectiveSequences()
Expand Down

0 comments on commit 5f9f276

Please sign in to comment.