Skip to content

Commit

Permalink
Merge branch 'release/v0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
valnoc committed Nov 5, 2018
2 parents b644fc0 + 2643c2e commit 610e12d
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 63 deletions.
14 changes: 5 additions & 9 deletions FataMorgana.podspec
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#
# Be sure to run `pod lib lint MyLib.podspec' to ensure this is a
# valid spec and remove all comments before submitting the spec.
#
# Any lines starting with a # are optional, but encouraged
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = "FataMorgana"
s.version = "0.3.0"
s.version = "0.4.0"
s.summary = "FataMorgana generates mocks using Mirage library."
s.description = <<-DESC
FataMorgana generates mocks using Mirage library.
It uses Sourcery as a code generator and provides several templates and annotations.
v0.4.0
- added variables for classes
- fixed "any" names of generic functions
v0.3.0
- added variables for protocols
- fixed methods duplication with class inheritance/implementation
Expand Down
15 changes: 10 additions & 5 deletions Template/Mock.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import Mirage
{% endmacro %}

{# === ANY === #}
{% macro callAnyOther type %}any{{ type|replace:"?","" }}(){% endmacro %}
{% macro callAnyOther type %}any{{ type|replace:"?",""|replace:"<",""|replace:">","" |replace:".","" }}(){% endmacro %}

{% macro callAnyArray type %}{#
#}{% if argument.returnEmptyArray %}{#
#}[]{#
#}{% else %}{#
#}any{{ type|replace:"?",""|replace:"[",""|replace:"]","" }}Array(){#
#}any{{ type|replace:"?",""|replace:"[",""|replace:"]",""|replace:"<",""|replace:">","" |replace:".","" }}Array(){#
#}{% endif %}{#
#}{% endmacro %}

{% macro callAnyDict type %}{#
#}{% if argument.returnEmptyDict %}{#
#}[:]{#
#}{% else %}{#
#}any{{ type|replace:"?",""|replace:"[",""|replace:"]",""|replace:":",""|replace:" ","" }}Dict(){#
#}any{{ type|replace:"?",""|replace:"[",""|replace:"]",""|replace:":",""|replace:" ","" |replace:"<",""|replace:">","" |replace:".","" }}Dict(){#
#}{% endif %}{#
#}{% endmacro %}

Expand Down Expand Up @@ -101,13 +101,15 @@ import Mirage
#}{% endmacro %}

{# mock #}
{% macro printOverride method %}{% if method.definedInType.kind == "class" %}override {% endif %}{% endmacro %}

{% macro generateMockVar var %}
{% set varSelGet %}{% call getVarSelGet var %}{% endset %}
{% set varSelSet %}{% call getVarSelSet var %}{% endset %}
{##}
let {{ varSelGet }} = "{{ varSelGet }}"
let {{ varSelSet }} = "{{ varSelSet }}"
var {{ var.name}}: {{ var.typeName }} {
{% call printOverride var %}var {{ var.name}}: {{ var.typeName }} {
get { return mockManager.handle({{ varSelGet }}, withDefaultReturnValue: {% call callAny var.typeName %}, withArgs:nil) as{%if var.isOptional%}?{%else%}!{%endif%} {{ var.typeName|replace:"?","" }} }
{% if var.writeAccess != "" and var.writeAccess != "fileprivate" %}
set(value) { mockManager.handle({{ varSelSet }}, withDefaultReturnValue: nil, withArgs:value) }
Expand Down Expand Up @@ -176,10 +178,13 @@ class Mock{{ type.name }}: {{ type.name }}, Mock {
}

//MARK: - Mock{{ type.name }}
{% for var in type.allVariables|!definedInExtension|!annotated:"mirageSkip" %}
{% call generateMockVar var %}
{% endfor %}

{% for method in type.methods|!definedInExtension|!annotated:"mirageSkip" %}
{% if not method.isInitializer and not method.isDeinitializer and not method.accessLevel == "fileprivate" %}
{% call generateMockMethod method %}

{% endif %}
{% endfor %}
}
Expand Down
1 change: 0 additions & 1 deletion example/.sourcery.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sources:
- ./FataExample/Services/
- ./FataExample/Objects/
templates:
- ./../Template/
output:
Expand Down
2 changes: 1 addition & 1 deletion example/FataExample/Services/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protocol Service {
func methodTwoArgsArrDict(arg1: [String], arg2: [String: String])
func methodTwoArgsArrDictOpt(arg1: [String]?, arg2: [String: String]?)

func methodClosureNamed(closure: Closure1)
func methodClosureNamed(closure: @escaping Closure1)
func methodClosureNoName(_ closure: @escaping Closure1)
func methodClosureLabel(bestClosure closure: @escaping Closure1) -> Closure1

Expand Down
2 changes: 1 addition & 1 deletion example/FataExample/Services/Service2Impl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Service2Impl: Service2 {

func methodTwoArgsArrDictOpt(arg1: [String]?, arg2: [String : String]?) { }

func methodClosureNamed(closure: () -> Void) { }
func methodClosureNamed(closure: @escaping () -> Void) { }

func methodClosureNoName(_ closure: @escaping Closure1) { }

Expand Down
2 changes: 1 addition & 1 deletion example/FataExample/Services/ServiceImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ServiceImpl: Service {

func methodTwoArgsArrDictOpt(arg1: [String]?, arg2: [String : String]?) { }

func methodClosureNamed(closure: () -> Void) { }
func methodClosureNamed(closure: @escaping Closure1) { }

func methodClosureNoName(_ closure: @escaping Closure1) { }

Expand Down
2 changes: 1 addition & 1 deletion example/FataExampleTests/mocks/MockService.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class MockService: Service, Mock {
}

let sel_methodClosureNamed = "sel_methodClosureNamed"
func methodClosureNamed(closure: Closure1) {
func methodClosureNamed(closure: @escaping Closure1) {
mockManager.handle(sel_methodClosureNamed, withDefaultReturnValue: nil, withArgs: closure)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class MockService2: Service2, Mock {
}

let sel_methodClosureNamed = "sel_methodClosureNamed"
func methodClosureNamed(closure: Closure1) {
func methodClosureNamed(closure: @escaping Closure1) {
mockManager.handle(sel_methodClosureNamed, withDefaultReturnValue: nil, withArgs: closure)
}

Expand Down
105 changes: 84 additions & 21 deletions example/FataExampleTests/mocks/MockService2Impl.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,104 +62,167 @@ class MockService2Impl: Service2Impl, Mock {
}
}
//MARK: - MockService2Impl
let sel_get_varvarOne = "sel_get_varvarOne"
let sel_set_varvarOne = "sel_set_varvarOne"
override var varvarOne: String {
get { return mockManager.handle(sel_get_varvarOne, withDefaultReturnValue: anyString(), withArgs:nil) as! String }
set(value) { mockManager.handle(sel_set_varvarOne, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varOne = "sel_get_varOne"
let sel_set_varOne = "sel_set_varOne"
override var varOne: String {
get { return mockManager.handle(sel_get_varOne, withDefaultReturnValue: anyString(), withArgs:nil) as! String }
set(value) { mockManager.handle(sel_set_varOne, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varOpt = "sel_get_varOpt"
let sel_set_varOpt = "sel_set_varOpt"
override var varOpt: String? {
get { return mockManager.handle(sel_get_varOpt, withDefaultReturnValue: anyString(), withArgs:nil) as? String }
set(value) { mockManager.handle(sel_set_varOpt, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varArr = "sel_get_varArr"
let sel_set_varArr = "sel_set_varArr"
override var varArr: [String] {
get { return mockManager.handle(sel_get_varArr, withDefaultReturnValue: anyStringArray(), withArgs:nil) as! [String] }
set(value) { mockManager.handle(sel_set_varArr, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varArrOpt = "sel_get_varArrOpt"
let sel_set_varArrOpt = "sel_set_varArrOpt"
override var varArrOpt: [String]? {
get { return mockManager.handle(sel_get_varArrOpt, withDefaultReturnValue: anyStringArray(), withArgs:nil) as? [String] }
set(value) { mockManager.handle(sel_set_varArrOpt, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varDict = "sel_get_varDict"
let sel_set_varDict = "sel_set_varDict"
override var varDict: [String : String] {
get { return mockManager.handle(sel_get_varDict, withDefaultReturnValue: anyStringStringDict(), withArgs:nil) as! [String : String] }
set(value) { mockManager.handle(sel_set_varDict, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varDictOpt = "sel_get_varDictOpt"
let sel_set_varDictOpt = "sel_set_varDictOpt"
override var varDictOpt: [String : String]? {
get { return mockManager.handle(sel_get_varDictOpt, withDefaultReturnValue: anyStringStringDict(), withArgs:nil) as? [String : String] }
set(value) { mockManager.handle(sel_set_varDictOpt, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varGetter = "sel_get_varGetter"
let sel_set_varGetter = "sel_set_varGetter"
override var varGetter: String {
get { return mockManager.handle(sel_get_varGetter, withDefaultReturnValue: anyString(), withArgs:nil) as! String }
set(value) { mockManager.handle(sel_set_varGetter, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varGetter2 = "sel_get_varGetter2"
let sel_set_varGetter2 = "sel_set_varGetter2"
override var varGetter2: String {
get { return mockManager.handle(sel_get_varGetter2, withDefaultReturnValue: anyString(), withArgs:nil) as! String }
}
let sel_get_varGetter3 = "sel_get_varGetter3"
let sel_set_varGetter3 = "sel_set_varGetter3"
override var varGetter3: String {
get { return mockManager.handle(sel_get_varGetter3, withDefaultReturnValue: anyString(), withArgs:nil) as! String }
}
let sel_get_varGetterOpt = "sel_get_varGetterOpt"
let sel_set_varGetterOpt = "sel_set_varGetterOpt"
override var varGetterOpt: String {
get { return mockManager.handle(sel_get_varGetterOpt, withDefaultReturnValue: anyString(), withArgs:nil) as! String }
set(value) { mockManager.handle(sel_set_varGetterOpt, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varClosure = "sel_get_varClosure"
let sel_set_varClosure = "sel_set_varClosure"
override var varClosure: Closure1 {
get { return mockManager.handle(sel_get_varClosure, withDefaultReturnValue: anyClosure1(), withArgs:nil) as! Closure1 }
set(value) { mockManager.handle(sel_set_varClosure, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varClosureOpt = "sel_get_varClosureOpt"
let sel_set_varClosureOpt = "sel_set_varClosureOpt"
override var varClosureOpt: Closure1? {
get { return mockManager.handle(sel_get_varClosureOpt, withDefaultReturnValue: anyClosure1(), withArgs:nil) as? Closure1 }
set(value) { mockManager.handle(sel_set_varClosureOpt, withDefaultReturnValue: nil, withArgs:value) }
}
let sel_get_varClosureOptGetter = "sel_get_varClosureOptGetter"
let sel_set_varClosureOptGetter = "sel_set_varClosureOptGetter"
override var varClosureOptGetter: Closure1? {
get { return mockManager.handle(sel_get_varClosureOptGetter, withDefaultReturnValue: anyClosure1(), withArgs:nil) as? Closure1 }
set(value) { mockManager.handle(sel_set_varClosureOptGetter, withDefaultReturnValue: nil, withArgs:value) }
}

let sel_methodVoidVoid = "sel_methodVoidVoid"
override func methodVoidVoid() {
mockManager.handle(sel_methodVoidVoid, withDefaultReturnValue: nil, withArgs: nil)
}

let sel_methodVoid = "sel_methodVoid"
override func methodVoid() {
mockManager.handle(sel_methodVoid, withDefaultReturnValue: nil, withArgs: nil)
}

let sel_methodReturnsOne = "sel_methodReturnsOne"
override func methodReturnsOne() -> String {
return mockManager.handle(sel_methodReturnsOne, withDefaultReturnValue: anyString(), withArgs: nil) as! String
}

let sel_methodReturnsOneOpt = "sel_methodReturnsOneOpt"
override func methodReturnsOneOpt() -> String? {
return mockManager.handle(sel_methodReturnsOneOpt, withDefaultReturnValue: anyString(), withArgs: nil) as? String
}

let sel_methodReturnsArray = "sel_methodReturnsArray"
override func methodReturnsArray() -> [String] {
return mockManager.handle(sel_methodReturnsArray, withDefaultReturnValue: anyStringArray(), withArgs: nil) as! [String]
}

let sel_methodReturnsArrayOpt = "sel_methodReturnsArrayOpt"
override func methodReturnsArrayOpt() -> [String]? {
return mockManager.handle(sel_methodReturnsArrayOpt, withDefaultReturnValue: anyStringArray(), withArgs: nil) as? [String]
}

let sel_methodReturnsDict = "sel_methodReturnsDict"
override func methodReturnsDict() -> [String : String] {
return mockManager.handle(sel_methodReturnsDict, withDefaultReturnValue: anyStringStringDict(), withArgs: nil) as! [String : String]
}

let sel_methodReturnsDictOpt = "sel_methodReturnsDictOpt"
override func methodReturnsDictOpt() -> [String : String]? {
return mockManager.handle(sel_methodReturnsDictOpt, withDefaultReturnValue: anyStringStringDict(), withArgs: nil) as? [String : String]
}

let sel_methodOneArg = "sel_methodOneArg"
override func methodOneArg(arg: String) {
mockManager.handle(sel_methodOneArg, withDefaultReturnValue: nil, withArgs: arg)
}

let sel_methodOneArgReturnsOne = "sel_methodOneArgReturnsOne"
override func methodOneArgReturnsOne(arg: String) -> String {
return mockManager.handle(sel_methodOneArgReturnsOne, withDefaultReturnValue: anyString(), withArgs: arg) as! String
}

let sel_methodTwoArgs = "sel_methodTwoArgs"
override func methodTwoArgs(arg1: String, arg2: String) {
mockManager.handle(sel_methodTwoArgs, withDefaultReturnValue: nil, withArgs: arg1, arg2)
}

let sel_methodTwoArgsOpt = "sel_methodTwoArgsOpt"
override func methodTwoArgsOpt(arg1: String?, arg2: String?) {
mockManager.handle(sel_methodTwoArgsOpt, withDefaultReturnValue: nil, withArgs: arg1, arg2)
}

let sel_methodTwoArgsArrDict = "sel_methodTwoArgsArrDict"
override func methodTwoArgsArrDict(arg1: [String], arg2: [String : String]) {
mockManager.handle(sel_methodTwoArgsArrDict, withDefaultReturnValue: nil, withArgs: arg1, arg2)
}

let sel_methodTwoArgsArrDictOpt = "sel_methodTwoArgsArrDictOpt"
override func methodTwoArgsArrDictOpt(arg1: [String]?, arg2: [String : String]?) {
mockManager.handle(sel_methodTwoArgsArrDictOpt, withDefaultReturnValue: nil, withArgs: arg1, arg2)
}

let sel_methodClosureNamed = "sel_methodClosureNamed"
override func methodClosureNamed(closure: () -> Void) {
override func methodClosureNamed(closure: @escaping () -> Void) {
mockManager.handle(sel_methodClosureNamed, withDefaultReturnValue: nil, withArgs: closure)
}

let sel_methodClosureNoName = "sel_methodClosureNoName"
override func methodClosureNoName(_ closure: @escaping Closure1) {
mockManager.handle(sel_methodClosureNoName, withDefaultReturnValue: nil, withArgs: closure)
}

let sel_methodClosureLabel = "sel_methodClosureLabel"
override func methodClosureLabel(bestClosure closure: @escaping Closure1) -> Closure1 {
return mockManager.handle(sel_methodClosureLabel, withDefaultReturnValue: anyClosure1(), withArgs: closure) as! Closure1
}

let sel_methodCanNotBeSkipped = "sel_methodCanNotBeSkipped"
override func methodCanNotBeSkipped() {
mockManager.handle(sel_methodCanNotBeSkipped, withDefaultReturnValue: nil, withArgs: nil)
}

let sel_methodSameName = "sel_methodSameName"
override func methodSameName() {
mockManager.handle(sel_methodSameName, withDefaultReturnValue: nil, withArgs: nil)
}

let sel_methodSameNameString = "sel_methodSameNameString"
override func methodSameName(string: String) {
mockManager.handle(sel_methodSameNameString, withDefaultReturnValue: nil, withArgs: string)
}

}
Loading

0 comments on commit 610e12d

Please sign in to comment.