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

Swift 2.2.1 code fails to parse #17

Closed
ivany4 opened this issue Jun 13, 2016 · 6 comments
Closed

Swift 2.2.1 code fails to parse #17

ivany4 opened this issue Jun 13, 2016 · 6 comments
Assignees
Labels

Comments

@ivany4
Copy link

ivany4 commented Jun 13, 2016

I have a swift file with a protocol followed by protocol extensions. There are some comments in the file, including // MARK: - declarations.
When I run cuckoo console utility, parsing fails with errors
Unknown kind: source.lang.swift.syntaxtype.comment.mark Unknown kind: source.lang.swift.decl.extension

As a result, the generated file, contains public without any declaration following it. The generated protocol mock looks ok, though.

@TadeasKriz
Copy link
Member

Seems like we have to add option to skip unknown tokens or ignore comment tokens. Thanks for the report.

@FilipDolnik
Copy link
Member

I wasn't able to reproduce your problem. Could you please try it with new version (0.5.0) and send us the file which causes this error?

@ivany4
Copy link
Author

ivany4 commented Jun 16, 2016

Unfortunately, same happens with 0.5.0 version.

The problematic source code is

import UIKit
/**
 *  This is the protocol for the repeatable UI elements that can be reused.
 */
public protocol Reusable {   
    /**
     *  The reuse identifier of the element.
     */
    var reuseIdentifier: String? { get }
}

// MARK: - UITableViewCell

public extension Reusable where Self: UITableViewCell {
}

I use the generator command

Pods/Cuckoo/run generate --testable MyProj --output out.swift Reusable.swift

and get the

Unknown kind: source.lang.swift.syntaxtype.comment.mark
Unknown kind: source.lang.swift.decl.extension

The out.swift looks like this (notice public declaration above import Cuckoo):

// MARK: - Mocks generated from file: Reusable.swift at 2016-06-16 09:54:23 +0000

import UIKit

/**
 *  This is the protocol for the repeatable UI elements that can be reused.
 */
public 
import Cuckoo
@testable import MyProj

public class MockReusable: Reusable, Cuckoo.Mock {
    public let manager: Cuckoo.MockManager<__StubbingProxy_Reusable, __VerificationProxy_Reusable> = Cuckoo.MockManager()

    private var observed: Reusable?

    public required init() {
        observed = nil
    }

    public required init(spyOn victim: Reusable) {
        observed = victim
    }
    public var reuseIdentifier: String? {
        get {
            return manager.getter("reuseIdentifier", original: observed.map { o in return { () -> String? in o.reuseIdentifier } })()
        }
    }

    public struct __StubbingProxy_Reusable: Cuckoo.StubbingProxy {
        let handler: Cuckoo.StubbingHandler

        public init(handler: Cuckoo.StubbingHandler) {
            self.handler = handler
        }
        var reuseIdentifier: ToBeStubbedReadOnlyProperty<String?> {
            return handler.stubReadOnlyProperty("reuseIdentifier")
        }

    }

    public struct __VerificationProxy_Reusable: Cuckoo.VerificationProxy {
        let handler: Cuckoo.VerificationHandler

        public init(handler: Cuckoo.VerificationHandler) {
            self.handler = handler
        }
        var reuseIdentifier: VerifyReadOnlyProperty<String?> {
            return handler.verifyReadOnlyProperty("reuseIdentifier")
        }

    }
}

@TadeasKriz
Copy link
Member

@FilipDolnik Seems to be a bug in FileHeaderHandler.

@FilipDolnik
Copy link
Member

Problem is with the public modificator. So this is raw code which won`t work.

public protocol Reusable {   
}

All attributes like @objc causes this as well. Temporary workaround is to use --no-header parameter.

@TadeasKriz
Copy link
Member

Should be fixed in 0.5.1. Please try it out! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants