Skip to content

Commit

Permalink
Merge pull request #148 from ba-st/web_origin_improvements
Browse files Browse the repository at this point in the history
Add `WebOrigin>>asWebOrigin` and `WebOrigin>>asUrl`
  • Loading branch information
gcotelli authored Mar 17, 2022
2 parents 0632294 + 0299e9a commit 8b47458
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
36 changes: 35 additions & 1 deletion source/Stargate-Model-Tests/WebOriginTest.class.st
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
Class {
#name : #WebOriginTest,
#superclass : #TestCase,
#category : #'Stargate-Model-Tests-Routing'
#category : #'Stargate-Model-Tests-CORS'
}

{ #category : #tests }
WebOriginTest >> testAsUrl [

| origin |
origin := 'http://example.com/' asWebOrigin.

self assertUrl: origin asUrl equals: 'http://example.com'
]

{ #category : #tests }
WebOriginTest >> testAsWebOrigin [

| origin |
origin := 'http://example.com/' asWebOrigin.

self assert: origin asWebOrigin == origin
]

{ #category : #tests }
WebOriginTest >> testComparing [

Expand All @@ -25,6 +43,22 @@ WebOriginTest >> testComparing [
withMessageText: 'mailto:[email protected] does not comply with a valid origin'
]

{ #category : #tests }
WebOriginTest >> testPrintString [

self
assert: 'http://example.com/' asWebOrigin printString
equals: 'http://example.com';
assert: 'http://example.com:80/' asWebOrigin printString
equals: 'http://example.com';
assert: 'http://example.com/path/file' asWebOrigin printString
equals: 'http://example.com';
assert:
'https://[email protected]:123/forum/questions?id=1'
asWebOrigin printString
equals: 'https://www.example.com:123'
]

{ #category : #tests }
WebOriginTest >> testValidOrigins [

Expand Down
12 changes: 12 additions & 0 deletions source/Stargate-Model/WebOrigin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ WebOrigin >> = aWebOrigin [
^ self asString = aWebOrigin asString
]

{ #category : #converting }
WebOrigin >> asUrl [

^ url copy
]

{ #category : #converting }
WebOrigin >> asWebOrigin [

^ self
]

{ #category : #comparing }
WebOrigin >> hash [

Expand Down

0 comments on commit 8b47458

Please sign in to comment.