From c167c8d916efb6f44e4df6662d227c94fd18cc49 Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Sun, 21 Aug 2022 11:50:42 +0200 Subject: [PATCH 1/2] 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 3e48c6c0b58ea4930fed880fd95570e42e40e10d Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Tue, 23 Aug 2022 11:07:56 +0200 Subject: [PATCH 2/2] 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