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

Replace pragma structure #37

Open
wants to merge 6 commits into
base: plcte-2020
Choose a base branch
from
Open
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
@@ -1,9 +1,15 @@
rules
Pragma: aNode with: literal with: values with: anotherLiteral

| exampleName |
(#('exampleNamed:' 'scriptExampleNamed:') anySatisfy: [:prefix | values children first interval contents beginsWith: prefix]) ifTrue: [

|pragmaPrefixes exampleName|
pragmaPrefixes := BPExample subclasses collect: [:aSubclass | aSubclass bpExamplePragmaPrefix asString, ':'].
(pragmaPrefixes anySatisfy: [:prefix | values children first interval contents beginsWith: prefix]) ifTrue: [
exampleName := self value: values children first children first.

self flag: #todo. "As soon as script examples are supported by test serialization, delete condition. jb"
(values children first interval contents beginsWith: BPMethodExample bpExamplePragmaPrefix)
ifTrue: [exampleName := (BPDeserializer deserialize: (Compiler evaluate: exampleName)) exampleName].

annotations add: (BPExampleAnnotation new
exampleName: exampleName;
enclosedExpressionSource: aNode interval contents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ExecutableCode:variables:with:code:" : "pre 5/29/2019 10:51",
"KeywordPragma:with:with:" : "pre 7/23/2019 12:10",
"MethodDeclaration:with:and:and:" : "pre 5/29/2019 10:45",
"Pragma:with:with:with:" : "jb 12/7/2020 18:01",
"Pragma:with:with:with:" : "jb 2/2/2021 20:28",
"Pragmas:pragmas:" : "jb 12/7/2020 18:01",
"defaultExpression:" : "jb 12/7/2020 18:01",
"initialize" : "pre 3/24/2020 09:39",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
building
deserialize: aTest
"Deserializes a given Test into a newly generated Example. Consumer is the method which uses the example"

^ ((self registeredDeserializers collect: [:d | d from: aTest]) detect: [:d | d canDeserialize]) deserialize

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"class" : {
"deserialize:for:" : "pm 1/9/2021 17:09",
"deserialize:" : "jb 2/1/2021 22:42",
"registeredDeserializers" : "jb 1/18/2021 23:23" },
"instance" : {
} }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
initialize-release
initializeFromDeserialized: aBPExample


self
testRef: aBPExample method;
exampleName: aBPExample exampleName.

aBPExample setUpScript ifNotNil: [self setUpScript: aBPExample setUpScript].
aBPExample tearDownScript ifNotNil: [self tearDownScript: aBPExample tearDownScript].
aBPExample expectedResult ifNotNil: [self expectedResult: aBPExample expectedResult].
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
initialize-release
initializeFromPragma: aPragma

"'exampleNamed:' 'active:'? 'self:'? 'setUp:'? 'tearDown:'? 'expectedResult:'? 'with'*"
self
method: aPragma method;
exampleName: aPragma arguments first.
"'testRef:' 'active:'? 'setUp:'? 'tearDown:'? / 'scriptExampleNamed:' 'active:'? 'setUp:'? 'tearDown:'? 'expectedResult:'? 'script:'? "
| serializingMethod |
serializingMethod := Compiler evaluate: aPragma arguments first.
self initializeFromDeserialized: (BPDeserializer deserialize: serializingMethod);
method: aPragma method.

aPragma bpAsDictionary
at: #active ifPresent: [:isActive | self isActive: isActive];
at: #setUp ifPresent: [:newScript | self setUpScript: newScript];
at: #tearDown ifPresent: [:newScript | self tearDownScript: newScript];
at: #expectedResult ifPresent: [:result | self expectedResult: result].
at: #tearDown ifPresent: [:newScript | self tearDownScript: newScript].
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
testRef: aMethodReference

testRef := aMethodReference
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
testRef

^ testRef ifNil: [self testRef: (BPExampleToTestSerializer serialize: self). testRef]
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"ensureTerminatedProcess" : "jb 12/7/2020 18:10",
"exampleName" : "pre 9/30/2020 09:50",
"exampleName:" : "jb 12/7/2020 18:10",
"exampleReference" : "pre 9/30/2020 09:53",
"execute" : "pre 9/30/2020 09:54",
"expectedResult" : "jb 12/7/2020 21:56",
"expectedResult:" : "jb 12/7/2020 21:56",
"hash" : "pre 9/30/2020 09:54",
"initialize" : "pre 1/7/2021 09:33",
"initializeFromDeserialized:" : "jb 2/1/2021 19:58",
"initializeFromMethod:" : "jb 12/3/2020 22:37",
"initializeFromPragma:" : "pre 1/21/2021 16:49",
"initializeFromPragma:" : "jb 2/2/2021 23:51",
"isActive" : "pre 9/30/2020 09:49",
"isActive:" : "pre 10/23/2020 10:16",
"liveSpecimen" : "pre 9/30/2020 10:20",
Expand All @@ -38,6 +38,8 @@
"setUpScript:" : "pre 1/21/2021 15:36",
"tearDownScript" : "pre 1/21/2021 15:36",
"tearDownScript:" : "pre 1/21/2021 15:36",
"testRef" : "jb 2/1/2021 19:14",
"testRef:" : "jb 2/1/2021 18:54",
"toggleIsActive" : "pre 10/23/2020 10:16",
"trace" : "pre 9/30/2020 09:55",
"traceAsyncNotifying:" : "pre 1/15/2021 13:07",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"traceInformation",
"expectedResult",
"setUpScript",
"tearDownScript" ],
"tearDownScript",
"testRef" ],
"name" : "BPExample",
"pools" : [
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ instance creation
newFor: anExample in: aMethodReference

"This is intended for new examples which are not yet serialized in any source code"

^ self new
exampleName: anExample exampleName;
methodReference: aMethodReference;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ui
asMorph

^ self actualExample morphClass new
annotation: self;
example: self actualExample;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"class" : {
"annotationTag" : "pre 7/24/2019 11:05",
"newFor:in:" : "pre 1/6/2021 17:10" },
"newFor:in:" : "jb 2/1/2021 20:35" },
"instance" : {
"actualExample" : "jb 12/7/2020 18:12",
"asMorph" : "pre 9/30/2020 10:41",
"asMorph" : "jb 2/1/2021 23:40",
"canBeAnnotatedTo" : "jb 12/3/2020 22:37",
"enclosedExpressionSource" : "pre 7/23/2019 12:18",
"exampleName" : "pre 7/23/2019 11:56",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
instance-creation
serialize: anExample

(self forExample: anExample) serialize
"Returns the created method."
^ (self forExample: anExample) serialize
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
helper
isGeneratedExampleTest: aMethodName in: aClass

|methodEntry|
methodEntry := self methodEntryFor: aMethodName in: aClass.
self assert: [methodEntry notNil].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
serializing
serialize

| class |
| class methodName |
class := self buildClass.
class compile: (self buildTestForClass: class) classified: (self serializedMethodCategory).
methodName := class compile: (self buildTestForClass: class) classified: (self serializedMethodCategory).
^ (self methodEntryFor: methodName in: class) asString.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ serializedFormOf: aPossibleCodeSnippet

| result |
aPossibleCodeSnippet isSymbol ifTrue: [^ self exampleMethodClassName, ' ' , aPossibleCodeSnippet].
(self example isLiveSpecimenReference: aPossibleCodeSnippet) ifTrue: [^ ''].
result := Compiler evaluate: aPossibleCodeSnippet.
(self example isLiveSpecimenReference: result) ifTrue: [^ (self example resolveLiveSpecimen: result) printString].
^ result isSymbol
ifTrue: [self exampleMethodClassName, ' ' , result]
ifFalse: [aPossibleCodeSnippet]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"class" : {
"canSerialize:" : "jb 1/1/2021 22:55",
"forExample:" : "pm 12/10/2020 10:07",
"serialize:" : "jb 1/2/2021 01:50" },
"serialize:" : "jb 2/1/2021 19:13" },
"instance" : {
"buildClass" : "jb 12/13/2020 22:48",
"buildComment" : "jb 12/13/2020 22:50",
Expand All @@ -16,13 +16,13 @@
"example:" : "jb 1/1/2021 21:31",
"exampleMethodClassName" : "jb 1/1/2021 21:26",
"isExisting:in:" : "jb 1/1/2021 22:53",
"isGeneratedExampleTest:in:" : "pm 1/9/2021 17:46",
"isGeneratedExampleTest:in:" : "jb 2/1/2021 19:03",
"methodEntryFor:in:" : "jb 1/2/2021 00:18",
"serialize" : "jb 1/1/2021 22:54",
"serialize" : "jb 2/1/2021 19:55",
"serializedClassCategory" : "jb 1/2/2021 00:15",
"serializedClassName" : "jb 1/2/2021 00:15",
"serializedExpectedResult" : "jb 1/1/2021 23:44",
"serializedFormOf:" : "jb 1/1/2021 23:42",
"serializedFormOf:" : "jb 2/2/2021 23:52",
"serializedMethodCategory" : "pm 11/30/2020 21:23",
"serializedMethodName" : "jb 12/14/2020 00:35",
"serializedMethodParameters" : "jb 1/1/2021 21:17",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
serialize
serialize: anExample

(self chooseSerializationClassFor: anExample) serialize: anExample
"Returns the created method."
^ (self chooseSerializationClassFor: anExample) serialize: anExample
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"class" : {
"chooseSerializationClassFor:" : "jb 12/13/2020 23:21",
"serializationClasses" : "jb 12/13/2020 23:19",
"serialize:" : "jb 1/1/2021 22:57",
"serialize:" : "jb 2/1/2021 19:13",
"serializeActiveExamples" : "jb 1/1/2021 21:01" },
"instance" : {
} }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
constants
bpExamplePragmaPrefix

^ #exampleNamed
^ #testRef
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
serialization
asPragma

"'exampleNamed:' 'active:'? 'setUp:'? 'tearDown:'? 'self:'? 'expectedResult:'? 'with'*"
^ '<exampleNamed: ''{1}''{2}{3}{4}{5}{6}{7}>' format: {
self exampleName.
"'testRef' 'active:'? 'setUp:'? 'tearDown:'? "
^ '<testRef: ''{1}''{2}{3}{4}>' format: {
self testRef.
self isActive ifFalse: [''] ifTrue: [' active: true'].
self setUpScript ifNil: [''] ifNotNil: [:setUpScript | ' setUp: ' , setUpScript printString].
self tearDownScript ifNil: [''] ifNotNil: [:tearDownScript | ' tearDown: ' , tearDownScript printString].
self receiverConstructor ifNil: [''] ifNotNil: [:aReceiverConstructor | ' self: ' , aReceiverConstructor printString].
self expectedResult ifNil: [''] ifNotNil: [:anExpectedResult | ' expectedResult: ' , anExpectedResult printString].
self argumentScripts ifEmpty: [''] ifNotEmpty: [(self argumentScripts collect: [:anArgumentScript | ' with: ' , anArgumentScript printString]) join]}
self tearDownScript ifNil: [''] ifNotNil: [:tearDownScript | ' tearDown: ' , tearDownScript printString]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
initialize-release
initializeFromDeserialized: aBPExample

super initializeFromDeserialized: aBPExample.

aBPExample receiverConstructor ifNotNil: [ self receiverConstructor: aBPExample receiverConstructor].
aBPExample argumentScripts ifNotNil: [ self argumentScripts: aBPExample argumentScripts].

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"class" : {
"bpExamplePragmaPrefix" : "pre 1/21/2021 15:45" },
"bpExamplePragmaPrefix" : "jb 2/1/2021 19:47" },
"instance" : {
"=" : "pre 1/12/2021 15:22",
"argumentNames" : "pre 8/25/2020 09:41",
"argumentScriptStringAt:" : "pre 7/10/2020 18:23",
"argumentScripts" : "pre 7/23/2019 12:20",
"argumentScripts:" : "pre 7/23/2019 09:23",
"asPragma" : "jb 1/2/2021 19:22",
"asPragma" : "jb 2/2/2021 14:25",
"canBeUsedForDoIts" : "jb 12/3/2020 22:38",
"execute" : "jb 12/3/2020 21:15",
"initialize" : "pre 9/30/2020 09:55",
"initializeFromDeserialized:" : "jb 2/1/2021 18:21",
"initializeFromMethod:" : "jb 12/3/2020 23:18",
"initializeFromPragma:" : "jb 1/2/2021 21:17",
"isLiveSpecimenReference:" : "pre 7/10/2020 18:22",
"liveSpecimen" : "pre 1/22/2021 18:52",
"morphClass" : "pre 9/30/2020 10:40",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
},
"instance" : {
"canDeserialize" : "jb 1/18/2021 23:11",
"deserialize" : "jb 1/18/2021 23:58" } }
"deserialize" : "jb 2/1/2021 22:36" } }
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
building
deserialize

| call |

call := self findStatementWithMessage: #assert:equals:.

^ BPMethodExample new
exampleName: self exampleName;
method: self test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
},
"instance" : {
"canDeserialize" : "pm 1/9/2021 16:10",
"deserialize" : "jb 1/18/2021 23:58",
"deserialize" : "jb 2/1/2021 22:43",
"deserializeExpected:" : "pm 1/9/2021 16:57" } }
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
},
"instance" : {
"canDeserialize" : "pm 1/9/2021 16:10",
"deserialize" : "jb 1/18/2021 23:58",
"deserialize" : "jb 2/1/2021 22:36",
"deserializeException:" : "pm 1/9/2021 16:57",
"getFirstStatementFrom:" : "pm 1/6/2021 13:14" } }
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ asPragma
self isActive ifFalse: [''] ifTrue: [' active: true'].
self setUpScript ifNil: [''] ifNotNil: [:setUpScript | ' setUp: ' , setUpScript printString].
self tearDownScript ifNil: [''] ifNotNil: [:tearDownScript | ' tearDown: ' , tearDownScript printString].
self expectedResult ifNil: [''] ifNotNil: [:anExpectedResult | ' expectedResult: ' , anExpectedResult printString]
script ifNil: [''] ifNotNil: [' script:' , self scriptString]}
self expectedResult ifNil: [''] ifNotNil: [:anExpectedResult | ' expectedResult: ' , anExpectedResult printString].
self script ifNil: [''] ifNotNil: [' script: ' , self scriptString]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
initialize-release
initializeFromDeserialized: aBPExample

super initializeFromDeserialized: aBPExample.

aBPExample script ifNotNil: [ self script: aBPExample script].
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
initialize-release
initializeFromPragma: aPragma

super initializeFromPragma: aPragma.

self flag: #todo. "Do not overwrite this method as soon as script examples are also serialized as tests. jb"
"'scriptExampleNamed:' 'active:'? 'setUp:'? 'tearDown:'? 'expectedResult:'? 'script:'? "
self
method: aPragma method;
exampleName: aPragma arguments first.

aPragma bpAsDictionary
at: #active ifPresent: [:isActive | self isActive: isActive];
at: #setUp ifPresent: [:newScript | self setUpScript: newScript];
at: #tearDown ifPresent: [:newScript | self tearDownScript: newScript];
at: #expectedResult ifPresent: [:newResult | self expectedResult: newResult];
at: #script ifPresent: [:theScript | self script: theScript].
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"class" : {
"bpExamplePragmaPrefix" : "pre 1/21/2021 15:45" },
"bpExamplePragmaPrefix" : "jb 2/2/2021 19:58" },
"instance" : {
"asPragma" : "pre 1/21/2021 16:19",
"initializeFromPragma:" : "pre 1/21/2021 16:06",
"asPragma" : "jb 2/2/2021 20:05",
"initializeFromDeserialized:" : "jb 2/1/2021 18:22",
"initializeFromPragma:" : "jb 2/2/2021 13:49",
"morphClass" : "pre 9/30/2020 10:41",
"run" : "pre 1/21/2021 17:18",
"script" : "pre 9/30/2020 11:00",
Expand Down
Loading