From b00facf24af9faa06f1504b87c6e8917b9442bd4 Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Sat, 20 Aug 2022 18:56:37 +0200 Subject: [PATCH 1/6] Add base 64 encoding support --- .../GRPlatform.class/instance/base64Encode..st | 4 ++++ .../instance/base64Encode..st | 3 +++ .../instance/testBase64Encode.st | 14 ++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 repository/Grease-Core.package/GRPlatform.class/instance/base64Encode..st create mode 100644 repository/Grease-Pharo100-Core.package/GRPharoPlatform.class/instance/base64Encode..st create mode 100644 repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testBase64Encode.st diff --git a/repository/Grease-Core.package/GRPlatform.class/instance/base64Encode..st b/repository/Grease-Core.package/GRPlatform.class/instance/base64Encode..st new file mode 100644 index 00000000..1e94d60c --- /dev/null +++ b/repository/Grease-Core.package/GRPlatform.class/instance/base64Encode..st @@ -0,0 +1,4 @@ +encoding +base64Encode: aByteArray + "Base64 encode the given byte array and answer the result as a String." + self subclassResponsibility \ No newline at end of file diff --git a/repository/Grease-Pharo100-Core.package/GRPharoPlatform.class/instance/base64Encode..st b/repository/Grease-Pharo100-Core.package/GRPharoPlatform.class/instance/base64Encode..st new file mode 100644 index 00000000..4cb93d20 --- /dev/null +++ b/repository/Grease-Pharo100-Core.package/GRPharoPlatform.class/instance/base64Encode..st @@ -0,0 +1,3 @@ +encoding +base64Encode: aByteArray + ^ aByteArray base64Encoded \ No newline at end of file diff --git a/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testBase64Encode.st b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testBase64Encode.st new file mode 100644 index 00000000..d1a2b4be --- /dev/null +++ b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testBase64Encode.st @@ -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 ] \ No newline at end of file From 61c4c8db4ccc5d1da24948d709b0438a9d68abe0 Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Thu, 25 Aug 2022 10:31:40 +0200 Subject: [PATCH 2/6] Add more Pharo and Squeak implementations --- .../GRPharoPlatform.class/instance/base64Encode..st | 3 +++ .../GRPharoPlatform.class/instance/base64Encode..st | 3 +++ .../GRPharoPlatform.class/instance/base64Encode..st | 3 +++ .../GRPharoPlatform.class/instance/base64Encode..st | 3 +++ .../GRPharoPlatform.class/instance/base64Encode..st | 3 +++ 5 files changed, 15 insertions(+) create mode 100644 repository/Grease-Pharo60-Core.package/GRPharoPlatform.class/instance/base64Encode..st create mode 100644 repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/base64Encode..st create mode 100644 repository/Grease-Pharo90-Core.package/GRPharoPlatform.class/instance/base64Encode..st create mode 100644 repository/Grease-Squeak5-Core.package/GRPharoPlatform.class/instance/base64Encode..st create mode 100644 repository/Grease-Squeak6-Core.package/GRPharoPlatform.class/instance/base64Encode..st diff --git a/repository/Grease-Pharo60-Core.package/GRPharoPlatform.class/instance/base64Encode..st b/repository/Grease-Pharo60-Core.package/GRPharoPlatform.class/instance/base64Encode..st new file mode 100644 index 00000000..f5e24f05 --- /dev/null +++ b/repository/Grease-Pharo60-Core.package/GRPharoPlatform.class/instance/base64Encode..st @@ -0,0 +1,3 @@ +encoding +base64Encode: aByteArray + ^ (Base64MimeConverter base64Encode: aByteArray readStream) contents diff --git a/repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/base64Encode..st b/repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/base64Encode..st new file mode 100644 index 00000000..4cb93d20 --- /dev/null +++ b/repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/base64Encode..st @@ -0,0 +1,3 @@ +encoding +base64Encode: aByteArray + ^ aByteArray base64Encoded \ No newline at end of file diff --git a/repository/Grease-Pharo90-Core.package/GRPharoPlatform.class/instance/base64Encode..st b/repository/Grease-Pharo90-Core.package/GRPharoPlatform.class/instance/base64Encode..st new file mode 100644 index 00000000..4cb93d20 --- /dev/null +++ b/repository/Grease-Pharo90-Core.package/GRPharoPlatform.class/instance/base64Encode..st @@ -0,0 +1,3 @@ +encoding +base64Encode: aByteArray + ^ aByteArray base64Encoded \ No newline at end of file diff --git a/repository/Grease-Squeak5-Core.package/GRPharoPlatform.class/instance/base64Encode..st b/repository/Grease-Squeak5-Core.package/GRPharoPlatform.class/instance/base64Encode..st new file mode 100644 index 00000000..4cb93d20 --- /dev/null +++ b/repository/Grease-Squeak5-Core.package/GRPharoPlatform.class/instance/base64Encode..st @@ -0,0 +1,3 @@ +encoding +base64Encode: aByteArray + ^ aByteArray base64Encoded \ No newline at end of file diff --git a/repository/Grease-Squeak6-Core.package/GRPharoPlatform.class/instance/base64Encode..st b/repository/Grease-Squeak6-Core.package/GRPharoPlatform.class/instance/base64Encode..st new file mode 100644 index 00000000..4cb93d20 --- /dev/null +++ b/repository/Grease-Squeak6-Core.package/GRPharoPlatform.class/instance/base64Encode..st @@ -0,0 +1,3 @@ +encoding +base64Encode: aByteArray + ^ aByteArray base64Encoded \ No newline at end of file From a0cbf948e9d38983c7e8d86ec77b8d1103eeebbe Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Sun, 21 Aug 2022 11:50:42 +0200 Subject: [PATCH 3/6] Add #asMethodReturningString:named: Fixes #141 --- .../asMethodReturningString.named..st | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 repository/Grease-Core.package/GRPlatform.class/instance/asMethodReturningString.named..st diff --git a/repository/Grease-Core.package/GRPlatform.class/instance/asMethodReturningString.named..st b/repository/Grease-Core.package/GRPlatform.class/instance/asMethodReturningString.named..st new file mode 100644 index 00000000..364e0bf1 --- /dev/null +++ b/repository/Grease-Core.package/GRPlatform.class/instance/asMethodReturningString.named..st @@ -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: $' ] \ No newline at end of file From d05db984fe498e717e987a12a15db7b4e1f5de0e Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Tue, 23 Aug 2022 11:07:56 +0200 Subject: [PATCH 4/6] Add unit tests for string methods --- .../GRPlatform.class/instance/doSilently..st | 4 ++++ .../GRPlatformTest.class/instance/runCase.st | 3 +++ .../instance/supportsUnicode.st | 10 ++++++++++ .../instance/testCompileAsciiString.st | 17 +++++++++++++++++ .../instance/testCompileUnicodeString.st | 15 +++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 repository/Grease-Core.package/GRPlatform.class/instance/doSilently..st create mode 100644 repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/runCase.st create mode 100644 repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/supportsUnicode.st create mode 100644 repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testCompileAsciiString.st create mode 100644 repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testCompileUnicodeString.st diff --git a/repository/Grease-Core.package/GRPlatform.class/instance/doSilently..st b/repository/Grease-Core.package/GRPlatform.class/instance/doSilently..st new file mode 100644 index 00000000..89a96f47 --- /dev/null +++ b/repository/Grease-Core.package/GRPlatform.class/instance/doSilently..st @@ -0,0 +1,4 @@ +file library +doSilently: aBlock + "Suspend all notifications value evaluating the given block." + ^ aBlock value \ No newline at end of file diff --git a/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/runCase.st b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/runCase.st new file mode 100644 index 00000000..9465625f --- /dev/null +++ b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/runCase.st @@ -0,0 +1,3 @@ +running +runCase + GRPlatform current doSilently: [ super runCase ] \ No newline at end of file diff --git a/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/supportsUnicode.st b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/supportsUnicode.st new file mode 100644 index 00000000..a22719d9 --- /dev/null +++ b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/supportsUnicode.st @@ -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 ] \ No newline at end of file diff --git a/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testCompileAsciiString.st b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testCompileAsciiString.st new file mode 100644 index 00000000..cfe0c3ff --- /dev/null +++ b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testCompileAsciiString.st @@ -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 ] \ No newline at end of file diff --git a/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testCompileUnicodeString.st b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testCompileUnicodeString.st new file mode 100644 index 00000000..a02b1ac5 --- /dev/null +++ b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testCompileUnicodeString.st @@ -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 ] \ No newline at end of file From 6c7f37d9e6909fde572d03ac63db0f19c8334bb5 Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Fri, 26 Aug 2022 11:31:41 +0200 Subject: [PATCH 5/6] Add GemStone implementation --- .../GRGemStonePlatform.class/instance/base64Encode..st | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 repository/Grease-GemStone-Core.package/GRGemStonePlatform.class/instance/base64Encode..st diff --git a/repository/Grease-GemStone-Core.package/GRGemStonePlatform.class/instance/base64Encode..st b/repository/Grease-GemStone-Core.package/GRGemStonePlatform.class/instance/base64Encode..st new file mode 100644 index 00000000..f5e24f05 --- /dev/null +++ b/repository/Grease-GemStone-Core.package/GRGemStonePlatform.class/instance/base64Encode..st @@ -0,0 +1,3 @@ +encoding +base64Encode: aByteArray + ^ (Base64MimeConverter base64Encode: aByteArray readStream) contents From 6106bc7bef7e34e0b6d62acaab7c833434a6068b Mon Sep 17 00:00:00 2001 From: Johan Brichau Date: Fri, 26 Aug 2022 13:40:08 +0200 Subject: [PATCH 6/6] correct gemstone implementation of base64Encode --- .../GRGemStonePlatform.class/instance/base64Encode..st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/Grease-GemStone-Core.package/GRGemStonePlatform.class/instance/base64Encode..st b/repository/Grease-GemStone-Core.package/GRGemStonePlatform.class/instance/base64Encode..st index f5e24f05..4a3631f8 100644 --- a/repository/Grease-GemStone-Core.package/GRGemStonePlatform.class/instance/base64Encode..st +++ b/repository/Grease-GemStone-Core.package/GRGemStonePlatform.class/instance/base64Encode..st @@ -1,3 +1,3 @@ encoding base64Encode: aByteArray - ^ (Base64MimeConverter base64Encode: aByteArray readStream) contents + ^ (Base64MimeConverter mimeEncode: aByteArray readStream) contents