SystemOrganization addCategory: #'Refactoring-Tests-Spelling'! TestCase subclass: #RBSpellCheckerTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Spelling'! !RBSpellCheckerTest class methodsFor: 'accessing' stamp: 'lr 1/23/2010 16:46'! packageNamesUnderTest ^ #('Refactoring-Spelling')! ! !RBSpellCheckerTest methodsFor: 'utilities' stamp: 'lr 1/23/2010 16:31'! assert: aSourceString operator: aSelector gives: anExpectedString | result | result := self normalizer perform: aSelector with: aSourceString. self assert: result = anExpectedString description: 'Got ' , result printString , ', but expected ' , anExpectedString printString. result := self normalizer perform: aSelector with: anExpectedString. self assert: result = anExpectedString description: aSelector printString , ' is not idempotent'! ! !RBSpellCheckerTest methodsFor: 'accessing' stamp: 'lr 1/23/2010 16:21'! checker ^ RBSpellChecker default! ! !RBSpellCheckerTest methodsFor: 'accessing' stamp: 'lr 1/23/2010 16:22'! normalizer ^ RBArgumentVariableNamesSpellingRule new! ! !RBSpellCheckerTest methodsFor: 'testing-normalization' stamp: 'lr 1/23/2010 16:34'! testCamelCase self assert: '' operator: #normalizeCamelCase: gives: ''. self assert: 'CamelCase' operator: #normalizeCamelCase: gives: 'Camel Case'. self assert: 'CamelCase123' operator: #normalizeCamelCase: gives: 'Camel Case 123'. self assert: 'Camel00case' operator: #normalizeCamelCase: gives: 'Camel 00 case'. self assert: '0camels' operator: #normalizeCamelCase: gives: '0 camels'. self assert: '2 camels' operator: #normalizeCamelCase: gives: '2 camels'. self assert: '3 Camels' operator: #normalizeCamelCase: gives: '3 Camels'. self assert: 'camelCase' operator: #normalizeCamelCase: gives: 'camel Case'. self assert: 'camel0Case' operator: #normalizeCamelCase: gives: 'camel 0 Case'. self assert: 'camel' operator: #normalizeCamelCase: gives: 'camel'. self assert: 'Camel' operator: #normalizeCamelCase: gives: 'Camel'! ! !RBSpellCheckerTest methodsFor: 'testing' stamp: 'lr 1/23/2010 16:22'! testErrorousSentence | result | result := self checker check: 'This is an engilsh sendence with probles.'. self assert: result isCollection. self assert: result size = 3. self assert: (result includes: 'engilsh'). self assert: (result includes: 'sendence'). self assert: (result includes: 'probles')! ! !RBSpellCheckerTest methodsFor: 'testing-normalization' stamp: 'lr 1/23/2010 16:43'! testIdentifier self assert: nil operator: #normalizeLiteral: gives: 'nil'. self assert: true operator: #normalizeLiteral: gives: 'true'. self assert: false operator: #normalizeLiteral: gives: 'false'. self assert: 123 operator: #normalizeLiteral: gives: '123'. self assert: 123.456 operator: #normalizeLiteral: gives: '123.456'. self assert: $a operator: #normalizeLiteral: gives: 'a'. self assert: 'abcCde' operator: #normalizeLiteral: gives: 'abcCde'. self assert: #(a b c) operator: #normalizeLiteral: gives: 'a b c'. self assert: #[1 2 3] operator: #normalizeLiteral: gives: '1 2 3'! ! !RBSpellCheckerTest methodsFor: 'testing' stamp: 'lr 1/23/2010 16:22'! testPerfectSentence | result | result := self checker check: 'This is an english sentence without problems.'. self assert: result isCollection. self assert: result isEmpty! ! !RBSpellCheckerTest methodsFor: 'testing-normalization' stamp: 'lr 1/23/2010 16:38'! testSelector self assert: '' operator: #normalizeSelector: gives: ''. self assert: '+' operator: #normalizeSelector: gives: '+'. self assert: '==' operator: #normalizeSelector: gives: '=='. self assert: 'negated' operator: #normalizeSelector: gives: 'negated'. self assert: 'negatedValue' operator: #normalizeSelector: gives: 'negated Value'. self assert: 'raisedTo:' operator: #normalizeSelector: gives: 'raised To '. self assert: 'raised:to:' operator: #normalizeSelector: gives: 'raised to '! ! TestCase subclass: #RBSpellingRuleTest instanceVariableNames: 'model environment' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Spelling'! RBSpellingRuleTest class instanceVariableNames: 'classesRun'! !RBSpellingRuleTest commentStamp: 'StanShepherd 1/8/2010 22:15' prior: 0! For each of the spelling rules, I run the rule. I pass the result to the checking method for that rule class. e.g. RBClassCommentsSpellingRule is checked by #classCommentsSpellingRuleCheck:! RBSpellingRuleTest class instanceVariableNames: 'classesRun'! !RBSpellingRuleTest methodsFor: 'accessing' stamp: 'lr 1/24/2010 17:46'! category ^ 'Spelling-Data'! ! !RBSpellingRuleTest methodsFor: 'accessing' stamp: 'lr 1/24/2010 17:46'! categoryWrong ^ 'Spelling-Data-Wrng'! ! !RBSpellingRuleTest methodsFor: 'utilties' stamp: 'lr 1/24/2010 17:46'! defineClass: aSymbol ^ self defineClass: aSymbol category: self category! ! !RBSpellingRuleTest methodsFor: 'utilties' stamp: 'lr 1/23/2010 17:56'! defineClass: aSymbol category: aString | class | model defineClass: 'Object subclass: #' , aSymbol , ' instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: ''' , aString , ''''. class := model classNamed: aSymbol. environment addClass: class; addClass: class theMetaClass. ^ class! ! !RBSpellingRuleTest methodsFor: 'running' stamp: 'lr 1/23/2010 18:04'! runCase SystemChangeNotifier uniqueInstance doSilently: [ super runCase ]! ! !RBSpellingRuleTest methodsFor: 'utilties' stamp: 'lr 1/23/2010 18:03'! runRule: aClass expect: aCollection | rules rule composite undo | rules := RBSpellingRule allSubclasses collect: [ :each | each new ]. rule := rules detect: [ :each | each isKindOf: aClass ] ifNone: [ self error: aClass name , ' is not a spelling rule' ]. composite := RBCompositeLintRule rules: rules name: 'Spelling'. self assert: (rule name isString and: [ rule name notEmpty ]) description: aClass name , ' has no name'. undo := model changes execute. [ SmalllintChecker runRule: composite onEnvironment: environment ] ensure: [ undo execute ]. rules do: [ :each | self assert: (rule = each or: [ each result isEmpty ]) description: rule name , ' should not report errors' ]. rule result searchStrings do: [ :each | self assert: (aCollection includes: each) description: each printString , ' should not be reported' ]. aCollection do: [ :each | self assert: (rule result searchStrings includes: each) description: each printString , ' should be reported' ]. ^ rule result! ! !RBSpellingRuleTest methodsFor: 'running' stamp: 'lr 1/23/2010 17:17'! setUp super setUp. model := RBNamespace new. environment := ClassEnvironment new! ! !RBSpellingRuleTest methodsFor: 'running' stamp: 'lr 1/24/2010 17:46'! tearDown super tearDown. Smalltalk organization removeCategory: self category; removeCategory: self categoryWrong! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/23/2010 17:50'! testArgumentVariableNames | class result | class := self defineClass: #RBSpellingRuleData. class compile: 'wrong: wrng' classified: #(accessing). class compile: 'right: anInteger' classified: #(accessing). result := self runRule: RBArgumentVariableNamesSpellingRule expect: #('wrng'). self assert: (result includesSelector: #wrong: in: class). self deny: (result includesSelector: #right: in: class)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/24/2010 17:47'! testClassCategories | wrong right result | wrong := self defineClass: #RBSpellingRuleDataWrong category: self categoryWrong. right := self defineClass: #RBSpellingRuleDataRight. result := self runRule: RBClassCategoriesSpellingRule expect: #('Wrng'). self assert: (result includesClass: wrong). self deny: (result includesClass: right)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/23/2010 17:49'! testClassComments | wrong right result | wrong := self defineClass: #RBSpellingRuleDataWrong. wrong comment: 'wrng comment'. right := self defineClass: #RBSpellingRuleDataRight. right comment: 'right comment'. result := self runRule: RBClassCommentsSpellingRule expect: #('wrng'). self assert: (result includesClass: wrong). self deny: (result includesClass: right)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/23/2010 17:39'! testClassNames | wrong right result | wrong := self defineClass: #RBSpellingRuleDataWrng. right := self defineClass: #RBSpellingRuleDataRight. result := self runRule: RBClassNamesSpellingRule expect: #('Wrng'). self assert: (result includesClass: wrong). self deny: (result includesClass: right)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/23/2010 17:39'! testClassVariableNames | class result | class := self defineClass: #RBSpellingRuleData. class addClassVariable: 'VariableNameWrng VariableNameRight'. result := self runRule: RBClassVariableNamesSpellingRule expect: #('Wrng'). self assert: (result includesClass: class)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 3/26/2010 08:47'! testInstanceVariableNames | class result | class := self defineClass: #RBSpellingRuleData. class addInstanceVariable: 'instanceNameWrng'; addInstanceVariable: 'instanceNameRight'. class theMetaClass addInstanceVariable: 'classNameWrng'; addInstanceVariable: 'classNameRight'. result := self runRule: RBInstanceVariableNamesSpellingRule expect: #('Wrng'). self assert: (result includesClass: class). self assert: (result includesClass: class theMetaClass)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/23/2010 17:52'! testLiteralValues | class result | class := self defineClass: #RBSpellingRuleData. class compile: 'wrong #wrng' classified: #(accessing). class compile: 'right #right' classified: #(accessing). result := self runRule: RBLiteralValuesSpellingRule expect: #('wrng'). self assert: (result includesSelector: #wrong in: class). self deny: (result includesSelector: #right in: class)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/23/2010 17:53'! testMethodComments | class result | class := self defineClass: #RBSpellingRuleData. class compile: 'wrong "wrng comment"' classified: #(accessing). class compile: 'right "right comment"' classified: #(accessing). result := self runRule: RBMethodCommentsSpellingRule expect: #('wrng'). self assert: (result includesSelector: #wrong in: class). self deny: (result includesSelector: #right in: class)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/23/2010 17:53'! testMethodProtocols | class result | class := self defineClass: #RBSpellingRuleData. class compile: 'wrong' classified: #(wrng). class compile: 'right' classified: #(right). result := self runRule: RBMethodProtocolsSpellingRule expect: #('wrng'). self assert: (result includesSelector: #wrong in: class). self deny: (result includesSelector: #right in: class)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/23/2010 17:54'! testMethodSelectors | class result | class := self defineClass: #RBSpellingRuleData. class compile: 'wrng' classified: #(accessing). class compile: 'right' classified: #(accessing). result := self runRule: RBMethodSelectorsSpellingRule expect: #('wrng'). self assert: (result includesSelector: #wrng in: class). self deny: (result includesSelector: #right in: class)! ! !RBSpellingRuleTest methodsFor: 'tests' stamp: 'lr 1/23/2010 17:55'! testTemporaryVariableNames | class result | class := self defineClass: #RBSpellingRuleData. class compile: 'wrong | wrng |' classified: #(accessing). class compile: 'right | right |' classified: #(accessing). result := self runRule: RBTemporaryVariableNamesSpellingRule expect: #('wrng'). self assert: (result includesSelector: #wrong in: class). self deny: (result includesSelector: #right in: class)! !