Skip to content
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

Implements static string extension. #114

Merged
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
4 changes: 4 additions & 0 deletions Sources/StringGenerator/Snippets/SourceFileSnippet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ struct SourceFileSnippet: Snippet {
ExtensionSnippet(extending: .type(.String)) {
StringStringsTableStructSnippet(stringsTable: sourceFile.stringExtension.stringsTableStruct)
StringInitializerSnippet(stringsTable: sourceFile.stringExtension.stringsTableStruct)
StringsTableConversionStaticMethodSnippet(
stringsTable: sourceFile.stringExtension.stringsTableStruct,
returnType: .type(.String)
)
}

ExtensionSnippet(
Expand Down
27 changes: 27 additions & 0 deletions Tests/PluginTests/PluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ final class PluginTests: XCTestCase {
String(localizable: .demoBasic),
"A basic string"
)
XCTAssertEqual(
.localizable(.demoBasic),
"A basic string"
)

XCTAssertEqual(
String(localized: .localizable(.multiline(2))),
Expand All @@ -23,6 +27,13 @@ final class PluginTests: XCTestCase {
spans 2 lines
"""
)
XCTAssertEqual(
.localizable(.multiline(2)),
"""
A string that
spans 2 lines
"""
)

XCTAssertEqual(
String(localized: .featureOne(.pluralExample(1))),
Expand All @@ -32,6 +43,10 @@ final class PluginTests: XCTestCase {
String(featureOne: .pluralExample(1)),
"1 string remaining"
)
XCTAssertEqual(
.featureOne(.pluralExample(1)),
"1 string remaining"
)

XCTAssertEqual(
String(localized: .featureOne(.pluralExample(10))),
Expand All @@ -41,6 +56,10 @@ final class PluginTests: XCTestCase {
String(featureOne: .pluralExample(10)),
"10 strings remaining"
)
XCTAssertEqual(
.featureOne(.pluralExample(10)),
"10 strings remaining"
)
}

func testSwiftUI() {
Expand All @@ -59,11 +78,19 @@ final class PluginTests: XCTestCase {
String(legacy: .simpleString("foo")),
"This simple string: foo"
)
XCTAssertEqual(
.legacy(.simpleString("foo")),
"This simple string: foo"
)

XCTAssertEqual(
String(legacy: .plural("John", 1)),
"Hello John, I have 1 plural"
)
XCTAssertEqual(
.legacy(.plural("John", 1)),
"Hello John, I have 1 plural"
)
}

func testComparisons() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ extension String {
arguments: formatSpecifiers.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘FormatSpecifiers‘ strings table.
internal static func formatSpecifiers(_ formatSpecifiers: String.FormatSpecifiers) -> String {
String(formatSpecifiers: formatSpecifiers)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ extension String {
arguments: localizable.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Localizable‘ strings table.
internal static func localizable(_ localizable: String.Localizable) -> String {
String(localizable: localizable)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ extension String {
arguments: multiline.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Multiline‘ strings table.
internal static func multiline(_ multiline: String.Multiline) -> String {
String(multiline: multiline)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ extension String {
arguments: positional.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Positional‘ strings table.
internal static func positional(_ positional: String.Positional) -> String {
String(positional: positional)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ extension String {
arguments: simple.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Simple‘ strings table.
internal static func simple(_ simple: String.Simple) -> String {
String(simple: simple)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ extension String {
arguments: substitution.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Substitution‘ strings table.
internal static func substitution(_ substitution: String.Substitution) -> String {
String(substitution: substitution)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ extension String {
arguments: variations.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Variations‘ strings table.
internal static func variations(_ variations: String.Variations) -> String {
String(variations: variations)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ extension String {
arguments: legacy.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Legacy‘ strings table.
internal static func legacy(_ legacy: String.Legacy) -> String {
String(legacy: legacy)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ extension String {
arguments: legacy.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Legacy‘ strings table.
internal static func legacy(_ legacy: String.Legacy) -> String {
String(legacy: legacy)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ extension String {
arguments: legacy.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Legacy‘ strings table.
internal static func legacy(_ legacy: String.Legacy) -> String {
String(legacy: legacy)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ extension String {
arguments: localizable.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Localizable‘ strings table.
package static func localizable(_ localizable: String.Localizable) -> String {
String(localizable: localizable)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ extension String {
arguments: localizable.arguments.map(\.value)
)
}

/// Creates a `String` that represents a localized value in the ‘Localizable‘ strings table.
public static func localizable(_ localizable: String.Localizable) -> String {
String(localizable: localizable)
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Expand Down
Loading