Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the method isValidGlobalName #7533

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Collections-Strings/String.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1874,17 +1874,16 @@ String >> isString [

{ #category : #testing }
String >> isValidGlobalName [

"Answer whether the string receiver can be used as a global name (e.g., name of a class, name of a trait)"
self ifEmpty: [ ^ false ].

"reserverd default names"
self = 'NameOfSubclass' ifTrue: [ ^ false ].
self = 'TNameOfTrait' ifTrue: [ ^ false ].
(#('NameOfSubclass' 'MyClass' 'TNameOfTrait') includes: self) ifTrue: [ ^ false ].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know about this logic. But it's very surprizing. Why we can't have classes with those names? What makes them so special?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be really nice to explain it in the method comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bergel also it should be "reserved" - not "reserverd"


^ (self first isLetter
and: [self first isUppercase])
and: [ self allSatisfy: [:character |
character isAlphaNumeric or: [ character = $_ ]]]
and: [ self first isUppercase])
and: [ self allSatisfy: [ :character |
character isAlphaNumeric or: [ character = $_ ] ] ]
]

{ #category : #testing }
Expand Down
10 changes: 9 additions & 1 deletion src/Kernel-Tests-Extended/ClassTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ ClassTest >> testIsInstanceSide [
self deny: Point class isInstanceSide
]

{ #category : #'tests - class creation' }
ClassTest >> testIsValidGlobalName [
self deny: 'MyClass' isValidGlobalName.
self assert: 'MyCoolSubclass' isValidGlobalName.
self deny: 'MyCool Subclass' isValidGlobalName.
]

{ #category : #'tests - navigation' }
ClassTest >> testMethodsReferencingClass [
self assert: (ClassTest methodsReferencingClass: (Smalltalk classNamed: #ExampleForTest111)) equals: {(ClassTest >> #testOrdersACollectionOfClassesBySuperclass)}.
Expand Down Expand Up @@ -486,5 +493,6 @@ ClassTest >> testclassVariables [

{ #category : #'tests - class creation' }
ClassTest >> unclassifiedCategory [
^#Unclassified

^ #Unclassified
]