diff --git a/src/BaselineOfGitLabHealth/BaselineOfGitLabHealth.class.st b/src/BaselineOfGitLabHealth/BaselineOfGitLabHealth.class.st index 32743e9..97122f3 100644 --- a/src/BaselineOfGitLabHealth/BaselineOfGitLabHealth.class.st +++ b/src/BaselineOfGitLabHealth/BaselineOfGitLabHealth.class.st @@ -1,10 +1,11 @@ Class { - #name : #BaselineOfGitLabHealth, - #superclass : #BaselineOf, - #category : #BaselineOfGitLabHealth + #name : 'BaselineOfGitLabHealth', + #superclass : 'BaselineOf', + #category : 'BaselineOfGitLabHealth', + #package : 'BaselineOfGitLabHealth' } -{ #category : #baselines } +{ #category : 'baselines' } BaselineOfGitLabHealth >> baseline: spec [ @@ -21,14 +22,14 @@ BaselineOfGitLabHealth >> baseline: spec [ spec package: 'GitLabHealth-Model' with: [ spec requires: #( 'Moose' ) ] ] ] ] -{ #category : #baselines } +{ #category : 'baselines' } BaselineOfGitLabHealth >> customProjectAttributes [ self class environment at: #MooseEntity ifAbsent: [ ^ #(#WithoutFamix) ]. ^ #() ] -{ #category : #baselines } +{ #category : 'baselines' } BaselineOfGitLabHealth >> defineDependencies: spec [ spec @@ -39,11 +40,11 @@ BaselineOfGitLabHealth >> defineDependencies: spec [ with: [ spec repository: 'github://badetitou/MoreLogger:main/src' ] ] -{ #category : #baselines } +{ #category : 'baselines' } BaselineOfGitLabHealth >> defineGroups: spec [ ] -{ #category : #baselines } +{ #category : 'baselines' } BaselineOfGitLabHealth >> definePackages: spec [ spec @@ -72,6 +73,8 @@ BaselineOfGitLabHealth >> definePackages: spec [ package: 'GLPHExtended-Model' with: [ spec requires: #( 'GitLabHealth-Model' 'GitLabHealth-Model-Extension' ) ]; + package: 'GLPHExtended-Model-Tests' + with: [ spec requires: #( 'GLPHExtended-Model' ) ]; package: 'GLPHExtended-Model-Extension' with: [ spec requires: #( 'GLPHExtended-Model' 'GitLabHealth-Model' 'GitLabHealth-Model-Extension' ) ]; diff --git a/src/BaselineOfGitLabHealth/package.st b/src/BaselineOfGitLabHealth/package.st index 1aeec40..0d5dae3 100644 --- a/src/BaselineOfGitLabHealth/package.st +++ b/src/BaselineOfGitLabHealth/package.st @@ -1 +1 @@ -Package { #name : #BaselineOfGitLabHealth } +Package { #name : 'BaselineOfGitLabHealth' } diff --git a/src/GLPHExtended-Model-Extension/GLPHEChange.extension.st b/src/GLPHExtended-Model-Extension/GLPHEChange.extension.st index d3a8f24..cca9465 100644 --- a/src/GLPHExtended-Model-Extension/GLPHEChange.extension.st +++ b/src/GLPHExtended-Model-Extension/GLPHEChange.extension.st @@ -37,17 +37,20 @@ GLPHEChange >> name [ GLPHEChange class >> newFrom: aDiffLine [ "Factory a Change from a loc" - | aChange code| - aChange := GLPHELineOfCode new. - + | aChange trimedLine code | + trimedLine := aDiffLine trim. + + aChange := (trimedLine beginsWith: #+) + ifTrue: [ GLPHEAddition new ] + ifFalse: [ + (aDiffLine trim beginsWith: #-) + ifTrue: [ GLPHEDeletion new ] + ifFalse: [ GLPHELineOfCode new ] ]. + code := aDiffLine. - (aDiffLine beginsWith: #'@@') ifTrue: [ - code := (aDiffLine splitOn: '@@') copyWithoutFirst second. - ]. - (aDiffLine trim beginsWith: #+) ifTrue: [ aChange := GLPHEAddition new. ]. - (aDiffLine trim beginsWith: #-) ifTrue: [ aChange := GLPHEDeletion new. ]. - + (trimedLine beginsWith: #'@@') ifTrue: [ + code := (trimedLine splitOn: '@@') copyWithoutFirst second ]. aChange sourceCode: code. - + ^ aChange ] diff --git a/src/GLPHExtended-Model-Extension/GLPHEDiffRange.extension.st b/src/GLPHExtended-Model-Extension/GLPHEDiffRange.extension.st index 712e717..b8a8260 100644 --- a/src/GLPHExtended-Model-Extension/GLPHEDiffRange.extension.st +++ b/src/GLPHExtended-Model-Extension/GLPHEDiffRange.extension.st @@ -8,12 +8,13 @@ GLPHEDiffRange >> name [ { #category : #'*GLPHExtended-Model-Extension' } GLPHEDiffRange class >> newFrom: aLine [ - |range infos rangesInfo | - range := GLPHEDiffRange new. - infos := (aLine splitOn: '@@') copyWithoutFirst. - rangesInfo := infos first trim splitOn: ' '. + + | range infos rangesInfo | + range := GLPHEDiffRange new. + infos := (aLine splitOn: '@@') second. + rangesInfo := infos trim splitOn: ' '. range originalLineRange: rangesInfo first. - range newLineRange: rangesInfo second . - -^ range. + range newLineRange: rangesInfo second. + + ^ range ] diff --git a/src/GLPHExtended-Model-Tests/GLPHEChangeTest.class.st b/src/GLPHExtended-Model-Tests/GLPHEChangeTest.class.st new file mode 100644 index 0000000..d2bad1c --- /dev/null +++ b/src/GLPHExtended-Model-Tests/GLPHEChangeTest.class.st @@ -0,0 +1,35 @@ +" +A GLPHEChangeTest is a test class for testing the behavior of GLPHEChange +" +Class { + #name : #GLPHEChangeTest, + #superclass : #TestCase, + #category : #'GLPHExtended-Model-Tests-Entities' +} + +{ #category : #tests } +GLPHEChangeTest >> testNewEntityFromString [ + + | change | + change := GLPHEChange newFrom: '+ helloWorld'. + self assert: change class equals: GLPHEAddition. + self assert: change sourceCode equals: '+ helloWorld' +] + +{ #category : #tests } +GLPHEChangeTest >> testNewEntityFromStringDeletion [ + + | change | + change := GLPHEChange newFrom: '- helloWorld'. + self assert: change class equals: GLPHEDeletion. + self assert: change sourceCode equals: '- helloWorld' +] + +{ #category : #tests } +GLPHEChangeTest >> testNewEntityFromStringLOC [ + + | change | + change := GLPHEChange newFrom: 'helloWorld'. + self assert: change class equals: GLPHELineOfCode. + self assert: change sourceCode equals: 'helloWorld' +] diff --git a/src/GLPHExtended-Model-Tests/GLPHEDiffRangeTest.class.st b/src/GLPHExtended-Model-Tests/GLPHEDiffRangeTest.class.st new file mode 100644 index 0000000..d23b54e --- /dev/null +++ b/src/GLPHExtended-Model-Tests/GLPHEDiffRangeTest.class.st @@ -0,0 +1,28 @@ +" +A GLPHEDiffRangeTest is a test class for testing the behavior of GLPHEDiffRange +" +Class { + #name : #GLPHEDiffRangeTest, + #superclass : #TestCase, + #category : 'GLPHExtended-Model-Tests-Entities' +} + +{ #category : #tests } +GLPHEDiffRangeTest >> testNewEntityFromString [ + + | diffRange | + diffRange := GLPHEDiffRange newFrom: + '@@ -15,9 +15,9 @@ LLMModifierTest >> testGetViolationsMessage ['. + self assert: diffRange originalLineRange equals: '-15,9'. + self assert: diffRange newLineRange equals: '+15,9' +] + +{ #category : #tests } +GLPHEDiffRangeTest >> testNewEntityFromStringWithDifferentValues [ + + | diffRange | + diffRange := GLPHEDiffRange newFrom: + '@@ -15,7 +15,8 @@ LLMModifier >> getViolationsMessage: violations ['. + self assert: diffRange originalLineRange equals: '-15,7'. + self assert: diffRange newLineRange equals: '+15,8' +] diff --git a/src/GLPHExtended-Model-Tests/package.st b/src/GLPHExtended-Model-Tests/package.st new file mode 100644 index 0000000..cfde6b0 --- /dev/null +++ b/src/GLPHExtended-Model-Tests/package.st @@ -0,0 +1 @@ +Package { #name : #'GLPHExtended-Model-Tests' } diff --git a/src/GitLabHealth-Model-Extension-Tests/GLHExtensionTest.class.st b/src/GitLabHealth-Model-Extension-Tests/GLHExtensionTest.class.st index 374537a..072afe0 100644 --- a/src/GitLabHealth-Model-Extension-Tests/GLHExtensionTest.class.st +++ b/src/GitLabHealth-Model-Extension-Tests/GLHExtensionTest.class.st @@ -71,3 +71,83 @@ GLHExtensionTest >> testAddAllOfTypeUnlessWithAlreadyExistingEntity [ self assert: (values includes: user). self assert: (values includes: alreadyExistingUser) ] + +{ #category : #tests } +GLHExtensionTest >> testAddAllUnless [ + + | col | + col := OrderedCollection new. + col addAll: { 12 } unless: [ :a :b | a = b ]. + self assert: col size equals: 1. + self assert: col first equals: 12 +] + +{ #category : #tests } +GLHExtensionTest >> testAddAllUnlessIntersectionOfUsers [ + + | col result user1 user2 user3 user2b user3b user4 | + user1 := GLHUser new. + user1 id: 1. + user2 := GLHUser new. + user2 id: 2. + user3 := GLHUser new. + user3 id: 3. + col := OrderedCollection new. + col + addAll: { + user1. + user2. + user3 } + unless: [ :a :b | a id = b id ]. + self assert: col size equals: 3. + user2b := GLHUser new. + user2b id: 2. + user3b := GLHUser new. + user3b id: 3. + user4 := GLHUser new. + user4 id: 4. + + result := col + addAll: { + user2b. + user3b. + user4 } + unless: [ :a :b | a id = b id ]. + self assert: col size equals: 4. + self assert: result size equals: 3. + self assert: (result includes: user2). + self assert: (result includes: user3). + self assert: (result includes: user4) +] + +{ #category : #tests } +GLHExtensionTest >> testAddAllUnlessTwiceEqualityIsTheSameButNotObject [ + + | col user result userB | + user := GLHUser new. + user id: 12. + col := OrderedCollection new. + col addAll: { user } unless: [ :a :b | a id = b id ]. + self assert: col size equals: 1. + self assert: col first identicalTo: user. + userB := GLHUser new. + userB id: 12. + result := col addAll: { userB } unless: [ :a :b | a id = b id ]. + self assert: col size equals: 1. + self assert: result first identicalTo: user +] + +{ #category : #tests } +GLHExtensionTest >> testAddAllUnlessTwiceTheSame [ + + | col user result | + user := GLHUser new. + user id: 12. + col := OrderedCollection new. + col addAll: { user } unless: [ :a :b | a = b ]. + self assert: col size equals: 1. + self assert: col first identicalTo: user. + result := col addAll: { user } unless: [ :a :b | a = b ]. + self assert: col size equals: 1. + self assert: result first identicalTo: user +] diff --git a/src/GitLabHealth-Model-Extension/OrderedCollection.extension.st b/src/GitLabHealth-Model-Extension/OrderedCollection.extension.st index 0754d75..db53bb8 100644 --- a/src/GitLabHealth-Model-Extension/OrderedCollection.extension.st +++ b/src/GitLabHealth-Model-Extension/OrderedCollection.extension.st @@ -9,16 +9,20 @@ OrderedCollection >> add: anElmt unless: aConditionAsBlock [ { #category : #'*GitLabHealth-Model-Extension' } OrderedCollection >> addAll: anElmtCollection unless: aConditionAsBlock [ - "()>>>" - |addedElements| - - addedElements := (anElmtCollection reject: [ :anElmt | - self anySatisfy: [ :existingElmt | - aConditionAsBlock value: existingElmt value: anElmt ] ]). - - self addAll: addedElements. - - ^ (self select: [ :existingElmt | - anElmtCollection anySatisfy: [ :anElmt | - aConditionAsBlock value: anElmt value: existingElmt ] ]). + + | returnCollection | + "Create same kind of collection" + returnCollection := self species new. + "For each element of this collection" + + anElmtCollection do: [ :anElmt | + self + detect: [ :existingElmt | + aConditionAsBlock value: existingElmt value: anElmt ] + ifFound: [ :el | returnCollection add: el ] + ifNone: [ + returnCollection add: anElmt. + self add: anElmt ] ]. + + ^ returnCollection ]