Skip to content

Instantly share code, notes, and snippets.

@joseoliv joseoliv/OverrideTest.cyan

Last active Jun 24, 2019
What would you like to do?
package metaobjectTest
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
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'
@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
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)
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
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 {
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.