How to use SourceLocation class

Best Nimble code snippet using SourceLocation

Errors.swift

Source:Errors.swift Github

copy

Full Screen

...30 associatedtype ServiceError: Error & Decodable & Debuggable31}32extension FailableService {33 public func request<T: Decodable>(34 _ sourceLocation: SourceLocation,35 _ makeRequest: () throws -> Future<Response>36 ) throws -> Future<T> {37 return try makeRequest()38 .flatMap { response in39 try response.content40 .decode(T.self)41 .catchFlatMap { _ in42 try response.content43 .decode(ServiceError.self)44 .thenThrowing { throw $0 }45 }46 }47 .catchError(sourceLocation)48 }49 public func request(50 _ sourceLocation: SourceLocation,51 _ makeRequest: () throws -> Future<Response>52 ) throws -> Future<Void> {53 return try makeRequest()54 .flatMap { response in55 guard response.http.status == .noContent else {56 return try response.content57 .decode(ServiceError.self)58 .thenThrowing { throw $0 }59 }60 return response.future(())61 }62 .catchError(sourceLocation)63 }64}65extension CircleCIService: FailableService {66 struct ServiceError: Swift.Error, Decodable, Debuggable {67 let message: String68 let identifier: String = "CircleCIService"69 var reason: String {70 return message71 }72 }73}74extension GitHubService: FailableService {75 struct ServiceError: Swift.Error, Decodable, Debuggable {76 let message: String77 let identifier: String = "GitHubService"78 var reason: String {79 return message80 }81 }82}83extension JiraService: FailableService {84 public struct ServiceError: Swift.Error, Decodable, Debuggable {85 // See https://developer.atlassian.com/cloud/jira/platform/rest/v3/#status-codes for schema86 public let errorMessages: [String]87 public let errors: [String: String]88 public let identifier: String = "JiraService"89 public var reason: String {90 let allErrors = errorMessages + errors.sorted(by: <).map { "\($0): \($1)" }91 if allErrors.count > 1 {92 return allErrors93 .enumerated()94 .map { "[\($0.offset+1)] \($0.element)" }95 .joined(separator: " ")96 } else {97 return allErrors.first ?? "Unknown error"98 }99 }100 }101}102public struct NilValueError: Error, Debuggable {103 public let identifier = "nilValue"104 public let reason = "Unexpected nil value"105}106public struct ThrowError: Error, Debuggable {107 public let error: Error108 public let identifier: String109 public let reason: String110 public let sourceLocation: SourceLocation?111 init(error: Error, sourceLocation: SourceLocation) {112 self.error = error113 let _sourceLocation: SourceLocation?114 if let throwError = error as? ThrowError {115 self.identifier = throwError.identifier116 self.reason = throwError.reason117 _sourceLocation = throwError.sourceLocation118 } else if let debuggable = error as? Debuggable {119 self.identifier = "\(type(of: debuggable)).\(debuggable.identifier)"120 self.reason = debuggable.reason121 _sourceLocation = debuggable.sourceLocation122 } else {123 self.identifier = "\(type(of: error))"124 self.reason = error.localizedDescription125 _sourceLocation = sourceLocation126 }127 #if DEBUG128 self.sourceLocation = _sourceLocation ?? sourceLocation129 #else130 self.sourceLocation = nil131 #endif132 }133 init(error: Error, file: String, line: UInt, column: UInt, function: String) {134 self.init(135 error: error,136 sourceLocation: SourceLocation(137 file: file,138 function: function,139 line: line,140 column: column,141 range: nil142 )143 )144 }145}146#if !DEBUG147extension SlackService.Error {148 public var errorDescription: String? {149 return reason150 }151}152extension ThrowError: LocalizedError {153 public var errorDescription: String? {154 return reason155 }156}157#endif158public func attempt<T>(159 file: StaticString = #file,160 line: UInt = #line,161 column: UInt = #column,162 function: StaticString = #function,163 expr: () throws -> T?164) throws -> T {165 do {166 guard let value = try expr() else {167 throw NilValueError()168 }169 return value170 } catch {171 throw ThrowError(error: error, file: "\(file)", line: line, column: column, function: "\(function)")172 }173}174public func attempt<T>(175 file: StaticString = #file,176 line: UInt = #line,177 column: UInt = #column,178 function: StaticString = #function,179 expr: () throws -> T?180) throws -> T? {181 do {182 return try expr()183 } catch {184 throw ThrowError(error: error, file: "\(file)", line: line, column: column, function: "\(function)")185 }186}187extension Future {188 public func catchError(_ sourceLocation: SourceLocation) -> Future<Expectation> {189 return catchFlatMap { (error) -> EventLoopFuture<T> in190 throw ThrowError(error: error, sourceLocation: sourceLocation)191 }192 }193}194extension SlackService.Response {195 public init(error: Error, visibility: Visibility = .user) {196 #if DEBUG197 self.init(String(describing: error), visibility: visibility)198 #else199 self.init(error.localizedDescription, visibility: visibility)200 #endif201 }202}...

Full Screen

Full Screen

MockComponentBase.swift

Source:MockComponentBase.swift Github

copy

Full Screen

...100//101// struct __VerificationProxy_MockComponentBase: Cuckoo.VerificationProxy {102// private let cuckoo_manager: Cuckoo.MockManager103// private let callMatcher: Cuckoo.CallMatcher104// private let sourceLocation: Cuckoo.SourceLocation105//106// init(manager: Cuckoo.MockManager, callMatcher: Cuckoo.CallMatcher, sourceLocation: Cuckoo.SourceLocation) {107// self.cuckoo_manager = manager108// self.callMatcher = callMatcher109// self.sourceLocation = sourceLocation110// }111//112// var action: Cuckoo.VerifyReadOnlyProperty<Observable<ACTION>> {113// return .init(manager: cuckoo_manager, name: "action", callMatcher: callMatcher, sourceLocation: sourceLocation)114// }115//116// var actions: Cuckoo.VerifyReadOnlyProperty<[Observable<ACTION>]> {117// return .init(manager: cuckoo_manager, name: "actions", callMatcher: callMatcher, sourceLocation: sourceLocation)118// }119//120// @discardableResult...

Full Screen

Full Screen

SourceLocation.swift

Source:SourceLocation.swift Github

copy

Full Screen

1import Foundation2public struct SourceLocation: Hashable {3 public let line: Int4 public let column: Int5 public let source: URL?6 public init(line: Int, column: Int, source: URL? = nil) {7 self.line = line8 self.column = column9 self.source = source10 }11}12extension SourceLocation: CustomStringConvertible {13 public var description: String {14 var description = ""15 if let path = source?.relativePath, !path.isEmpty {16 description += "\(path):"17 }18 description += "\(line):\(column)"19 return description20 }21}22extension SourceLocation: Comparable {23 public static func < (lhs: SourceLocation, rhs: SourceLocation) -> Bool {24 if lhs.line < rhs.line {25 return true26 } else if lhs.line == rhs.line {27 return lhs.column < rhs.column28 } else {29 return false30 }31 }32}33extension SourceLocation {34 init(_ location: String.Index, in string: String, source: URL? = nil) {35 let range = string.lineRange(for: location ..< location)36 let column = 1 + string[range.lowerBound ..< location].count37 var line = 138 string.enumerateSubstrings(in: ..<range.lowerBound, options: [.byLines, .substringNotRequired]) { _, _, _, _ in39 line += 140 }41 self.init(line: line, column: column, source: source)42 }43}44public typealias SourceRange = Range<SourceLocation>45extension SourceRange {46 init(_ range: Range<String.Index>, in string: String, source: URL? = nil) {47 self = SourceLocation(range.lowerBound, in: string, source: source) ..< SourceLocation(range.upperBound, in: string, source: source)48 }49}...

Full Screen

Full Screen

SourceLocation

Using AI Code Generation

copy

Full Screen

1import Nimble2func test() {3 let location = SourceLocation(file: "file.swift", line: 10)4 expect(1).to(equal(1), description: "1 should equal 1", location: location)5}6import Quick7func test() {8 let location = SourceLocation(file: "file.swift", line: 10)9 expect(1).to(equal(1), description: "1 should equal 1", location: location)10}11import Quick12func test() {13 let location = SourceLocation(file: "file.swift", line: 10)14 expect(1).to(equal(1), description: "1 should equal 1", location: location)15}16import Quick17func test() {18 let location = SourceLocation(file: "file.swift", line: 10)19 expect(1).to(equal(1), description: "1 should equal 1", location: location)20}21import Quick22func test() {23 let location = SourceLocation(file: "file.swift", line: 10)24 expect(1).to(equal(1), description: "1 should equal 1", location: location)25}26import Quick27func test() {28 let location = SourceLocation(file: "file.swift", line: 10)29 expect(1).to(equal(1), description: "1 should equal 1", location: location)30}31import Quick32func test() {33 let location = SourceLocation(file: "file.swift", line: 10)34 expect(1).to(equal(1), description: "1 should equal 1", location: location)35}36import Quick37func test() {38 let location = SourceLocation(file: "file.swift", line: 10)39 expect(1).to(equal(1),

Full Screen

Full Screen

SourceLocation

Using AI Code Generation

copy

Full Screen

1import Nimble2import Quick3class FirstSpec: QuickSpec {4 override func spec() {5 describe("First") {6 it("should pass") {7 expect(true).to(beTrue())8 }9 it("should fail") {10 expect(true).to(beFalse())11 }12 }13 }14}15import Nimble16import Quick17class SecondSpec: QuickSpec {18 override func spec() {19 describe("Second") {20 it("should pass") {21 expect(true).to(beTrue())22 }23 it("should fail") {24 expect(true).to(beFalse())25 }26 }27 }28}29import Nimble30import Quick31class ThirdSpec: QuickSpec {32 override func spec() {33 describe("Third") {34 it("should pass") {35 expect(true).to(beTrue())36 }37 it("should fail") {38 expect(true).to(beFalse())39 }40 }41 }42}43import Nimble44import Quick45class FourthSpec: QuickSpec {46 override func spec() {47 describe("Fourth") {48 it("should pass") {49 expect(true).to(beTrue())50 }51 it("should fail") {52 expect(true).to(beFalse())53 }54 }55 }56}57import Nimble58import Quick59class FifthSpec: QuickSpec {60 override func spec() {61 describe("Fifth") {62 it("should pass") {63 expect(true).to(beTrue())64 }65 it("should fail") {66 expect(true).to(beFalse())67 }68 }69 }70}71import Nimble72import Quick73class SixthSpec: QuickSpec {74 override func spec() {75 describe("Sixth") {76 it("should pass") {77 expect(true).to(beTrue())78 }79 it("should fail") {80 expect(true).to(beFalse())81 }82 }83 }84}85import Nimble

Full Screen

Full Screen

SourceLocation

Using AI Code Generation

copy

Full Screen

1import Nimble2func test() {3 let sourceLocation = SourceLocation(file: "1.swift", line: 5)4 expect(1).to(equal(2), description: "1 is not equal to 2", file: sourceLocation.file, line: sourceLocation.line)5}6import Quick7func test() {8 let sourceLocation = SourceLocation(file: "2.swift", line: 5)9 expect(1).to(equal(2), description: "1 is not equal to 2", file: sourceLocation.file, line: sourceLocation.line)10}11import Quick12func test() {13 let sourceLocation = SourceLocation(file: "3.swift", line: 5)14 expect(1).to(equal(2), description: "1 is not equal to 2", file: sourceLocation.file, line: sourceLocation.line)15}16import Nimble17func test() {18 let sourceLocation = SourceLocation(file: "4.swift", line: 5)19 expect(1).to(equal(2), description: "1 is not equal to 2", file: sourceLocation.file, line: sourceLocation.line)20}21import Quick22func test() {23 let sourceLocation = SourceLocation(file: "5.swift", line: 5)24 expect(1).to(equal(2), description: "1 is not equal to 2", file: sourceLocation.file, line: sourceLocation.line)25}26import Quick27func test() {28 let sourceLocation = SourceLocation(file: "6.swift", line: 5)29 expect(1).to(equal(2), description: "1 is not equal to 2", file: sourceLocation.file, line: sourceLocation.line)30}31import Nimble32func test() {33 let sourceLocation = SourceLocation(file: "7.swift", line: 5)34 expect(1).to(equal(2), description:

Full Screen

Full Screen

SourceLocation

Using AI Code Generation

copy

Full Screen

1import Nimble2let sourceLocation = SourceLocation(file: "path/to/file", line: 1)3expect("foo", file: sourceLocation.file, line: sourceLocation.line) == "bar"4import Nimble5let sourceLocation = SourceLocation(file: "path/to/file", line: 1)6expect("foo", file: sourceLocation.file, line: sourceLocation.line) == "bar"7import Nimble8let sourceLocation = SourceLocation(file: "path/to/file", line: 1)9expect("foo", file: sourceLocation.file, line: sourceLocation.line) == "bar"10import Nimble11let sourceLocation = SourceLocation(file: "path/to/file", line: 1)12expect("foo", file: sourceLocation.file, line: sourceLocation.line) == "bar"13import Nimble14let sourceLocation = SourceLocation(file: "path/to/file", line: 1)15expect("foo", file: sourceLocation.file, line: sourceLocation.line) == "bar"16import Nimble17let sourceLocation = SourceLocation(file: "path/to/file", line: 1)18expect("foo", file: sourceLocation.file, line: sourceLocation.line) == "bar"19import Nimble20let sourceLocation = SourceLocation(file: "path/to/file", line: 1)21expect("foo", file: sourceLocation.file, line: sourceLocation.line) == "bar"22import Nimble23let sourceLocation = SourceLocation(file: "path/to/file", line: 1)24expect("foo", file: sourceLocation.file, line: sourceLocation.line) == "bar"25import Nimble

Full Screen

Full Screen

SourceLocation

Using AI Code Generation

copy

Full Screen

1import Nimble2import XCTest3class Test : XCTestCase {4 func test() {5 expect(1).to(equal(1), description: "test")6 }7}8import Nimble9import XCTest10class Test : XCTestCase {11 func test() {12 expect(1).to(equal(1), description: "test")13 }14}15import Nimble16import XCTest17class Test : XCTestCase {18 func test() {19 expect(1).to(equal(1), description: "test")20 }21}22import Nimble23import XCTest24class Test : XCTestCase {25 func test() {26 expect(1).to(equal(1), description: "test")27 }28}29import Nimble30import XCTest31class Test : XCTestCase {32 func test() {33 expect(1).to(equal(1), description: "test")34 }35}36import Nimble37import XCTest38class Test : XCTestCase {39 func test() {40 expect(1).to(equal(1), description: "test")41 }42}43import Nimble44import XCTest45class Test : XCTestCase {46 func test() {47 expect(1).to(equal(1), description: "test")48 }49}50import Nimble51import XCTest52class Test : XCTestCase {53 func test() {54 expect(1).to(equal(1), description: "test")55 }56}57import Nimble58import XCTest59class Test : XCTestCase {60 func test() {61 expect(1).to(equal(1), description: "test")62 }63}64import Nimble65import XCTest66class Test : XCTestCase {67 func test() {68 expect(1

Full Screen

Full Screen

SourceLocation

Using AI Code Generation

copy

Full Screen

1import Nimble2let sourceLocation = SourceLocation(file: "file.swift", line: 1)3let failure = FailureMessage(stringValue: failureMessage, location: sourceLocation)4expect(failure.description).to(equal("file.swift:1: This is a failure message"))5import Quick6let sourceLocation = SourceLocation(file: "file.swift", line: 1)7let failure = FailureMessage(stringValue: failureMessage, location: sourceLocation)8expect(failure.description).to(equal("file.swift:1: This is a failure message"))9let failure = FailureMessage(stringValue: failureMessage, location: sourceLocation)10let failure = FailureMessage(stringValue: failureMessage, location: sourceLocation)

Full Screen

Full Screen

SourceLocation

Using AI Code Generation

copy

Full Screen

1class ExampleSpec: QuickSpec {2 override func spec() {3 it("has a valid SourceLocation") {4 expect(__FILE__).to(equal("1.swift"))5 expect(__LINE__).to(equal(8))6 expect(__COLUMN__).to(equal(18))7 }8 }9}10class ExampleSpec2: QuickSpec {11 override func spec() {12 it("has a valid SourceLocation") {13 expect(__FILE__).to(equal("2.swift"))14 expect(__LINE__).to(equal(8))15 expect(__COLUMN__).to(equal(18))16 }17 }18}19class ExampleSpec3: QuickSpec {20 override func spec() {21 it("has a valid SourceLocation") {22 expect(__FILE__).to(equal("3.swift"))23 expect(__LINE__).to(equal(8))24 expect(__COLUMN__).to(equal(18))25 }26 }27}28class ExampleSpec4: QuickSpec {29 override func spec() {30 it("has a valid SourceLocation") {31 expect(__FILE__).to(equal("4.swift"))32 expect(__LINE__).to(equal(8))33 expect(__COLUMN__).to(equal(18))34 }35 }36}37class ExampleSpec5: QuickSpec {38 override func spec() {39 it("has a valid SourceLocation") {40 expect(__FILE__).to(equal("5.swift"))41 expect(__LINE__).to(equal(8))42 expect(__COLUMN__).to(equal(18))43 }44 }45}46class ExampleSpec6: QuickSpec {47 override func spec() {48 it("has a valid SourceLocation") {49 expect(__FILE__).to(equal("6.swift"))50 expect(__LINE__).to(equal(8))51 expect(__COLUMN__).to(equal(18

Full Screen

Full Screen

SourceLocation

Using AI Code Generation

copy

Full Screen

1import Nimble2import Foundation3func test() {4 let location = SourceLocation(file: "1.swift", line: 7)5 let message = ExpectationMessage.expectedActualValueTo("equal <1>")6 expect(1, message: message, location: location).to(equal(2))7}8test()9import Quick10import Foundation11func test() {12 let location = SourceLocation(file: "2.swift", line: 7)13 let message = ExpectationMessage.expectedActualValueTo("equal <1>")14 expect(1, message: message, location: location).to(equal(2))15}16test()17import Quick18import Foundation19func test() {20 let location = SourceLocation(file: "3.swift", line: 7)21 let message = ExpectationMessage.expectedActualValueTo("equal <1>")22 expect(1, message: message, location: location).to(equal(2))23}24test()25import Quick26import Foundation27func test() {28 let location = SourceLocation(file: "4.swift", line: 7)29 let message = ExpectationMessage.expectedActualValueTo("equal <1>")30 expect(1, message: message, location: location).to(equal(2))31}32test()33import Quick34import Foundation35func test() {36 let location = SourceLocation(file: "5.swift", line: 7)37 let message = ExpectationMessage.expectedActualValueTo("equal <1>")38 expect(1, message: message, location: location).to(equal(2))39}40test()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Nimble automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful