Last active
August 30, 2022 12:13
-
-
Save joseoliv/eecfc1850ba7b9aa9dd183f61e2b0fba to your computer and use it in GitHub Desktop.
overrideTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package metaobjectTest | |
@doc{* | |
Annotation 'overrideTest' should be attached to a method. | |
It generates a file with a prototype for testing with | |
the contents of the attached DSL whenever the attached | |
method is overridden in a subprototype. Let us see the details. | |
The following checks are made whenever the method attached | |
to the annotation is overridden in a subprototype. | |
The test file is generated only if one of the following | |
is true: | |
- the subprototype full name (with the package name) | |
or the subprototype name is in the | |
set of the package associated to "overrideTest". A string | |
is associated to a package key using method | |
addToPackageKeyValueSet | |
of class WrCyanPackage_dpp. In practice, just attach annotation | |
'addToSet' to the package in the pyan file: | |
// this is a project file. Its extension is '.pyan' | |
program | |
@addToSet(overrideTest, OverrideTest, "metaobjectTest.OtherProto") | |
package metaobjectTest | |
In this case, test would be generated in prototypes | |
OverrideTest and OtherProto of the current package, which | |
is metaobjectTest (assuming these prototype use annotation 'overrideTest'). | |
- the subprototype package name or the subprototype full name is | |
in the set associated to key "overrideTest". A string | |
is associated to a program key using method | |
addProgramKeyValueSet | |
of class WrProgram_dpp. In practice, just attach annotation | |
'addToSet' to the program in the pyan file: | |
// this is a project file. Its extension is '.pyan' | |
@addToSet(overrideTest, "metaobjectTest.OverrideTest", otherPackage) | |
program | |
If any of the tests above fail, nothing is done. Otherwise, the | |
metaobject replaces all occurrences of the string | |
(%SUBPROTOTYPE%) in the attached DSL with the real subprototype | |
name. Then it creates a file in the same package as the | |
package of this prototype with the text contents. The | |
file is created in directory '--test' of the package. | |
The file name is | |
"OverrideTest_" + FullPrototypeName + "_" + alphaMethodName | |
in which: | |
- operator + concatenates strings | |
- FullPrototypeName is the subprototype name with the package | |
but with '.' replaced by '_' | |
- alphaMethodName is the method name. | |
If the method name is an operator name as '+' or '<=', | |
it is first converted into alphabetic characters. For | |
example, '==' is converted into '_equal_equal'. | |
For example, the name generated by method 'getClientName' of this prototype, | |
in subprototype 'main.SubOverrideTest' is | |
OverrideTest_main_SubOverrideTest_getClientName | |
*} | |
open | |
object OverrideTest | |
/* | |
simulates a bank account. | |
Field 'total' keeps the total amount in the account. | |
Money can be added with 'add:' and withdrawn with 'withdraw:' | |
*/ | |
func init { | |
self._name = "Marcia"; | |
} | |
func run { | |
} | |
@overrideTest{* | |
func test { | |
var (%SUBPROTOTYPE%) subproto = (%SUBPROTOTYPE%) new; | |
var localTotal = subproto getTotal; | |
subproto add: 100; | |
subproto withdraw: 100; | |
assert localTotal == subproto getTotal; | |
} | |
*} | |
func withdraw: Int amount { total = total - amount } | |
func add: Int amount { total = total + amount } | |
func getClientName -> String = "Marcia"; | |
@property var Int total = 0; | |
@property var String _name | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment