Files
Sourcery/SourceryTests/Models/TypedSpec.generated.swift
T
Ruslan Alikhamov cec7895f0a Adjusted file structure to accommodate two generated files (#1299)
* Adjusted file structure to accommodate two generated files

* Adjusted scripting

* Removed Description, Diffable, Equality for now

* Removed Stencil import

* Updated templates

* Updated scripting

* Updated generated coding

* Disable build deletion (temp)

* Updated template

* Updated generated code

* updated generated code

* Updated generated code

* Adjusted scripting

* Updated scripting

* Updated generated code

* Reverted template deletion

* Removed Stencil imports

* Updated generated code

* trigger CI

* Removed description, diffable and equality stencil templates

* Reverted temporary changes

* Commented failing tests

* Skipping JSExport for description & hash

* Updated generated code

* Enabled failing tests

* Adding stencil templates back to test tests

* Reset generated file for linux for test

* Reverted Extensions for testing

* Reverted ParserResultsComposed

* Attempt to fix unit tests

* Attempt to resolve unit test

* Reverted TypeName asSource

* Reverted TypeName revertion

* Reverted revert of ParserResultComposed

* Reverted revert of Extensions

* Reverted revert of Linux.content.generated

* Reverted attempts to fix unit tests

* Fix for the failing codegen tests

* Added clarifying comment

* Removed description, diffable and equality stencil templates

* Updated generated code

* Tinkering with optimization level for speed boost

* Excluded stencil templates for codegen

* Fixed wrong compiler flag

* Removed speed optimization to a separate PR

* Reverted test code
2024-03-13 00:01:29 +04:00

361 lines
17 KiB
Swift

// Generated using Sourcery 2.1.7 https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
import Quick
import Nimble
#if SWIFT_PACKAGE
import SourceryLib
#else
import Sourcery
#endif
@testable import SourceryFramework
@testable import SourceryRuntime
// swiftlint:disable function_body_length
class TypedSpec: QuickSpec {
override func spec() {
describe("AssociatedValue") {
func typeName(_ code: String) -> TypeName {
let wrappedCode =
"""
struct Wrapper {
var myFoo: \(code)
}
"""
guard let parser = try? makeParser(for: wrappedCode) else { fail(); return TypeName(name: "") }
let result = try? parser.parse()
let variable = result?.types.first?.variables.first
return variable?.typeName ?? TypeName(name: "")
}
#if canImport(ObjectiveC)
it("can report optional via KVC") {
expect(AssociatedValue(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(AssociatedValue(typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(AssociatedValue(typeName: typeName("Int?")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(false))
expect(AssociatedValue(typeName: typeName("Int!")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(true))
expect(AssociatedValue(typeName: typeName("Int?")).value(forKeyPath: "unwrappedTypeName") as? String).to(equal("Int"))
}
it("can report tuple type via KVC") {
let sut = AssociatedValue(typeName: typeName("(Int, Int)"))
expect(sut.value(forKeyPath: "isTuple") as? Bool).to(equal(true))
}
it("can report closure type via KVC") {
let sut = AssociatedValue(typeName: typeName("(Int) -> (Int)"))
expect(sut.value(forKeyPath: "isClosure") as? Bool).to(equal(true))
}
it("can report array type via KVC") {
let sut = AssociatedValue(typeName: typeName("[Int]"))
expect(sut.value(forKeyPath: "isArray") as? Bool).to(equal(true))
}
it("can report set type via KVC") {
let sut = AssociatedValue(typeName: typeName("Set<Int>"))
expect(sut.value(forKeyPath: "isSet") as? Bool).to(equal(true))
}
it("can report dictionary type via KVC") {
let sut = AssociatedValue(typeName: typeName("[Int: Int]"))
expect(sut.value(forKeyPath: "isDictionary") as? Bool).to(equal(true))
}
it("can report actual type name via KVC") {
let sut = AssociatedValue(typeName: typeName("Alias"))
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Alias")))
sut.typeName.actualTypeName = typeName("Int")
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Int")))
}
#endif
}
describe("ClosureParameter") {
func typeName(_ code: String) -> TypeName {
let wrappedCode =
"""
struct Wrapper {
var myFoo: \(code)
}
"""
guard let parser = try? makeParser(for: wrappedCode) else { fail(); return TypeName(name: "") }
let result = try? parser.parse()
let variable = result?.types.first?.variables.first
return variable?.typeName ?? TypeName(name: "")
}
#if canImport(ObjectiveC)
it("can report optional via KVC") {
expect(ClosureParameter(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(ClosureParameter(typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(ClosureParameter(typeName: typeName("Int?")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(false))
expect(ClosureParameter(typeName: typeName("Int!")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(true))
expect(ClosureParameter(typeName: typeName("Int?")).value(forKeyPath: "unwrappedTypeName") as? String).to(equal("Int"))
}
it("can report tuple type via KVC") {
let sut = ClosureParameter(typeName: typeName("(Int, Int)"))
expect(sut.value(forKeyPath: "isTuple") as? Bool).to(equal(true))
}
it("can report closure type via KVC") {
let sut = ClosureParameter(typeName: typeName("(Int) -> (Int)"))
expect(sut.value(forKeyPath: "isClosure") as? Bool).to(equal(true))
}
it("can report array type via KVC") {
let sut = ClosureParameter(typeName: typeName("[Int]"))
expect(sut.value(forKeyPath: "isArray") as? Bool).to(equal(true))
}
it("can report set type via KVC") {
let sut = ClosureParameter(typeName: typeName("Set<Int>"))
expect(sut.value(forKeyPath: "isSet") as? Bool).to(equal(true))
}
it("can report dictionary type via KVC") {
let sut = ClosureParameter(typeName: typeName("[Int: Int]"))
expect(sut.value(forKeyPath: "isDictionary") as? Bool).to(equal(true))
}
it("can report actual type name via KVC") {
let sut = ClosureParameter(typeName: typeName("Alias"))
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Alias")))
sut.typeName.actualTypeName = typeName("Int")
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Int")))
}
#endif
}
describe("MethodParameter") {
func typeName(_ code: String) -> TypeName {
let wrappedCode =
"""
struct Wrapper {
var myFoo: \(code)
}
"""
guard let parser = try? makeParser(for: wrappedCode) else { fail(); return TypeName(name: "") }
let result = try? parser.parse()
let variable = result?.types.first?.variables.first
return variable?.typeName ?? TypeName(name: "")
}
#if canImport(ObjectiveC)
it("can report optional via KVC") {
expect(MethodParameter(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(MethodParameter(typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(MethodParameter(typeName: typeName("Int?")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(false))
expect(MethodParameter(typeName: typeName("Int!")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(true))
expect(MethodParameter(typeName: typeName("Int?")).value(forKeyPath: "unwrappedTypeName") as? String).to(equal("Int"))
}
it("can report tuple type via KVC") {
let sut = MethodParameter(typeName: typeName("(Int, Int)"))
expect(sut.value(forKeyPath: "isTuple") as? Bool).to(equal(true))
}
it("can report closure type via KVC") {
let sut = MethodParameter(typeName: typeName("(Int) -> (Int)"))
expect(sut.value(forKeyPath: "isClosure") as? Bool).to(equal(true))
}
it("can report array type via KVC") {
let sut = MethodParameter(typeName: typeName("[Int]"))
expect(sut.value(forKeyPath: "isArray") as? Bool).to(equal(true))
}
it("can report set type via KVC") {
let sut = MethodParameter(typeName: typeName("Set<Int>"))
expect(sut.value(forKeyPath: "isSet") as? Bool).to(equal(true))
}
it("can report dictionary type via KVC") {
let sut = MethodParameter(typeName: typeName("[Int: Int]"))
expect(sut.value(forKeyPath: "isDictionary") as? Bool).to(equal(true))
}
it("can report actual type name via KVC") {
let sut = MethodParameter(typeName: typeName("Alias"))
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Alias")))
sut.typeName.actualTypeName = typeName("Int")
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Int")))
}
#endif
}
describe("TupleElement") {
func typeName(_ code: String) -> TypeName {
let wrappedCode =
"""
struct Wrapper {
var myFoo: \(code)
}
"""
guard let parser = try? makeParser(for: wrappedCode) else { fail(); return TypeName(name: "") }
let result = try? parser.parse()
let variable = result?.types.first?.variables.first
return variable?.typeName ?? TypeName(name: "")
}
#if canImport(ObjectiveC)
it("can report optional via KVC") {
expect(TupleElement(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(TupleElement(typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(TupleElement(typeName: typeName("Int?")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(false))
expect(TupleElement(typeName: typeName("Int!")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(true))
expect(TupleElement(typeName: typeName("Int?")).value(forKeyPath: "unwrappedTypeName") as? String).to(equal("Int"))
}
it("can report tuple type via KVC") {
let sut = TupleElement(typeName: typeName("(Int, Int)"))
expect(sut.value(forKeyPath: "isTuple") as? Bool).to(equal(true))
}
it("can report closure type via KVC") {
let sut = TupleElement(typeName: typeName("(Int) -> (Int)"))
expect(sut.value(forKeyPath: "isClosure") as? Bool).to(equal(true))
}
it("can report array type via KVC") {
let sut = TupleElement(typeName: typeName("[Int]"))
expect(sut.value(forKeyPath: "isArray") as? Bool).to(equal(true))
}
it("can report set type via KVC") {
let sut = TupleElement(typeName: typeName("Set<Int>"))
expect(sut.value(forKeyPath: "isSet") as? Bool).to(equal(true))
}
it("can report dictionary type via KVC") {
let sut = TupleElement(typeName: typeName("[Int: Int]"))
expect(sut.value(forKeyPath: "isDictionary") as? Bool).to(equal(true))
}
it("can report actual type name via KVC") {
let sut = TupleElement(typeName: typeName("Alias"))
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Alias")))
sut.typeName.actualTypeName = typeName("Int")
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Int")))
}
#endif
}
describe("Typealias") {
func typeName(_ code: String) -> TypeName {
let wrappedCode =
"""
struct Wrapper {
var myFoo: \(code)
}
"""
guard let parser = try? makeParser(for: wrappedCode) else { fail(); return TypeName(name: "") }
let result = try? parser.parse()
let variable = result?.types.first?.variables.first
return variable?.typeName ?? TypeName(name: "")
}
#if canImport(ObjectiveC)
it("can report optional via KVC") {
expect(Typealias(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(Typealias(typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(Typealias(typeName: typeName("Int?")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(false))
expect(Typealias(typeName: typeName("Int!")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(true))
expect(Typealias(typeName: typeName("Int?")).value(forKeyPath: "unwrappedTypeName") as? String).to(equal("Int"))
}
it("can report tuple type via KVC") {
let sut = Typealias(typeName: typeName("(Int, Int)"))
expect(sut.value(forKeyPath: "isTuple") as? Bool).to(equal(true))
}
it("can report closure type via KVC") {
let sut = Typealias(typeName: typeName("(Int) -> (Int)"))
expect(sut.value(forKeyPath: "isClosure") as? Bool).to(equal(true))
}
it("can report array type via KVC") {
let sut = Typealias(typeName: typeName("[Int]"))
expect(sut.value(forKeyPath: "isArray") as? Bool).to(equal(true))
}
it("can report set type via KVC") {
let sut = Typealias(typeName: typeName("Set<Int>"))
expect(sut.value(forKeyPath: "isSet") as? Bool).to(equal(true))
}
it("can report dictionary type via KVC") {
let sut = Typealias(typeName: typeName("[Int: Int]"))
expect(sut.value(forKeyPath: "isDictionary") as? Bool).to(equal(true))
}
it("can report actual type name via KVC") {
let sut = Typealias(typeName: typeName("Alias"))
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Alias")))
sut.typeName.actualTypeName = typeName("Int")
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Int")))
}
#endif
}
describe("Variable") {
func typeName(_ code: String) -> TypeName {
let wrappedCode =
"""
struct Wrapper {
var myFoo: \(code)
}
"""
guard let parser = try? makeParser(for: wrappedCode) else { fail(); return TypeName(name: "") }
let result = try? parser.parse()
let variable = result?.types.first?.variables.first
return variable?.typeName ?? TypeName(name: "")
}
#if canImport(ObjectiveC)
it("can report optional via KVC") {
expect(Variable(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(Variable(typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect(Variable(typeName: typeName("Int?")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(false))
expect(Variable(typeName: typeName("Int!")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(true))
expect(Variable(typeName: typeName("Int?")).value(forKeyPath: "unwrappedTypeName") as? String).to(equal("Int"))
}
it("can report tuple type via KVC") {
let sut = Variable(typeName: typeName("(Int, Int)"))
expect(sut.value(forKeyPath: "isTuple") as? Bool).to(equal(true))
}
it("can report closure type via KVC") {
let sut = Variable(typeName: typeName("(Int) -> (Int)"))
expect(sut.value(forKeyPath: "isClosure") as? Bool).to(equal(true))
}
it("can report array type via KVC") {
let sut = Variable(typeName: typeName("[Int]"))
expect(sut.value(forKeyPath: "isArray") as? Bool).to(equal(true))
}
it("can report set type via KVC") {
let sut = Variable(typeName: typeName("Set<Int>"))
expect(sut.value(forKeyPath: "isSet") as? Bool).to(equal(true))
}
it("can report dictionary type via KVC") {
let sut = Variable(typeName: typeName("[Int: Int]"))
expect(sut.value(forKeyPath: "isDictionary") as? Bool).to(equal(true))
}
it("can report actual type name via KVC") {
let sut = Variable(typeName: typeName("Alias"))
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Alias")))
sut.typeName.actualTypeName = typeName("Int")
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Int")))
}
#endif
}
}
}