X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
file library
asMethodReturningString: aByteArrayOrString named: aSymbol
"Generates the source of a method named aSymbol that returns aByteArrayOrString as a String.

This implementation answers a String formatted like so

aSymbol
^ aByteArrayOrString

Subclasses need to override this method if the dialect needs changes to support Unicode string literals"
^ String streamContents: [ :stream |
stream
nextPutAll: aSymbol;
nextPut: Character cr.
stream
tab;
nextPutAll: '^ '''.
aByteArrayOrString greaseString do: [ :each |
each = $' ifTrue: [ stream nextPut: $' ].
stream nextPut: each ].
stream nextPut: $' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
encoding
base64Encode: aByteArray
"Base64 encode the given byte array and answer the result as a String."
self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
file library
doSilently: aBlock
"Suspend all notifications value evaluating the given block."
^ aBlock value
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
encoding
base64Encode: aByteArray
^ (Base64MimeConverter mimeEncode: aByteArray readStream) contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
encoding
base64Encode: aByteArray
^ aByteArray base64Encoded
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
encoding
base64Encode: aByteArray
^ (Base64MimeConverter base64Encode: aByteArray readStream) contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
encoding
base64Encode: aByteArray
^ aByteArray base64Encoded
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
encoding
base64Encode: aByteArray
^ aByteArray base64Encoded
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
encoding
base64Encode: aByteArray
^ aByteArray base64Encoded
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
encoding
base64Encode: aByteArray
^ aByteArray base64Encoded
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
running
runCase
GRPlatform current doSilently: [ super runCase ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
private
supportsUnicode
"dynamically try to figure out whether the current dialect supports Unicode"
^ [
String
with: (Character value: 16r1F1F3)
with: (Character value: 16r1F1F1).
true
] on: Error
do: [ :error | false ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests
testBase64Encode
| input |
input := #(
(97 110 121 32 99 97 114 110 97 108 32 112 108 101 97 115 117 114 101 46) 'YW55IGNhcm5hbCBwbGVhc3VyZS4='
(97 110 121 32 99 97 114 110 97 108 32 112 108 101 97 115 117 114 101) 'YW55IGNhcm5hbCBwbGVhc3VyZQ=='
(97 110 121 32 99 97 114 110 97 108 32 112 108 101 97 115 117 114) 'YW55IGNhcm5hbCBwbGVhc3Vy'
(97 110 121 32 99 97 114 110 97 108 32 112 108 101 97 115 117) 'YW55IGNhcm5hbCBwbGVhc3U='
(97 110 121 32 99 97 114 110 97 108 32 112 108 101 97 115) 'YW55IGNhcm5hbCBwbGVhcw==').
1 to: input size by: 2 do: [ :index |
| decoded expected |
decoded := GRPlatform current base64Encode: (input at: index) asByteArray.
expected := input at: index + 1.
self assert: decoded = expected ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tests-file library
testCompileAsciiString
| selector expected source |

self supportsUnicode ifFalse: [
^ self ].

selector := #stringMethod.
expected := 'test ok'.
source := GRPlatform current asMethodReturningString: expected named: selector.
[
| actual |
GRPlatform current compile: source into: self class classified: 'private'.
actual := self perform: selector.
self assert: expected = actual
] ensure: [
GRPlatform current removeSelector: #stringMethod from: self class ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tests-file library
testCompileUnicodeString
| selector expected source |
selector := #stringMethod.
expected := String
with: (Character value: 16r1F1F3)
with: (Character value: 16r1F1F1).
source := GRPlatform current asMethodReturningString: expected named: selector.
[
| actual |
GRPlatform current compile: source into: self class classified: 'private'.
actual := self perform: selector.
self assert: expected = actual
] ensure: [
GRPlatform current removeSelector: #stringMethod from: self class ]
X Tutup