Permalink
Browse files

Add self test for _replaceTokenFindMatch

  • Loading branch information...
1 parent ff9e864 commit c0044122f41224df7907c0d4d31742cf4b80e6d6 @thomasjfox thomasjfox committed Jan 11, 2013
Showing with 54 additions and 0 deletions.
  1. +54 −0 tools/matchcompiler.py
View
@@ -571,6 +571,57 @@ def _selftest_replaceTokenSimpleMatch(self):
self._assertEquals(output, 'if (Token::simpleMatch(tok, "foo\"special\"bar")) {')
self._assertEquals(1, len(self._matchStrs))
+ def _selftest_replaceTokenFindSimpleMatch(self):
+ self._reset()
+
+ input = 'if (Token::findsimplematch(tok, "foobar")) {'
+ output = self._replaceTokenFindMatch(input)
+ self._assertEquals(output, 'if (findmatch1(tok)) {')
+ self._assertEquals(1, len(self._matchStrs))
+ self._assertEquals(1, self._matchStrs['foobar'])
+
+ input = 'if (Token::findsimplematch(tok->next()->next(), "foobar", tok->link())) {'
+ output = self._replaceTokenFindMatch(input)
+ self._assertEquals(output, 'if (findmatch2(tok->next()->next(), tok->link())) {')
+ self._assertEquals(1, len(self._matchStrs))
+ self._assertEquals(1, self._matchStrs['foobar'])
+
+ input = 'if (Token::findsimplematch(tok, "foo\"special\"bar")) {'
+ output = self._replaceTokenFindMatch(input)
+ # FIXME: Currently detected as non-static pattern
+ self._assertEquals(output, 'if (Token::findsimplematch(tok, "foo\"special\"bar")) {')
+ self._assertEquals(1, len(self._matchStrs))
+
+ def _selftest_replaceTokenFindMatch(self):
+ self._reset()
+
+ input = 'if (Token::findmatch(tok, "foobar")) {'
+ output = self._replaceTokenFindMatch(input)
+ self._assertEquals(output, 'if (findmatch1(tok)) {')
+ self._assertEquals(1, len(self._matchStrs))
+ self._assertEquals(1, self._matchStrs['foobar'])
+
+ # findmatch with varid
+ input = 'if (Token::findmatch(tok, "foobar %varid%", tok->varId())) {'
+ output = self._replaceTokenFindMatch(input)
+ self._assertEquals(output, 'if (findmatch2(tok, tok->varId())) {')
+ self._assertEquals(1, len(self._matchStrs))
+ self._assertEquals(1, self._matchStrs['foobar'])
+
+ # findmatch with end token
+ input = 'if (Token::findmatch(tok->next()->next(), "foobar %type%", tok->link())) {'
+ output = self._replaceTokenFindMatch(input)
+ self._assertEquals(output, 'if (findmatch3(tok->next()->next(), tok->link())) {')
+ self._assertEquals(2, len(self._matchStrs))
+ self._assertEquals(1, self._matchStrs['foobar'])
+
+ # findmatch with end token and varid
+ input = 'if (Token::findmatch(tok->next()->next(), "foobar %type% %varid%", tok->link(), 123)) {'
+ output = self._replaceTokenFindMatch(input)
+ self._assertEquals(output, 'if (findmatch4(tok->next()->next(), tok->link(), 123)) {')
+ self._assertEquals(2, len(self._matchStrs))
+ self._assertEquals(1, self._matchStrs['foobar'])
+
def _selftests(self):
self._selftest_parseMatch()
@@ -581,6 +632,9 @@ def _selftests(self):
self._selftest_replaceTokenMatchWithVarId()
self._selftest_replaceTokenSimpleMatch()
+ self._selftest_replaceTokenFindSimpleMatch()
+ self._selftest_replaceTokenFindMatch()
+
self._reset()
def main():

0 comments on commit c004412

Please sign in to comment.