Skip to content

Commit

Permalink
Merge pull request #26 from YusukeHosonuma/fix
Browse files Browse the repository at this point in the history
fix: @available annotation
  • Loading branch information
YusukeHosonuma authored Mar 13, 2020
2 parents 4861f4d + eec98b1 commit ab2803d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
31 changes: 31 additions & 0 deletions Sources/DSL/BasicDSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Yusuke Hosonuma on 2020/03/12.
//

// MARK: - Basic API

/// Assert to `target` function with `rows` parameters.
/// - Parameters:
/// - target: test target function or operator
Expand All @@ -30,3 +32,32 @@ public func args<T, R>(_ args: T,
line: UInt = #line) -> Row<T, R> {
Row(args: args, expect: expect, file: file, line: line)
}

// MARK: - Operator based API

precedencegroup ExpectRowPrecedence {
lowerThan: FunctionArrowPrecedence
}

infix operator ==>: ExpectRowPrecedence

/// Create expectation row.
/// - Parameters:
/// - lhs: parameters of test target function
/// - rhs: expected value
public func ==> <T, R>(lhs: T, rhs: R) -> ExpectRow<T, R> {
ExpectRow(args: lhs, expect: rhs)
}

public struct ExpectRow<T, R> {
var args: T
var expect: R
}

public func expect<T, R>(
_ row: ExpectRow<T, R>,
file: StaticString = #file,
line: UInt = #line
) -> Row<T, R> {
Row(args: row.args, expect: row.expect, file: file, line: line)
}
36 changes: 0 additions & 36 deletions Sources/DSL/FunctionBuilderDSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,6 @@
// Note:
// Function Builder is supported by Swift 5.1 or later.

// MARK: - Operators

precedencegroup ExpectRowPrecedence {
lowerThan: FunctionArrowPrecedence
}

infix operator ==>: ExpectRowPrecedence

/// Create expectation row.
/// - Parameters:
/// - lhs: parameters of test target function
/// - rhs: expected value
@available(swift 5.1)
public func ==> <T, R>(lhs: T, rhs: R) -> ExpectRow<T, R> {
ExpectRow(args: lhs, expect: rhs)
}

@available(swift 5.1)
public struct ExpectRow<T, R> {
var args: T
var expect: R
}

// MARK: - Function Builders

@available(swift 5.1)
@_functionBuilder
public struct ParameterBuilder<T, R> {
Expand All @@ -42,8 +17,6 @@ public struct ParameterBuilder<T, R> {
}
}

// MARK: - DSL

/// Create `Expect` for start parameterized-test.
/// - Parameters:
/// - targetFunction: test target function
Expand All @@ -56,12 +29,3 @@ public func assert<T, R: Equatable>(
) {
ParameterizedTest(target: targetFunction, customAssertion: customAssertion).execute(with: rows())
}

@available(swift 5.1)
public func expect<T, R>(
_ row: ExpectRow<T, R>,
file: StaticString = #file,
line: UInt = #line
) -> Row<T, R> {
Row(args: row.args, expect: row.expect, file: file, line: line)
}

0 comments on commit ab2803d

Please sign in to comment.