Skip to content

Add generic and throwing function example #1

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
May 2, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions Sources/SymbolLocatorTestsSupport/SymbolLocatorTestsSupport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// SymbolLocatorTestsSupport.h
// SymbolLocatorTestsSupport

#include "SymbolLocator.h"

DEFINE_SL_STUB_SLF(SymbolLocatorTestsSupportTestStub_CGSizeHasZero, SwiftUI, $sSo6CGSizeV7SwiftUIE7hasZeroSbvg);
DEFINE_SL_STUB_SLF(SymbolLocatorTestsSupportTestStub_UpdateLocked, SwiftUI, $s7SwiftUI6UpdateO6lockedyxxyKXEKlFZ);
3 changes: 0 additions & 3 deletions Sources/SymbolLocatorTestsSupport/Test.c

This file was deleted.

34 changes: 32 additions & 2 deletions Tests/SymbolLocatorTests/SymbolLocatorTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Testing
import SymbolLocator
import SymbolLocatorTestsSupport
import Foundation

#if canImport(SwiftUI, _underlyingVersion: 6.0.87)
import SwiftUI

extension CGSize {
var hasZero: Bool {
Expand All @@ -10,7 +12,9 @@ extension CGSize {
}
}

@Test func example() async throws {
// Example for simple getter method
@Test
func sizeExample() async throws {
let size1 = CGSize(width: 0, height: 0)
let size2 = CGSize(width: 1, height: 0)
let size3 = CGSize(width: 0, height: 1)
Expand All @@ -20,3 +24,29 @@ extension CGSize {
#expect(size3.hasZero)
#expect(!size4.hasZero)
}

enum Update {}

extension Update {
@_silgen_name("SymbolLocatorTestsSupportTestStub_UpdateLocked")
static func locked<T>(_ body: () throws -> T) rethrows -> T
}

// Example for generic and throwing function
@Test
func updateLockedExample() async throws {
let result = Update.locked { 3 }
#expect(result == 3)
enum E: Error {
case a, b
}
try await confirmation { confirm in
do {
let _ = try Update.locked { throw E.b }
} catch E.a {
confirm()
}
}
}

#endif