Skip to content

[test] Update tests to pass with 5.5 toolchain #420

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

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions Tests/SourceKitLSPTests/InlayHintsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class InlayHintsTests: XCTestCase {
))
}

func performInlayHintsRequest(text: String, range: Range<Position>? = nil) -> [InlayHint] {
func performInlayHintsRequest(text: String, range: Range<Position>? = nil) throws -> [InlayHint] {
let url = URL(fileURLWithPath: "/\(#function)/a.swift")

sk.send(DidOpenTextDocumentNotification(textDocument: TextDocumentItem(
Expand All @@ -53,21 +53,26 @@ final class InlayHintsTests: XCTestCase {
)))

let request = InlayHintsRequest(textDocument: TextDocumentIdentifier(url), range: range)
return try! sk.sendSync(request)

do {
return try sk.sendSync(request)
} catch let error as ResponseError where error.message.contains("unknown request: source.request.variable.type") {
throw XCTSkip("toolchain does not support variable.type request")
}
}

func testEmpty() {
func testEmpty() throws {
let text = ""
let hints = performInlayHintsRequest(text: text)
let hints = try performInlayHintsRequest(text: text)
XCTAssertEqual(hints, [])
}

func testBindings() {
func testBindings() throws {
let text = """
let x = 4
var y = "test" + "123"
"""
let hints = performInlayHintsRequest(text: text)
let hints = try performInlayHintsRequest(text: text)
XCTAssertEqual(hints, [
InlayHint(
position: Position(line: 0, utf16index: 5),
Expand All @@ -82,7 +87,7 @@ final class InlayHintsTests: XCTestCase {
])
}

func testRanged() {
func testRanged() throws {
let text = """
func square(_ x: Double) -> Double {
let result = x * x
Expand All @@ -96,7 +101,7 @@ final class InlayHintsTests: XCTestCase {
}
"""
let range = Position(line: 6, utf16index: 0)..<Position(line: 9, utf16index: 0)
let hints = performInlayHintsRequest(text: text, range: range)
let hints = try performInlayHintsRequest(text: text, range: range)
XCTAssertEqual(hints, [
InlayHint(
position: Position(line: 6, utf16index: 10),
Expand All @@ -111,7 +116,7 @@ final class InlayHintsTests: XCTestCase {
])
}

func testFields() {
func testFields() throws {
let text = """
class X {
let instanceMember = 3
Expand All @@ -127,7 +132,7 @@ final class InlayHintsTests: XCTestCase {
static let staticMember = 3.0
}
"""
let hints = performInlayHintsRequest(text: text)
let hints = try performInlayHintsRequest(text: text)
XCTAssertEqual(hints, [
InlayHint(
position: Position(line: 1, utf16index: 20),
Expand Down Expand Up @@ -157,19 +162,19 @@ final class InlayHintsTests: XCTestCase {
])
}

func testExplicitTypeAnnotation() {
func testExplicitTypeAnnotation() throws {
let text = """
let x: String = "abc"

struct X {
var y: Int = 34
}
"""
let hints = performInlayHintsRequest(text: text)
let hints = try performInlayHintsRequest(text: text)
XCTAssertEqual(hints, [])
}

func testClosureParams() {
func testClosureParams() throws {
let text = """
func f(x: Int) {}

Expand All @@ -179,7 +184,7 @@ final class InlayHintsTests: XCTestCase {
x + y
}
"""
let hints = performInlayHintsRequest(text: text)
let hints = try performInlayHintsRequest(text: text)
XCTAssertEqual(hints, [
InlayHint(
position: Position(line: 2, utf16index: 5),
Expand Down