def testGetPrevMatchingLTWithInnerOnes(self): lexer = nsiqcppstyle_checker.CppLexerNavigator( "a.cpp", "std::map<std::set<int>, float> m;") # This step resolves comments and some token types like FUNCTION nsiqcppstyle_checker.ContructContextInfo(lexer) lexer.Reset() # Get the first < token ltToken = lexer.GetNextTokenInType("LT") assert (ltToken is not None and ltToken.type == "LT" and ltToken.column == 9) # Get the first > token gtToken = lexer.GetNextTokenInType("GT") assert (gtToken is not None and gtToken.type == "GT") # Get the second > token prevGtTokenColumn = gtToken.column gtToken = lexer.GetNextTokenInType("GT") assert (gtToken is not None and gtToken.type == "GT" and gtToken.column != prevGtTokenColumn) # Expect the matching < token to be the first < token matchingLtToken = lexer.GetPrevMatchingLT() assert (matchingLtToken is not None and matchingLtToken.type == "LT") assert (matchingLtToken.column == ltToken.column)
def test5(self): data = """ foo (bar*)[]; """ navigator = nsiqcppstyle_checker.CppLexerNavigator("a.cpp", data) nsiqcppstyle_checker.ContructContextInfo(navigator) navigator.Reset() tok = navigator.GetNextTokenSkipWhiteSpaceAndComment() assert(tok.type == 'ID' and tok.value == 'foo')
def testGetPrevMatchingLT(self): lexer = nsiqcppstyle_checker.CppLexerNavigator("a.cpp", "std::set<int> m;") # This step resolves comments and some token types like FUNCTION nsiqcppstyle_checker.ContructContextInfo(lexer) lexer.Reset(); ltToken = lexer.GetNextTokenInType("LT") assert(ltToken != None and ltToken.type == "LT") gtToken = lexer.GetNextTokenInType("GT") assert(gtToken != None and gtToken.type == "GT") matchingLtToken = lexer.GetPrevMatchingLT() assert(matchingLtToken != None and matchingLtToken.type == "LT") assert(matchingLtToken.column == ltToken.column)
def test3(self): data = """ #ifdef dsd void function1() { #else void function2() { #endif } """ navigator = nsiqcppstyle_checker.CppLexerNavigator("a.cpp", data) nsiqcppstyle_checker.ContructContextInfo(navigator) navigator.Reset() while(True): tok = navigator.GetNextTokenSkipWhiteSpaceAndComment() if tok is None: break
def __testFunctionSpecifier(self, specifier): lexer = nsiqcppstyle_checker.CppLexerNavigator("a.cpp", "void FunctionName() " + specifier + ";") # This step resolves comments and some token types like FUNCTION nsiqcppstyle_checker.ContructContextInfo(lexer) lexer.Reset(); assert(lexer.GetNextTokenSkipWhiteSpaceAndComment().type == 'VOID') assert(lexer.GetNextTokenSkipWhiteSpaceAndComment().type == 'FUNCTION') assert(lexer.GetNextTokenSkipWhiteSpaceAndComment().type == 'LPAREN') assert(lexer.GetNextTokenSkipWhiteSpaceAndComment().type == 'RPAREN') # Specifier keyword specifierToken = lexer.GetNextTokenSkipWhiteSpaceAndComment() assert(specifierToken.type == 'IGNORE') assert(specifierToken.value == specifier) assert(lexer.GetNextTokenSkipWhiteSpaceAndComment().type == 'SEMI') assert(lexer.GetNextTokenSkipWhiteSpaceAndComment() == None)
def test4(self): data = """ #define dsd(dsd) \\ \tdo { \\ ff(1);\\ } while(0) int a; """ console.SetLevel(console.Level.Verbose) navigator = nsiqcppstyle_checker.CppLexerNavigator("a.cpp", data) nsiqcppstyle_checker.ContructContextInfo(navigator) navigator.Reset() while(True): tok = navigator.GetNextTokenSkipWhiteSpaceAndComment() if tok is None: break
def test4(self): data = """ #define dsd(dsd) \\ \tdo { \\ ff(1);\\ } while(0) int a; """ nsiqcppstyle_state._nsiqcppstyle_state.verbose = True navigator = nsiqcppstyle_checker.CppLexerNavigator("a.cpp", data) nsiqcppstyle_checker.ContructContextInfo(navigator) navigator.Reset() while(True) : tok = navigator.GetNextTokenSkipWhiteSpaceAndComment() if tok == None : break print tok, tok.contextStack, tok.pp