63 lines
2.7 KiB
Plaintext
63 lines
2.7 KiB
Plaintext
{% for container in containers %}
|
|
class Mock{{ container.name }}: {{ container.name }}, Cuckoo.Mock {
|
|
typealias MocksType = {{ container.name }}
|
|
typealias Stubbing = __StubbingProxy_{{ container.name }}
|
|
typealias Verification = __VerificationProxy_{{ container.name }}
|
|
let cuckoo_manager = Cuckoo.MockManager()
|
|
|
|
private var observed: {{ container.name }}?
|
|
|
|
func spy(on victim: {{ container.name }}) -> Self {
|
|
observed = victim
|
|
return self
|
|
}
|
|
|
|
{% for property in container.properties %}
|
|
// {{property}}
|
|
{{ property.accessibility }}{% if container.@type == "ClassDeclaration" %} override{% endif %} var {{ property.name }}: {{ property.type }} {
|
|
get {
|
|
return cuckoo_manager.getter("{{ property.name }}", original: observed.map { o in return { () -> {{ property.type }} in o.{{ property.name }} }})
|
|
}
|
|
{% ifnot property.isReadOnly %}
|
|
set {
|
|
cuckoo_manager.setter("{{ property.name }}", value: newValue, original: observed != nil ? { self.observed?.{{ property.name }} = $0 } : nil)
|
|
}
|
|
{% endif %}
|
|
}
|
|
{% endfor %}
|
|
|
|
{% for initializer in container.initializers %}
|
|
// {{initializer}}
|
|
{{ initializer.accessibility }}{% if container.@type == "ClassDeclaration" %} override{% endif %}{% if initializer.@type == "ProtocolMethod" %} required{%endif%} init({{initializer.parameterSignature}}) {
|
|
{% if container.@type == "ClassDeclaration" %}
|
|
super.init({{initializer.call}})
|
|
{% endif %}
|
|
}
|
|
{% endfor %}
|
|
|
|
{% for method in container.methods %}
|
|
// {{method}}
|
|
{{ method.accessibility }}{% if container.@type == "ClassDeclaration" %} override{% endif %} func {{ method.name }}({{ method.parameterSignature }}) {{ method.returnSignature }} {
|
|
{{ method.parameters|openNestedClosure:method.isThrowing }}
|
|
return{% if method.isThrowing %} try{% endif %} cuckoo_manager.call{% if method.isThrowing %}Throws{% endif %}("{{method.fullyQualifiedName}}",
|
|
parameters: ({{method.parameterNames}}),
|
|
original: observed.map { o in
|
|
return { (args){{method.returnSignature}} in
|
|
let ({{ method.parameterNames }}) = args
|
|
{% if method.returnType != "Void" %}return{% endif %}{% if method.isThrowing %} try{% endif %} o.{{method.name}}{%if method.isOptional %}?{%endif%}({{method.call}})
|
|
}
|
|
})
|
|
{{ method.parameters|closeNestedClosure }}
|
|
}
|
|
{% endfor %}
|
|
|
|
{% include "StubbingProxy.swift.stencil" %}
|
|
|
|
{% include "VerificationProxy.swift.stencil" %}
|
|
|
|
}
|
|
|
|
{% include "NopImplStub.swift.stencil" %}
|
|
|
|
{% endfor %}
|