@@ -27,46 +27,51 @@ import (
2727var _ = Suite (& testConsistentSuite {})
2828
2929type testConsistentSuite struct {
30+ content string
31+
32+ reservedKeywords []string
33+ unreservedKeywords []string
34+ notKeywordTokens []string
35+ tidbKeywords []string
3036}
3137
32- func (s * testConsistentSuite ) TestKeywordConsistent (c * C ) {
38+ func (s * testConsistentSuite ) SetUpSuite (c * C ) {
3339 _ , filename , _ , _ := runtime .Caller (0 )
3440 parserFilename := path .Join (path .Dir (filename ), "parser.y" )
3541 parserFile , err := os .Open (parserFilename )
3642 c .Assert (err , IsNil )
3743 data , err := ioutil .ReadAll (parserFile )
3844 c .Assert (err , IsNil )
39- content : = string (data )
45+ s . content = string (data )
4046
4147 reservedKeywordStartMarker := "\t /* The following tokens belong to ReservedKeyword. Notice: make sure these tokens are contained in ReservedKeyword. */"
4248 unreservedKeywordStartMarker := "\t /* The following tokens belong to UnReservedKeyword. Notice: make sure these tokens are contained in UnReservedKeyword. */"
4349 notKeywordTokenStartMarker := "\t /* The following tokens belong to NotKeywordToken. Notice: make sure these tokens are contained in NotKeywordToken. */"
4450 tidbKeywordStartMarker := "\t /* The following tokens belong to TiDBKeyword. Notice: make sure these tokens are contained in TiDBKeyword. */"
4551 identTokenEndMarker := "%token\t <item>"
4652
47- reservedKeywords := extractKeywords (content , reservedKeywordStartMarker , unreservedKeywordStartMarker )
48-
49- unreservedKeywords := extractKeywords (content , unreservedKeywordStartMarker , notKeywordTokenStartMarker )
50-
51- notKeywordTokens := extractKeywords (content , notKeywordTokenStartMarker , tidbKeywordStartMarker )
52-
53- tidbKeywords := extractKeywords (content , tidbKeywordStartMarker , identTokenEndMarker )
53+ s .reservedKeywords = extractKeywords (s .content , reservedKeywordStartMarker , unreservedKeywordStartMarker )
54+ s .unreservedKeywords = extractKeywords (s .content , unreservedKeywordStartMarker , notKeywordTokenStartMarker )
55+ s .notKeywordTokens = extractKeywords (s .content , notKeywordTokenStartMarker , tidbKeywordStartMarker )
56+ s .tidbKeywords = extractKeywords (s .content , tidbKeywordStartMarker , identTokenEndMarker )
57+ }
5458
59+ func (s * testConsistentSuite ) TestKeywordConsistent (c * C ) {
5560 for k , v := range aliases {
56- c .Assert (k != v , IsTrue )
61+ c .Assert (k , Not ( Equals ), v )
5762 c .Assert (tokenMap [k ], Equals , tokenMap [v ])
5863 }
59- keywordCount := len (reservedKeywords ) + len (unreservedKeywords ) + len (notKeywordTokens ) + len (tidbKeywords )
64+ keywordCount := len (s . reservedKeywords ) + len (s . unreservedKeywords ) + len (s . notKeywordTokens ) + len (s . tidbKeywords )
6065 c .Assert (len (tokenMap )- len (aliases ), Equals , keywordCount - len (windowFuncTokenMap ))
6166
62- unreservedCollectionDef := extractKeywordsFromCollectionDef (content , "\n UnReservedKeyword:" )
63- c .Assert (unreservedKeywords , DeepEquals , unreservedCollectionDef )
67+ unreservedCollectionDef := extractKeywordsFromCollectionDef (s . content , "\n UnReservedKeyword:" )
68+ c .Assert (s . unreservedKeywords , DeepEquals , unreservedCollectionDef )
6469
65- notKeywordTokensCollectionDef := extractKeywordsFromCollectionDef (content , "\n NotKeywordToken:" )
66- c .Assert (notKeywordTokens , DeepEquals , notKeywordTokensCollectionDef )
70+ notKeywordTokensCollectionDef := extractKeywordsFromCollectionDef (s . content , "\n NotKeywordToken:" )
71+ c .Assert (s . notKeywordTokens , DeepEquals , notKeywordTokensCollectionDef )
6772
68- tidbKeywordsCollectionDef := extractKeywordsFromCollectionDef (content , "\n TiDBKeyword:" )
69- c .Assert (tidbKeywords , DeepEquals , tidbKeywordsCollectionDef )
73+ tidbKeywordsCollectionDef := extractKeywordsFromCollectionDef (s . content , "\n TiDBKeyword:" )
74+ c .Assert (s . tidbKeywords , DeepEquals , tidbKeywordsCollectionDef )
7075}
7176
7277func extractMiddle (str , startMarker , endMarker string ) string {
0 commit comments