diff --git a/Sources/SyntaxKit/Attribute.swift b/Sources/SyntaxKit/Attribute.swift index c3d909b..526a55a 100644 --- a/Sources/SyntaxKit/Attribute.swift +++ b/Sources/SyntaxKit/Attribute.swift @@ -31,10 +31,10 @@ import SwiftSyntax /// Internal representation of a Swift attribute with its arguments. internal struct AttributeInfo { - let name: String - let arguments: [String] + internal let name: String + internal let arguments: [String] - init(name: String, arguments: [String] = []) { + internal init(name: String, arguments: [String] = []) { self.name = name self.arguments = arguments } diff --git a/Sources/SyntaxKit/CodeBlock+Generate.swift b/Sources/SyntaxKit/CodeBlock+Generate.swift index c912232..9acbb9e 100644 --- a/Sources/SyntaxKit/CodeBlock+Generate.swift +++ b/Sources/SyntaxKit/CodeBlock+Generate.swift @@ -45,6 +45,21 @@ extension CodeBlock { item = .stmt(stmt) } else if let expr = self.syntax.as(ExprSyntax.self) { item = .expr(expr) + } else if let token = self.syntax.as(TokenSyntax.self) { + // Wrap TokenSyntax in DeclReferenceExprSyntax and then in ExprSyntax + let expr = ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier(token.text))) + item = .expr(expr) + } else if let switchCase = self.syntax.as(SwitchCaseSyntax.self) { + // Wrap SwitchCaseSyntax in a SwitchExprSyntax and treat it as an expression + // This is a fallback for when SwitchCase is used standalone + let switchExpr = SwitchExprSyntax( + switchKeyword: .keyword(.switch, trailingTrivia: .space), + subject: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("_"))), + leftBrace: .leftBraceToken(leadingTrivia: .space, trailingTrivia: .newline), + cases: SwitchCaseListSyntax([SwitchCaseListSyntax.Element(switchCase)]), + rightBrace: .rightBraceToken(leadingTrivia: .newline) + ) + item = .expr(ExprSyntax(switchExpr)) } else { fatalError( "Unsupported syntax type at top level: \(type(of: self.syntax)) generating from \(self)") diff --git a/Sources/SyntaxKit/CommentedCodeBlock.swift b/Sources/SyntaxKit/CommentedCodeBlock.swift index 351a5df..79f6ef3 100644 --- a/Sources/SyntaxKit/CommentedCodeBlock.swift +++ b/Sources/SyntaxKit/CommentedCodeBlock.swift @@ -33,10 +33,10 @@ import SwiftSyntax // MARK: - Wrapper `CodeBlock` that injects leading trivia internal struct CommentedCodeBlock: CodeBlock { - let base: CodeBlock - let lines: [Line] + internal let base: CodeBlock + internal let lines: [Line] - var syntax: SyntaxProtocol { + internal var syntax: SyntaxProtocol { // Shortcut if there are no comment lines guard !lines.isEmpty else { return base.syntax } diff --git a/Sources/SyntaxKit/Enum.swift b/Sources/SyntaxKit/Enum.swift index 82e6dd4..65a9183 100644 --- a/Sources/SyntaxKit/Enum.swift +++ b/Sources/SyntaxKit/Enum.swift @@ -145,33 +145,43 @@ public struct Enum: CodeBlock { /// A Swift `case` declaration inside an `enum`. public struct EnumCase: CodeBlock { private let name: String - private var value: String? - private var intValue: Int? + private var literalValue: Literal? /// Creates a `case` declaration. /// - Parameter name: The name of the case. public init(_ name: String) { self.name = name + self.literalValue = nil } - /// Sets the raw value of the case to a string. - /// - Parameter value: The string value. + /// Sets the raw value of the case to a Literal. + /// - Parameter value: The literal value. /// - Returns: A copy of the case with the raw value set. - public func equals(_ value: String) -> Self { + public func equals(_ value: Literal) -> Self { var copy = self - copy.value = value - copy.intValue = nil + copy.literalValue = value return copy } - /// Sets the raw value of the case to an integer. + /// Sets the raw value of the case to a string (for backward compatibility). + /// - Parameter value: The string value. + /// - Returns: A copy of the case with the raw value set. + public func equals(_ value: String) -> Self { + self.equals(.string(value)) + } + + /// Sets the raw value of the case to an integer (for backward compatibility). /// - Parameter value: The integer value. /// - Returns: A copy of the case with the raw value set. public func equals(_ value: Int) -> Self { - var copy = self - copy.value = nil - copy.intValue = value - return copy + self.equals(.integer(value)) + } + + /// Sets the raw value of the case to a float (for backward compatibility). + /// - Parameter value: The float value. + /// - Returns: A copy of the case with the raw value set. + public func equals(_ value: Double) -> Self { + self.equals(.float(value)) } public var syntax: SyntaxProtocol { @@ -179,22 +189,40 @@ public struct EnumCase: CodeBlock { let identifier = TokenSyntax.identifier(name, trailingTrivia: .space) var initializer: InitializerClauseSyntax? - if let value = value { - initializer = InitializerClauseSyntax( - equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space), - value: StringLiteralExprSyntax( - openingQuote: .stringQuoteToken(), - segments: StringLiteralSegmentListSyntax([ - .stringSegment(StringSegmentSyntax(content: .stringSegment(value))) - ]), - closingQuote: .stringQuoteToken() + if let literal = literalValue { + switch literal { + case .string(let value): + initializer = InitializerClauseSyntax( + equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space), + value: StringLiteralExprSyntax( + openingQuote: .stringQuoteToken(), + segments: StringLiteralSegmentListSyntax([ + .stringSegment(StringSegmentSyntax(content: .stringSegment(value))) + ]), + closingQuote: .stringQuoteToken() + ) ) - ) - } else if let intValue = intValue { - initializer = InitializerClauseSyntax( - equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space), - value: IntegerLiteralExprSyntax(digits: .integerLiteral(String(intValue))) - ) + case .float(let value): + initializer = InitializerClauseSyntax( + equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space), + value: FloatLiteralExprSyntax(literal: .floatLiteral(String(value))) + ) + case .integer(let value): + initializer = InitializerClauseSyntax( + equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space), + value: IntegerLiteralExprSyntax(digits: .integerLiteral(String(value))) + ) + case .nil: + initializer = InitializerClauseSyntax( + equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space), + value: NilLiteralExprSyntax(nilKeyword: .keyword(.nil)) + ) + case .boolean(let value): + initializer = InitializerClauseSyntax( + equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space), + value: BooleanLiteralExprSyntax(literal: value ? .keyword(.true) : .keyword(.false)) + ) + } } return EnumCaseDeclSyntax( diff --git a/Sources/SyntaxKit/Group.swift b/Sources/SyntaxKit/Group.swift index 7b3e824..329574a 100644 --- a/Sources/SyntaxKit/Group.swift +++ b/Sources/SyntaxKit/Group.swift @@ -31,7 +31,7 @@ import SwiftSyntax /// A group of code blocks. public struct Group: CodeBlock { - let members: [CodeBlock] + internal let members: [CodeBlock] /// Creates a group of code blocks. /// - Parameter content: A ``CodeBlockBuilder`` that provides the members of the group. diff --git a/Sources/SyntaxKit/Let.swift b/Sources/SyntaxKit/Let.swift index cd2d46d..354a2d7 100644 --- a/Sources/SyntaxKit/Let.swift +++ b/Sources/SyntaxKit/Let.swift @@ -31,8 +31,8 @@ import SwiftSyntax /// A Swift `let` declaration for use in an `if` statement. public struct Let: CodeBlock { - let name: String - let value: String + internal let name: String + internal let value: String /// Creates a `let` declaration for an `if` statement. /// - Parameters: diff --git a/Sources/SyntaxKit/Parameter.swift b/Sources/SyntaxKit/Parameter.swift index 75703c2..3090d6c 100644 --- a/Sources/SyntaxKit/Parameter.swift +++ b/Sources/SyntaxKit/Parameter.swift @@ -33,10 +33,10 @@ import SwiftSyntax /// A parameter for a function or initializer. public struct Parameter: CodeBlock { - let name: String - let type: String - let defaultValue: String? - let isUnnamed: Bool + internal let name: String + internal let type: String + internal let defaultValue: String? + internal let isUnnamed: Bool internal var attributes: [AttributeInfo] = [] /// Creates a parameter for a function or initializer. diff --git a/Sources/SyntaxKit/ParameterExp.swift b/Sources/SyntaxKit/ParameterExp.swift index 02274e8..87294a8 100644 --- a/Sources/SyntaxKit/ParameterExp.swift +++ b/Sources/SyntaxKit/ParameterExp.swift @@ -31,8 +31,8 @@ import SwiftSyntax /// A parameter for a function call. public struct ParameterExp: CodeBlock { - let name: String - let value: String + internal let name: String + internal let value: String /// Creates a parameter for a function call. /// - Parameters: diff --git a/Sources/SyntaxKit/Parenthesized.swift b/Sources/SyntaxKit/Parenthesized.swift new file mode 100644 index 0000000..be8959b --- /dev/null +++ b/Sources/SyntaxKit/Parenthesized.swift @@ -0,0 +1,55 @@ +// +// Parenthesized.swift +// SyntaxKit +// +// Created by Leo Dion. +// Copyright © 2025 BrightDigit. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +import SwiftSyntax + +/// A code block that wraps its content in parentheses. +public struct Parenthesized: CodeBlock { + private let content: CodeBlock + + /// Creates a parenthesized code block. + /// - Parameter content: The code block to wrap in parentheses. + public init(@CodeBlockBuilderResult _ content: () -> [CodeBlock]) { + let blocks = content() + precondition(blocks.count == 1, "Parenthesized expects exactly one code block.") + self.content = blocks[0] + } + + public var syntax: SyntaxProtocol { + ExprSyntax( + TupleExprSyntax( + leftParen: .leftParenToken(), + elements: LabeledExprListSyntax([ + LabeledExprSyntax(expression: content.expr) + ]), + rightParen: .rightParenToken() + ) + ) + } +} diff --git a/Sources/SyntaxKit/VariableExp.swift b/Sources/SyntaxKit/VariableExp.swift index 5616290..fb55e86 100644 --- a/Sources/SyntaxKit/VariableExp.swift +++ b/Sources/SyntaxKit/VariableExp.swift @@ -31,7 +31,7 @@ import SwiftSyntax /// An expression that refers to a variable. public struct VariableExp: CodeBlock { - let name: String + internal let name: String /// Creates a variable expression. /// - Parameter name: The name of the variable. @@ -71,8 +71,8 @@ public struct VariableExp: CodeBlock { /// An expression that accesses a property on a base expression. public struct PropertyAccessExp: CodeBlock { - let baseName: String - let propertyName: String + internal let baseName: String + internal let propertyName: String /// Creates a property access expression. /// - Parameters: @@ -97,9 +97,9 @@ public struct PropertyAccessExp: CodeBlock { /// An expression that calls a function. public struct FunctionCallExp: CodeBlock { - let baseName: String - let methodName: String - let parameters: [ParameterExp] + internal let baseName: String + internal let methodName: String + internal let parameters: [ParameterExp] /// Creates a function call expression. /// - Parameters: diff --git a/Sources/SyntaxKit/parser/TokenVisitor.swift b/Sources/SyntaxKit/parser/TokenVisitor.swift index aad7ca5..f377831 100644 --- a/Sources/SyntaxKit/parser/TokenVisitor.swift +++ b/Sources/SyntaxKit/parser/TokenVisitor.swift @@ -30,9 +30,9 @@ import Foundation @_spi(RawSyntax) import SwiftSyntax -final class TokenVisitor: SyntaxRewriter { +internal final class TokenVisitor: SyntaxRewriter { // var list = [String]() - var tree = [TreeNode]() + internal var tree = [TreeNode]() private var current: TreeNode! private var index = 0 @@ -40,14 +40,14 @@ final class TokenVisitor: SyntaxRewriter { private let locationConverter: SourceLocationConverter private let showMissingTokens: Bool - init(locationConverter: SourceLocationConverter, showMissingTokens: Bool) { + internal init(locationConverter: SourceLocationConverter, showMissingTokens: Bool) { self.locationConverter = locationConverter self.showMissingTokens = showMissingTokens super.init(viewMode: showMissingTokens ? .all : .sourceAccurate) } // swiftlint:disable:next cyclomatic_complexity function_body_length - override func visitPre(_ node: Syntax) { + override internal func visitPre(_ node: Syntax) { let syntaxNodeType = node.syntaxNodeType let className: String @@ -177,7 +177,7 @@ final class TokenVisitor: SyntaxRewriter { current = treeNode } - override func visit(_ token: TokenSyntax) -> TokenSyntax { + override internal func visit(_ token: TokenSyntax) -> TokenSyntax { current.text = token .text .escapeHTML() @@ -199,7 +199,7 @@ final class TokenVisitor: SyntaxRewriter { return token } - override func visitPost(_ node: Syntax) { + override internal func visitPost(_ node: Syntax) { if let parent = current.parent { current = tree[parent] } else { diff --git a/Sources/SyntaxKit/parser/TreeNode.swift b/Sources/SyntaxKit/parser/TreeNode.swift index 4c35089..a83ec0d 100644 --- a/Sources/SyntaxKit/parser/TreeNode.swift +++ b/Sources/SyntaxKit/parser/TreeNode.swift @@ -29,16 +29,16 @@ import Foundation -final class TreeNode: Codable { - let id: Int - var parent: Int? +internal final class TreeNode: Codable { + internal let id: Int + internal var parent: Int? - var text: String - var range = Range( + internal var text: String + internal var range = Range( startRow: 0, startColumn: 0, endRow: 0, endColumn: 0) - var structure = [StructureProperty]() - var type: SyntaxType - var token: Token? + internal var structure = [StructureProperty]() + internal var type: SyntaxType + internal var token: Token? init(id: Int, text: String, range: Range, type: SyntaxType) { self.id = id @@ -71,11 +71,11 @@ extension TreeNode: CustomStringConvertible { } } -struct Range: Codable, Equatable { - let startRow: Int - let startColumn: Int - let endRow: Int - let endColumn: Int +internal struct Range: Codable, Equatable { + internal let startRow: Int + internal let startColumn: Int + internal let endRow: Int + internal let endColumn: Int } extension Range: CustomStringConvertible { @@ -91,10 +91,10 @@ extension Range: CustomStringConvertible { } } -struct StructureProperty: Codable, Equatable { - let name: String - let value: StructureValue? - let ref: String? +internal struct StructureProperty: Codable, Equatable { + internal let name: String + internal let value: StructureValue? + internal let ref: String? init(name: String, value: StructureValue? = nil, ref: String? = nil) { self.name = name.escapeHTML() @@ -115,9 +115,9 @@ extension StructureProperty: CustomStringConvertible { } } -struct StructureValue: Codable, Equatable { - let text: String - let kind: String? +internal struct StructureValue: Codable, Equatable { + internal let text: String + internal let kind: String? init(text: String, kind: String? = nil) { self.text = text.escapeHTML().replaceHTMLWhitespacesToSymbols() @@ -136,7 +136,7 @@ extension StructureValue: CustomStringConvertible { } } -enum SyntaxType: String, Codable { +internal enum SyntaxType: String, Codable { case decl case expr case pattern @@ -145,10 +145,10 @@ enum SyntaxType: String, Codable { case other } -struct Token: Codable, Equatable { - let kind: String - var leadingTrivia: String - var trailingTrivia: String +internal struct Token: Codable, Equatable { + internal let kind: String + internal var leadingTrivia: String + internal var trailingTrivia: String init(kind: String, leadingTrivia: String, trailingTrivia: String) { self.kind = kind.escapeHTML() diff --git a/Sources/skit/main.swift b/Sources/skit/main.swift index d7952fe..b500a63 100644 --- a/Sources/skit/main.swift +++ b/Sources/skit/main.swift @@ -31,7 +31,8 @@ import Foundation import SyntaxKit // Read Swift code from stdin -let code = String(data: FileHandle.standardInput.readDataToEndOfFile(), encoding: .utf8) ?? "" +internal let code = + String(data: FileHandle.standardInput.readDataToEndOfFile(), encoding: .utf8) ?? "" do { // Parse the code using SyntaxKit diff --git a/Tests/SyntaxKitTests/AssertionMigrationTests.swift b/Tests/SyntaxKitTests/AssertionMigrationTests.swift index a6d03f2..3c8d824 100644 --- a/Tests/SyntaxKitTests/AssertionMigrationTests.swift +++ b/Tests/SyntaxKitTests/AssertionMigrationTests.swift @@ -4,10 +4,10 @@ import Testing /// Tests specifically focused on assertion migration from XCTest to Swift Testing /// Ensures all assertion patterns from the original tests work correctly with #expect() -struct AssertionMigrationTests { +internal struct AssertionMigrationTests { // MARK: - XCTAssertEqual Migration Tests - @Test func testEqualityAssertionMigration() throws { + @Test internal func testEqualityAssertionMigration() throws { // Test the most common migration: XCTAssertEqual -> #expect(a == b) let function = Function("test", returns: "String") { Return { @@ -29,7 +29,7 @@ struct AssertionMigrationTests { // MARK: - XCTAssertFalse Migration Tests - @Test func testFalseAssertionMigration() { + @Test internal func testFalseAssertionMigration() { let syntax = Group { Variable(.let, name: "test", type: "String", equals: "\"value\"") } @@ -42,7 +42,7 @@ struct AssertionMigrationTests { // MARK: - Complex Assertion Migration Tests - @Test func testNormalizedStringComparisonMigration() throws { + @Test internal func testNormalizedStringComparisonMigration() throws { let blackjackCard = Struct("Card") { Enum("Suit") { EnumCase("hearts").equals("♡") @@ -68,7 +68,7 @@ struct AssertionMigrationTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testMultipleAssertionsInSingleTest() { + @Test internal func testMultipleAssertionsInSingleTest() { let generated = "struct Test { var value: Int }" // Test multiple assertions in one test method diff --git a/Tests/SyntaxKitTests/AttributeTests.swift b/Tests/SyntaxKitTests/AttributeTests.swift index 717811a..3c70141 100644 --- a/Tests/SyntaxKitTests/AttributeTests.swift +++ b/Tests/SyntaxKitTests/AttributeTests.swift @@ -30,9 +30,9 @@ import SyntaxKit import Testing -@Suite struct AttributeTests { +@Suite internal struct AttributeTests { @Test("Class with attribute generates correct syntax") - func testClassWithAttribute() throws { + internal func testClassWithAttribute() throws { let classDecl = Class("Foo") { Variable(.var, name: "bar", type: "String", equals: "bar") }.attribute("objc") @@ -43,7 +43,7 @@ import Testing } @Test("Function with attribute generates correct syntax") - func testFunctionWithAttribute() throws { + internal func testFunctionWithAttribute() throws { let function = Function("bar") { Variable(.let, name: "message", type: "String", equals: "bar") }.attribute("available") @@ -54,7 +54,7 @@ import Testing } @Test("Variable with attribute generates correct syntax") - func testVariableWithAttribute() throws { + internal func testVariableWithAttribute() throws { let variable = Variable(.var, name: "bar", type: "String", equals: "bar") .attribute("Published") @@ -64,7 +64,7 @@ import Testing } @Test("Multiple attributes on class generates correct syntax") - func testMultipleAttributesOnClass() throws { + internal func testMultipleAttributesOnClass() throws { let classDecl = Class("Foo") { Variable(.var, name: "bar", type: "String", equals: "bar") } @@ -78,7 +78,7 @@ import Testing } @Test("Attribute with arguments generates correct syntax") - func testAttributeWithArguments() throws { + internal func testAttributeWithArguments() throws { let attribute = Attribute("available", arguments: ["iOS", "17.0", "*"]) let generated = attribute.syntax.description @@ -89,7 +89,7 @@ import Testing } @Test("Attribute with single argument generates correct syntax") - func testAttributeWithSingleArgument() throws { + internal func testAttributeWithSingleArgument() throws { let attribute = Attribute("available", argument: "iOS 17.0") let generated = attribute.syntax.description @@ -98,7 +98,7 @@ import Testing } @Test("Comprehensive attribute example generates correct syntax") - func testComprehensiveAttributeExample() throws { + internal func testComprehensiveAttributeExample() throws { let classDecl = Class("Foo") { Variable(.var, name: "bar", type: "String", equals: "bar") .attribute("Published") @@ -127,7 +127,7 @@ import Testing } @Test("Function with attribute arguments generates correct syntax") - func testFunctionWithAttributeArguments() throws { + internal func testFunctionWithAttributeArguments() throws { let function = Function("bar") { Variable(.let, name: "message", type: "String", equals: "bar") }.attribute("available", arguments: ["iOS", "17.0", "*"]) @@ -141,7 +141,7 @@ import Testing } @Test("Class with attribute arguments generates correct syntax") - func testClassWithAttributeArguments() throws { + internal func testClassWithAttributeArguments() throws { let classDecl = Class("Foo") { Variable(.var, name: "bar", type: "String", equals: "bar") }.attribute("available", arguments: ["iOS", "17.0"]) @@ -154,7 +154,7 @@ import Testing } @Test("Variable with attribute arguments generates correct syntax") - func testVariableWithAttributeArguments() throws { + internal func testVariableWithAttributeArguments() throws { let variable = Variable(.var, name: "bar", type: "String", equals: "bar") .attribute("available", arguments: ["iOS", "17.0"]) @@ -166,7 +166,7 @@ import Testing } @Test("Parameter with attribute generates correct syntax") - func testParameterWithAttribute() throws { + internal func testParameterWithAttribute() throws { let function = Function("process") { Parameter(name: "data", type: "Data") .attribute("escaping") @@ -181,7 +181,7 @@ import Testing } @Test("Parameter with attribute arguments generates correct syntax") - func testParameterWithAttributeArguments() throws { + internal func testParameterWithAttributeArguments() throws { let function = Function("validate") { Parameter(name: "input", type: "String") .attribute("available", arguments: ["iOS", "17.0"]) diff --git a/Tests/SyntaxKitTests/BasicTests.swift b/Tests/SyntaxKitTests/BasicTests.swift index bfc9433..2fb77b3 100644 --- a/Tests/SyntaxKitTests/BasicTests.swift +++ b/Tests/SyntaxKitTests/BasicTests.swift @@ -2,8 +2,8 @@ import Testing @testable import SyntaxKit -struct BasicTests { - @Test func testBlackjackCardExample() throws { +internal struct BasicTests { + @Test internal func testBlackjackCardExample() throws { let blackjackCard = Struct("BlackjackCard") { Enum("Suit") { EnumCase("spades").equals("♠") diff --git a/Tests/SyntaxKitTests/BlackjackTests.swift b/Tests/SyntaxKitTests/BlackjackTests.swift index 16ab0d0..0d71ceb 100644 --- a/Tests/SyntaxKitTests/BlackjackTests.swift +++ b/Tests/SyntaxKitTests/BlackjackTests.swift @@ -2,8 +2,8 @@ import Testing @testable import SyntaxKit -struct BlackjackTests { - @Test func testBlackjackCardExample() throws { +internal struct BlackjackTests { + @Test internal func testBlackjackCardExample() throws { let syntax = Struct("BlackjackCard") { Enum("Suit") { EnumCase("spades").equals("♠") @@ -71,7 +71,7 @@ struct BlackjackTests { } // swiftlint:disable:next function_body_length - @Test func testFullBlackjackCardExample() throws { + @Test internal func testFullBlackjackCardExample() throws { // swiftlint:disable:next closure_body_length let syntax = Struct("BlackjackCard") { Enum("Suit") { diff --git a/Tests/SyntaxKitTests/ClassTests.swift b/Tests/SyntaxKitTests/ClassTests.swift index 5b967d0..8c5bc1b 100644 --- a/Tests/SyntaxKitTests/ClassTests.swift +++ b/Tests/SyntaxKitTests/ClassTests.swift @@ -2,8 +2,8 @@ import Testing @testable import SyntaxKit -struct ClassTests { - @Test func testClassWithInheritance() { +internal struct ClassTests { + @Test internal func testClassWithInheritance() { let carClass = Class("Car") { Variable(.var, name: "brand", type: "String") Variable(.var, name: "numberOfWheels", type: "Int") @@ -21,7 +21,7 @@ struct ClassTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testEmptyClass() { + @Test internal func testEmptyClass() { let emptyClass = Class("EmptyClass") {} let expected = """ @@ -34,7 +34,7 @@ struct ClassTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testClassWithGenerics() { + @Test internal func testClassWithGenerics() { let genericClass = Class("Container") { Variable(.var, name: "value", type: "T") }.generic("T") @@ -50,7 +50,7 @@ struct ClassTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testClassWithMultipleGenerics() { + @Test internal func testClassWithMultipleGenerics() { let multiGenericClass = Class("Pair") { Variable(.var, name: "first", type: "T") Variable(.var, name: "second", type: "U") @@ -68,7 +68,7 @@ struct ClassTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testFinalClass() { + @Test internal func testFinalClass() { let finalClass = Class("FinalClass") { Variable(.var, name: "value", type: "String") }.final() @@ -84,7 +84,7 @@ struct ClassTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testClassWithMultipleInheritance() { + @Test internal func testClassWithMultipleInheritance() { let classWithMultipleInheritance = Class("AdvancedVehicle") { Variable(.var, name: "speed", type: "Int") }.inherits("Vehicle") @@ -100,7 +100,7 @@ struct ClassTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testClassWithGenericsAndInheritance() { + @Test internal func testClassWithGenericsAndInheritance() { let genericClassWithInheritance = Class("GenericContainer") { Variable(.var, name: "items", type: "[T]") }.generic("T").inherits("Collection") @@ -116,7 +116,7 @@ struct ClassTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testFinalClassWithInheritanceAndGenerics() { + @Test internal func testFinalClassWithInheritanceAndGenerics() { let finalGenericClass = Class("FinalGenericClass") { Variable(.var, name: "value", type: "T") }.generic("T").inherits("BaseClass").final() @@ -132,7 +132,7 @@ struct ClassTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testClassWithFunctions() { + @Test internal func testClassWithFunctions() { let classWithFunctions = Class("Calculator") { Function("add", returns: "Int") { Parameter(name: "a", type: "Int") diff --git a/Tests/SyntaxKitTests/CodeStyleMigrationTests.swift b/Tests/SyntaxKitTests/CodeStyleMigrationTests.swift index 08aea89..8a9daa8 100644 --- a/Tests/SyntaxKitTests/CodeStyleMigrationTests.swift +++ b/Tests/SyntaxKitTests/CodeStyleMigrationTests.swift @@ -4,10 +4,10 @@ import Testing /// Tests for code style and API simplification changes introduced during Swift Testing migration /// Validates the simplified Swift APIs and formatting changes -struct CodeStyleMigrationTests { +internal struct CodeStyleMigrationTests { // MARK: - CharacterSet Simplification Tests - @Test func testCharacterSetSimplification() { + @Test internal func testCharacterSetSimplification() { // Test that .whitespacesAndNewlines works instead of CharacterSet.whitespacesAndNewlines let testString = "\n test content \n\t" @@ -20,7 +20,7 @@ struct CodeStyleMigrationTests { // MARK: - Indentation and Formatting Tests - @Test func testConsistentIndentationInMigratedCode() throws { + @Test internal func testConsistentIndentationInMigratedCode() throws { // Test that the indentation changes in the migrated code work correctly let syntax = Struct("IndentationTest") { Variable(.let, name: "property1", type: "String") diff --git a/Tests/SyntaxKitTests/CommentTests.swift b/Tests/SyntaxKitTests/CommentTests.swift index 331852e..e56fdcd 100644 --- a/Tests/SyntaxKitTests/CommentTests.swift +++ b/Tests/SyntaxKitTests/CommentTests.swift @@ -2,9 +2,9 @@ import Testing @testable import SyntaxKit -struct CommentTests { +internal struct CommentTests { // swiftlint:disable:next function_body_length - @Test func testCommentInjection() { + @Test internal func testCommentInjection() { // swiftlint:disable:next closure_body_length let syntax = Group { Struct("Card") { diff --git a/Tests/SyntaxKitTests/EdgeCaseTests.swift b/Tests/SyntaxKitTests/EdgeCaseTests.swift new file mode 100644 index 0000000..a2b63b6 --- /dev/null +++ b/Tests/SyntaxKitTests/EdgeCaseTests.swift @@ -0,0 +1,288 @@ +import Testing + +@testable import SyntaxKit + +internal struct EdgeCaseTests { + // MARK: - Error Handling Tests + + @Test("Infix with wrong number of operands throws fatal error") + internal func testInfixWrongOperandCount() { + // This test documents the expected behavior + // In a real scenario, this would cause a fatal error + // We can't easily test fatalError in unit tests, but we can document it + let infix = Infix("+") { + // Only one operand - should cause fatal error + VariableExp("x") + } + + // The fatal error would occur when accessing .syntax + // This test documents the expected behavior + #expect(true) // Placeholder - fatal errors can't be easily tested + } + + @Test("Return with no expressions throws fatal error") + internal func testReturnWithNoExpressions() { + // This test documents the expected behavior + // In a real scenario, this would cause a fatal error + let returnStmt = Return { + // Empty - should cause fatal error + } + + // The fatal error would occur when accessing .syntax + // This test documents the expected behavior + #expect(true) // Placeholder - fatal errors can't be easily tested + } + + // MARK: - Switch and Case Tests + + @Test("Switch with multiple patterns generates correct syntax") + internal func testSwitchWithMultiplePatterns() throws { + let switchStmt = Switch("value") { + SwitchCase("1") { + Return { VariableExp("one") } + } + SwitchCase("2") { + Return { VariableExp("two") } + } + } + + let generated = switchStmt.generateCode() + #expect(generated.contains("switch value")) + #expect(generated.contains("case 1:")) + #expect(generated.contains("case 2:")) + } + + @Test("SwitchCase with multiple patterns generates correct syntax") + internal func testSwitchCaseWithMultiplePatterns() throws { + let switchCase = SwitchCase("1", "2", "3") { + Return { VariableExp("number") } + } + + let generated = switchCase.generateCode() + #expect(generated.contains("case 1, 2, 3:")) + } + + // MARK: - Complex Expression Tests + + @Test("Infix with complex expressions generates correct syntax") + internal func testInfixWithComplexExpressions() throws { + let infix = Infix("*") { + Parenthesized { + Infix("+") { + VariableExp("a") + VariableExp("b") + } + } + Parenthesized { + Infix("-") { + VariableExp("c") + VariableExp("d") + } + } + } + + let generated = infix.generateCode() + #expect(generated.contains("(a + b) * (c - d)")) + } + + @Test("Return with VariableExp generates correct syntax") + internal func testReturnWithVariableExp() throws { + let returnStmt = Return { + VariableExp("result") + } + + let generated = returnStmt.generateCode() + #expect(generated.contains("return result")) + } + + @Test("Return with complex expression generates correct syntax") + internal func testReturnWithComplexExpression() throws { + let returnStmt = Return { + Infix("+") { + VariableExp("a") + VariableExp("b") + } + } + + let generated = returnStmt.generateCode() + #expect(generated.contains("return a + b")) + } + + // MARK: - CodeBlock Expression Tests + + @Test("CodeBlock expr with TokenSyntax wraps in DeclReferenceExpr") + internal func testCodeBlockExprWithTokenSyntax() throws { + let variableExp = VariableExp("x") + let expr = variableExp.expr + + let generated = expr.description + #expect(generated.contains("x")) + } + + // MARK: - Code Generation Edge Cases + + @Test("CodeBlock generateCode with CodeBlockItemListSyntax") + internal func testCodeBlockGenerateCodeWithItemList() throws { + let group = Group { + Variable(.let, name: "x", type: "Int", equals: "1") + Variable(.let, name: "y", type: "Int", equals: "2") + } + + let generated = group.generateCode() + #expect(generated.contains("let x : Int = 1")) + #expect(generated.contains("let y : Int = 2")) + } + + @Test("CodeBlock generateCode with single declaration") + internal func testCodeBlockGenerateCodeWithSingleDeclaration() throws { + let variable = Variable(.let, name: "x", type: "Int", equals: "1") + + let generated = variable.generateCode() + #expect(generated.contains("let x : Int = 1")) + } + + @Test("CodeBlock generateCode with single statement") + internal func testCodeBlockGenerateCodeWithSingleStatement() throws { + let assignment = Assignment("x", "42") + + let generated = assignment.generateCode() + #expect(generated.contains("x = 42")) + } + + @Test("CodeBlock generateCode with single expression") + internal func testCodeBlockGenerateCodeWithSingleExpression() throws { + let variableExp = VariableExp("x") + + let generated = variableExp.generateCode() + #expect(generated.contains("x")) + } + + // MARK: - Complex Type Tests + + @Test("TypeAlias with complex nested types") + internal func testTypeAliasWithComplexNestedTypes() throws { + let typeAlias = TypeAlias("ComplexType", equals: "Array>>") + + let generated = typeAlias.generateCode() + #expect( + generated.normalize().contains( + "typealias ComplexType = Array>>".normalize())) + } + + @Test("TypeAlias with multiple generic parameters") + internal func testTypeAliasWithMultipleGenericParameters() throws { + let typeAlias = TypeAlias("Result", equals: "Result") + + let generated = typeAlias.generateCode().normalize() + #expect(generated.contains("typealias Result = Result".normalize())) + } + + // MARK: - Function Parameter Tests + + @Test("Function with unnamed parameter generates correct syntax") + internal func testFunctionWithUnnamedParameter() throws { + let function = Function("process") { + Parameter(name: "data", type: "Data", isUnnamed: true) + } _: { + Variable(.let, name: "result", type: "String", equals: "processed") + } + + let generated = function.generateCode() + #expect(generated.contains("func process(_ data: Data)")) + } + + @Test("Function with parameter default value generates correct syntax") + internal func testFunctionWithParameterDefaultValue() throws { + let function = Function("greet") { + Parameter(name: "name", type: "String", defaultValue: "\"World\"") + } _: { + Variable(.let, name: "message", type: "String", equals: "greeting") + } + + let generated = function.generateCode() + #expect(generated.contains("func greet(name: String = \"World\")")) + } + + // MARK: - Enum Case Tests + + @Test("EnumCase with string raw value generates correct syntax") + internal func testEnumCaseWithStringRawValue() throws { + let enumDecl = Enum("Status") { + EnumCase("active").equals(Literal.string("active")) + EnumCase("inactive").equals(Literal.string("inactive")) + } + + let generated = enumDecl.generateCode().normalize() + #expect(generated.contains("case active = \"active\"")) + #expect(generated.contains("case inactive = \"inactive\"")) + } + + @Test("EnumCase with double raw value generates correct syntax") + internal func testEnumCaseWithDoubleRawValue() throws { + let enumDecl = Enum("Precision") { + EnumCase("low").equals(Literal.float(0.1)) + EnumCase("high").equals(Literal.float(0.001)) + } + + let generated = enumDecl.generateCode().normalize() + #expect(generated.contains("case low = 0.1")) + #expect(generated.contains("case high = 0.001")) + } + + // MARK: - Computed Property Tests + + @Test("ComputedProperty with complex return expression") + internal func testComputedPropertyWithComplexReturn() throws { + let computedProperty = ComputedProperty("description", type: "String") { + Return { + VariableExp("name").call("appending") { + ParameterExp(name: "", value: "\" - \" + String(count)") + } + } + } + + let generated = computedProperty.generateCode().normalize() + #expect(generated.contains("var description: String")) + #expect(generated.contains("return name.appending(\" - \" + String(count))")) + } + + // MARK: - Comment Integration Tests + + @Test("ComputedProperty with comments generates correct syntax") + internal func testComputedPropertyWithComments() throws { + let computedProperty = ComputedProperty("formattedName", type: "String") { + Return { + VariableExp("name").property("uppercased") + } + }.comment { + Line(.doc, "Returns the name in uppercase format") + } + + let generated = computedProperty.generateCode() + #expect(generated.contains("/// Returns the name in uppercase format")) + #expect(generated.contains("var formattedName : String")) + } + + // MARK: - Literal Tests + + @Test("Literal with nil generates correct syntax") + internal func testLiteralWithNil() throws { + let literal = Literal.nil + let generated = literal.generateCode() + #expect(generated.contains("nil")) + } + + @Test("Literal with boolean generates correct syntax") + internal func testLiteralWithBoolean() throws { + let literal = Literal.boolean(true) + let generated = literal.generateCode() + #expect(generated.contains("true")) + } + + @Test("Literal with float generates correct syntax") + internal func testLiteralWithFloat() throws { + let literal = Literal.float(3.14159) + let generated = literal.generateCode() + #expect(generated.contains("3.14159")) + } +} diff --git a/Tests/SyntaxKitTests/ExtensionTests.swift b/Tests/SyntaxKitTests/ExtensionTests.swift index b04190d..ee57490 100644 --- a/Tests/SyntaxKitTests/ExtensionTests.swift +++ b/Tests/SyntaxKitTests/ExtensionTests.swift @@ -31,10 +31,10 @@ import Testing @testable import SyntaxKit -struct ExtensionTests { +internal struct ExtensionTests { // MARK: - Basic Extension Tests - @Test func testBasicExtension() { + @Test internal func testBasicExtension() { let extensionDecl = Extension("String") { Variable(.let, name: "test", type: "Int", equals: "42") } @@ -45,7 +45,7 @@ struct ExtensionTests { #expect(generated.contains("let test: Int = 42")) } - @Test func testExtensionWithMultipleMembers() { + @Test internal func testExtensionWithMultipleMembers() { let extensionDecl = Extension("Array") { Variable(.let, name: "isEmpty", type: "Bool", equals: "true") Variable(.let, name: "count", type: "Int", equals: "0") @@ -60,7 +60,7 @@ struct ExtensionTests { // MARK: - Extension with Inheritance Tests - @Test func testExtensionWithSingleInheritance() { + @Test internal func testExtensionWithSingleInheritance() { let extensionDecl = Extension("MyEnum") { TypeAlias("MappedType", equals: "String") }.inherits("MappedValueRepresentable") @@ -71,7 +71,7 @@ struct ExtensionTests { #expect(generated.contains("typealias MappedType = String")) } - @Test func testExtensionWithMultipleInheritance() { + @Test internal func testExtensionWithMultipleInheritance() { let extensionDecl = Extension("MyEnum") { TypeAlias("MappedType", equals: "String") }.inherits("MappedValueRepresentable", "MappedValueRepresented") @@ -83,7 +83,7 @@ struct ExtensionTests { #expect(generated.contains("typealias MappedType = String")) } - @Test func testExtensionWithoutInheritance() { + @Test internal func testExtensionWithoutInheritance() { let extensionDecl = Extension("MyType") { Variable(.let, name: "constant", type: "String", equals: "value") } @@ -97,7 +97,7 @@ struct ExtensionTests { // MARK: - Extension with Complex Members Tests - @Test func testExtensionWithStaticVariables() { + @Test internal func testExtensionWithStaticVariables() { let array: [String] = ["a", "b", "c"] let dict: [Int: String] = [1: "one", 2: "two"] @@ -118,7 +118,7 @@ struct ExtensionTests { #expect(generated.contains("2: \"two\"")) } - @Test func testExtensionWithFunctions() { + @Test internal func testExtensionWithFunctions() { let extensionDecl = Extension("String") { Function("uppercasedFirst", returns: "String") { Return { @@ -136,7 +136,7 @@ struct ExtensionTests { // MARK: - Edge Cases - @Test func testExtensionWithEmptyBody() { + @Test internal func testExtensionWithEmptyBody() { let extensionDecl = Extension("EmptyType") { // Empty body } @@ -148,7 +148,7 @@ struct ExtensionTests { #expect(generated.contains("}")) } - @Test func testExtensionWithSpecialCharactersInName() { + @Test internal func testExtensionWithSpecialCharactersInName() { let extensionDecl = Extension("MyType") { Variable(.let, name: "generic", type: "T", equals: "nil") } @@ -159,7 +159,7 @@ struct ExtensionTests { #expect(generated.contains("let generic: T = nil")) } - @Test func testInheritsMethodReturnsNewInstance() { + @Test internal func testInheritsMethodReturnsNewInstance() { let original = Extension("Test") { Variable(.let, name: "value", type: "Int", equals: "42") } diff --git a/Tests/SyntaxKitTests/FrameworkCompatibilityTests.swift b/Tests/SyntaxKitTests/FrameworkCompatibilityTests.swift index d16bdc0..33f0de8 100644 --- a/Tests/SyntaxKitTests/FrameworkCompatibilityTests.swift +++ b/Tests/SyntaxKitTests/FrameworkCompatibilityTests.swift @@ -4,17 +4,17 @@ import Testing /// Tests to ensure compatibility and feature parity between XCTest and Swift Testing /// Validates that the migration maintains all testing capabilities -struct FrameworkCompatibilityTests { +internal struct FrameworkCompatibilityTests { // MARK: - Test Organization Migration Tests - @Test func testStructBasedOrganization() { + @Test internal func testStructBasedOrganization() { // Test that struct-based test organization works // This replaces: final class TestClass: XCTestCase let testExecuted = true #expect(testExecuted) } - @Test func testMethodAnnotationMigration() throws { + @Test internal func testMethodAnnotationMigration() throws { // Test that @Test annotation works with throws // This replaces: func testMethod() throws let syntax = Enum("TestEnum") { @@ -29,7 +29,7 @@ struct FrameworkCompatibilityTests { // MARK: - Error Handling Compatibility Tests - @Test func testThrowingTestCompatibility() throws { + @Test internal func testThrowingTestCompatibility() throws { // Ensure throws declaration works properly with @Test let function = Function("throwingFunction", returns: "String") { Parameter(name: "input", type: "String") @@ -45,7 +45,7 @@ struct FrameworkCompatibilityTests { // MARK: - Complex DSL Compatibility Tests - @Test func testFullBlackjackCompatibility() throws { + @Test internal func testFullBlackjackCompatibility() throws { // Test complex DSL patterns work with new framework let syntax = Struct("BlackjackCard") { Enum("Suit") { @@ -80,7 +80,7 @@ struct FrameworkCompatibilityTests { // MARK: - Function Generation Compatibility Tests - @Test func testFunctionGenerationCompatibility() throws { + @Test internal func testFunctionGenerationCompatibility() throws { let function = Function("calculateValue", returns: "Int") { Parameter(name: "multiplier", type: "Int") Parameter(name: "base", type: "Int", defaultValue: "10") @@ -101,7 +101,7 @@ struct FrameworkCompatibilityTests { // MARK: - Comment Injection Compatibility Tests - @Test func testCommentInjectionCompatibility() { + @Test internal func testCommentInjectionCompatibility() { let syntax = Struct("DocumentedStruct") { Variable(.let, name: "value", type: "String") .comment { @@ -121,7 +121,7 @@ struct FrameworkCompatibilityTests { // MARK: - Migration Regression Tests - @Test func testNoRegressionInCodeGeneration() { + @Test internal func testNoRegressionInCodeGeneration() { // Ensure migration doesn't introduce regressions let simpleStruct = Struct("Point") { Variable(.var, name: "x", type: "Double", equals: "0.0") @@ -135,7 +135,7 @@ struct FrameworkCompatibilityTests { #expect(generated.contains("var y: Double = 0.0".normalize())) } - @Test func testLiteralGeneration() { + @Test internal func testLiteralGeneration() { let group = Group { Return { Literal.integer(100) diff --git a/Tests/SyntaxKitTests/FunctionTests.swift b/Tests/SyntaxKitTests/FunctionTests.swift index 797002e..50f0da9 100644 --- a/Tests/SyntaxKitTests/FunctionTests.swift +++ b/Tests/SyntaxKitTests/FunctionTests.swift @@ -2,8 +2,8 @@ import Testing @testable import SyntaxKit -struct FunctionTests { - @Test func testBasicFunction() throws { +internal struct FunctionTests { + @Test internal func testBasicFunction() throws { let function = Function("calculateSum", returns: "Int") { Parameter(name: "a", type: "Int") Parameter(name: "b", type: "Int") @@ -27,7 +27,7 @@ struct FunctionTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testStaticFunction() throws { + @Test internal func testStaticFunction() throws { let function = Function( "createInstance", returns: "MyType", { @@ -55,7 +55,7 @@ struct FunctionTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testMutatingFunction() throws { + @Test internal func testMutatingFunction() throws { let function = Function( "updateValue", { diff --git a/Tests/SyntaxKitTests/LiteralTests.swift b/Tests/SyntaxKitTests/LiteralTests.swift index 255675a..28fb10f 100644 --- a/Tests/SyntaxKitTests/LiteralTests.swift +++ b/Tests/SyntaxKitTests/LiteralTests.swift @@ -2,8 +2,8 @@ import Testing @testable import SyntaxKit -struct LiteralTests { - @Test func testGroupWithLiterals() { +internal struct LiteralTests { + @Test internal func testGroupWithLiterals() { let group = Group { Return { Literal.integer(1) diff --git a/Tests/SyntaxKitTests/LiteralValueTests.swift b/Tests/SyntaxKitTests/LiteralValueTests.swift index 1517dcb..ce7cd09 100644 --- a/Tests/SyntaxKitTests/LiteralValueTests.swift +++ b/Tests/SyntaxKitTests/LiteralValueTests.swift @@ -31,37 +31,37 @@ import Testing @testable import SyntaxKit -struct LiteralValueTests { +internal struct LiteralValueTests { // MARK: - Array LiteralValue Tests - @Test func testArrayStringTypeName() { + @Test internal func testArrayStringTypeName() { let array: [String] = ["a", "b", "c"] #expect(array.typeName == "[String]") } - @Test func testArrayStringLiteralString() { + @Test internal func testArrayStringLiteralString() { let array: [String] = ["a", "b", "c"] #expect(array.literalString == "[\"a\", \"b\", \"c\"]") } - @Test func testEmptyArrayStringLiteralString() { + @Test internal func testEmptyArrayStringLiteralString() { let array: [String] = [] #expect(array.literalString == "[]") } - @Test func testArrayStringWithSpecialCharacters() { + @Test internal func testArrayStringWithSpecialCharacters() { let array: [String] = ["hello world", "test\"quote", "line\nbreak"] #expect(array.literalString == "[\"hello world\", \"test\\\"quote\", \"line\\nbreak\"]") } // MARK: - Dictionary LiteralValue Tests - @Test func testDictionaryIntStringTypeName() { + @Test internal func testDictionaryIntStringTypeName() { let dict: [Int: String] = [1: "a", 2: "b"] #expect(dict.typeName == "[Int: String]") } - @Test func testDictionaryIntStringLiteralString() { + @Test internal func testDictionaryIntStringLiteralString() { let dict: [Int: String] = [1: "a", 2: "b", 3: "c"] let literal = dict.literalString @@ -73,12 +73,12 @@ struct LiteralValueTests { #expect(literal.hasSuffix("]")) } - @Test func testEmptyDictionaryLiteralString() { + @Test internal func testEmptyDictionaryLiteralString() { let dict: [Int: String] = [:] #expect(dict.literalString == "[]") } - @Test func testDictionaryWithSpecialCharacters() { + @Test internal func testDictionaryWithSpecialCharacters() { let dict: [Int: String] = [1: "hello world", 2: "test\"quote"] let literal = dict.literalString @@ -91,7 +91,7 @@ struct LiteralValueTests { // MARK: - Dictionary Ordering Tests - @Test func testDictionaryOrderingIsConsistent() { + @Test internal func testDictionaryOrderingIsConsistent() { let dict1: [Int: String] = [2: "b", 1: "a", 3: "c"] let dict2: [Int: String] = [1: "a", 2: "b", 3: "c"] diff --git a/Tests/SyntaxKitTests/MainApplicationTests.swift b/Tests/SyntaxKitTests/MainApplicationTests.swift new file mode 100644 index 0000000..397838e --- /dev/null +++ b/Tests/SyntaxKitTests/MainApplicationTests.swift @@ -0,0 +1,195 @@ +import Foundation +import Testing + +@testable import SyntaxKit + +internal struct MainApplicationTests { + // MARK: - Main Application Error Handling Tests + + @Test("Main application handles valid input") + internal func testMainApplicationValidInput() throws { + // This test simulates the main application behavior + // We can't easily test the main function directly, but we can test its components + + let code = "let x = 42" + let response = try SyntaxParser.parse(code: code, options: ["fold"]) + + // Test JSON serialization (part of main application logic) + let jsonData = try JSONSerialization.data(withJSONObject: ["syntax": response.syntaxJSON]) + let jsonString = String(data: jsonData, encoding: .utf8) + + #expect(jsonString != nil) + #expect(jsonString!.contains("syntax")) + #expect(jsonString!.contains("let")) + } + + @Test("Main application handles empty input") + internal func testMainApplicationEmptyInput() throws { + let code = "" + let response = try SyntaxParser.parse(code: code, options: []) + + // Test JSON serialization with empty result + let jsonData = try JSONSerialization.data(withJSONObject: ["syntax": response.syntaxJSON]) + let jsonString = String(data: jsonData, encoding: .utf8) + + #expect(jsonString != nil) + #expect(jsonString!.contains("syntax")) + } + + @Test("Main application handles parsing errors") + internal func testMainApplicationHandlesParsingErrors() throws { + let invalidCode = "struct {" + + // The parser doesn't throw errors for invalid syntax, it returns a result + let response = try SyntaxParser.parse(code: invalidCode, options: []) + + // Test error JSON serialization (part of main application logic) + let jsonData = try JSONSerialization.data(withJSONObject: ["error": "Invalid syntax"]) + let jsonString = String(data: jsonData, encoding: .utf8) + + #expect(jsonString != nil) + #expect(jsonString!.contains("error")) + #expect(jsonString!.contains("Invalid syntax")) + } + + @Test("Main application handles JSON serialization errors") + internal func testMainApplicationHandlesJSONSerializationErrors() throws { + // Test with a response that might cause JSON serialization issues + let code = "let x = 42" + let response = try SyntaxParser.parse(code: code, options: []) + + // This should work fine, but we're testing the JSON serialization path + let jsonData = try JSONSerialization.data(withJSONObject: ["syntax": response.syntaxJSON]) + let jsonString = String(data: jsonData, encoding: .utf8) + + #expect(jsonString != nil) + } + + // MARK: - File I/O Simulation Tests + + @Test("Main application handles large input") + internal func testMainApplicationHandlesLargeInput() throws { + // Generate a large Swift file to test performance + var largeCode = "" + for index in 1...50 { + largeCode += """ + struct Struct\(index) { + let property\(index): String + func method\(index)() -> String { + return "value\(index)" + } + } + + """ + } + + let response = try SyntaxParser.parse(code: largeCode, options: ["fold"]) + let jsonData = try JSONSerialization.data(withJSONObject: ["syntax": response.syntaxJSON]) + let jsonString = String(data: jsonData, encoding: .utf8) + + #expect(jsonString != nil) + #expect(jsonString!.contains("Struct1")) + #expect(jsonString!.contains("Struct50")) + } + + @Test("Main application handles unicode input") + internal func testMainApplicationHandlesUnicodeInput() throws { + let unicodeCode = """ + let emoji = "🚀" + let unicode = "café" + let chinese = "你好" + """ + + let response = try SyntaxParser.parse(code: unicodeCode, options: []) + let jsonData = try JSONSerialization.data(withJSONObject: ["syntax": response.syntaxJSON]) + let jsonString = String(data: jsonData, encoding: .utf8) + + #expect(jsonString != nil) + #expect(jsonString!.contains("emoji")) + #expect(jsonString!.contains("unicode")) + #expect(jsonString!.contains("chinese")) + } + + // MARK: - Error Response Format Tests + + @Test("Main application error response format") + internal func testMainApplicationErrorResponseFormat() throws { + // Test the error response format that the main application would generate + let testError = NSError( + domain: "TestDomain", code: 1, userInfo: [NSLocalizedDescriptionKey: "Test error message"]) + + let errorResponse = ["error": testError.localizedDescription] + let jsonData = try JSONSerialization.data(withJSONObject: errorResponse) + let jsonString = String(data: jsonData, encoding: .utf8) + + #expect(jsonString != nil) + #expect(jsonString!.contains("error")) + #expect(jsonString!.contains("Test error message")) + } + + @Test("Main application handles encoding errors") + internal func testMainApplicationHandlesEncodingErrors() throws { + let code = "let x = 42" + let response = try SyntaxParser.parse(code: code, options: []) + + // Test UTF-8 encoding (part of main application logic) + let jsonData = try JSONSerialization.data(withJSONObject: ["syntax": response.syntaxJSON]) + let jsonString = String(data: jsonData, encoding: .utf8) + + #expect(jsonString != nil) + #expect(jsonString!.contains("syntax")) + } + + // MARK: - Integration Tests + + @Test("Main application integration with complex Swift code") + internal func testMainApplicationIntegrationWithComplexSwiftCode() throws { + let code = """ + @objc class MyClass: NSObject { + @Published var property: String = "default" + + func method(@escaping completion: @escaping (String) -> Void) { + completion("result") + } + + enum NestedEnum: Int { + case first = 1 + case second = 2 + } + } + """ + + let response = try SyntaxParser.parse(code: code, options: ["fold"]) + + // Test JSON serialization (part of main application logic) + let jsonData = try JSONSerialization.data(withJSONObject: ["syntax": response.syntaxJSON]) + let jsonString = String(data: jsonData, encoding: .utf8) + + #expect(jsonString != nil) + #expect(jsonString!.contains("syntax")) + #expect(jsonString!.contains("class")) + #expect(jsonString!.contains("MyClass")) + } + + @Test("Main application handles different parser options") + internal func testMainApplicationHandlesDifferentParserOptions() throws { + let code = "let x = 42" + + let response1 = try SyntaxParser.parse(code: code, options: []) + let response2 = try SyntaxParser.parse(code: code, options: ["fold"]) + + // Test JSON serialization for both responses + let jsonData1 = try JSONSerialization.data(withJSONObject: ["syntax": response1.syntaxJSON]) + let jsonString1 = String(data: jsonData1, encoding: .utf8) + + let jsonData2 = try JSONSerialization.data(withJSONObject: ["syntax": response2.syntaxJSON]) + let jsonString2 = String(data: jsonData2, encoding: .utf8) + + #expect(jsonString1 != nil) + #expect(jsonString2 != nil) + #expect(jsonString1!.contains("syntax")) + #expect(jsonString2!.contains("syntax")) + #expect(jsonString1!.contains("let")) + #expect(jsonString2!.contains("let")) + } +} diff --git a/Tests/SyntaxKitTests/MigrationTests.swift b/Tests/SyntaxKitTests/MigrationTests.swift index ddcc5a7..b97b32d 100644 --- a/Tests/SyntaxKitTests/MigrationTests.swift +++ b/Tests/SyntaxKitTests/MigrationTests.swift @@ -4,16 +4,16 @@ import Testing /// Tests specifically for verifying the Swift Testing framework migration /// These tests ensure that the migration from XCTest to Swift Testing works correctly -struct MigrationTests { +internal struct MigrationTests { // MARK: - Basic Test Structure Migration Tests - @Test func testStructBasedTestExecution() { + @Test internal func testStructBasedTestExecution() { // Test that struct-based tests execute properly let result = true #expect(result == true) } - @Test func testThrowingTestMethod() throws { + @Test internal func testThrowingTestMethod() throws { // Test that @Test works with throws declaration let syntax = Struct("TestStruct") { Variable(.let, name: "value", type: "String") @@ -25,21 +25,21 @@ struct MigrationTests { // MARK: - Assertion Migration Tests - @Test func testExpectEqualityAssertion() { + @Test internal func testExpectEqualityAssertion() { // Test #expect() replacement for XCTAssertEqual let actual = "test" let expected = "test" #expect(actual == expected) } - @Test func testExpectBooleanAssertion() { + @Test internal func testExpectBooleanAssertion() { // Test #expect() replacement for XCTAssertTrue/XCTAssertFalse let condition = true #expect(condition) #expect(!false) } - @Test func testExpectEmptyStringAssertion() { + @Test internal func testExpectEmptyStringAssertion() { // Test #expect() replacement for XCTAssertFalse(string.isEmpty) let generated = "non-empty string" #expect(!generated.isEmpty) @@ -47,7 +47,7 @@ struct MigrationTests { // MARK: - Code Generation Testing with New Framework - @Test func testBasicCodeGenerationWithNewFramework() throws { + @Test internal func testBasicCodeGenerationWithNewFramework() throws { let blackjackCard = Struct("BlackjackCard") { Enum("Suit") { EnumCase("spades").equals("♠") @@ -78,7 +78,7 @@ struct MigrationTests { // MARK: - String Options Migration Tests - @Test func testStringCompareOptionsSimplification() { + @Test internal func testStringCompareOptionsSimplification() { // Test that .regularExpression works instead of String.CompareOptions.regularExpression let testString = "public func test() { }" let result = testString.replacingOccurrences( @@ -87,7 +87,7 @@ struct MigrationTests { #expect(result == expected) } - @Test func testCharacterSetSimplification() { + @Test internal func testCharacterSetSimplification() { // Test that .whitespacesAndNewlines works instead of CharacterSet.whitespacesAndNewlines let testString = " test \n" let result = testString.trimmingCharacters(in: .whitespacesAndNewlines) @@ -97,7 +97,7 @@ struct MigrationTests { // MARK: - Complex Code Generation Tests - @Test func testComplexStructGeneration() throws { + @Test internal func testComplexStructGeneration() throws { let syntax = Struct("TestCard") { Variable(.let, name: "rank", type: "String") Variable(.let, name: "suit", type: "String") @@ -118,7 +118,7 @@ struct MigrationTests { #expect(generated.contains("func description() -> String".normalize())) } - @Test func testMigrationBackwardCompatibility() { + @Test internal func testMigrationBackwardCompatibility() { // Ensure that the migrated tests maintain the same functionality let group = Group { Return { diff --git a/Tests/SyntaxKitTests/OptionsMacroIntegrationTests.swift b/Tests/SyntaxKitTests/OptionsMacroIntegrationTests.swift index b013daa..af6106d 100644 --- a/Tests/SyntaxKitTests/OptionsMacroIntegrationTests.swift +++ b/Tests/SyntaxKitTests/OptionsMacroIntegrationTests.swift @@ -31,10 +31,10 @@ import Testing @testable import SyntaxKit -struct OptionsMacroIntegrationTests { +internal struct OptionsMacroIntegrationTests { // MARK: - Enum with Raw Values (Dictionary) Tests - @Test func testEnumWithRawValuesCreatesDictionary() { + @Test internal func testEnumWithRawValuesCreatesDictionary() { // Simulate the Options macro expansion for an enum with raw values let keyValues: [Int: String] = [2: "a", 5: "b", 6: "c", 12: "d"] @@ -56,7 +56,7 @@ struct OptionsMacroIntegrationTests { #expect(generated.contains("12: \"d\"")) } - @Test func testEnumWithoutRawValuesCreatesArray() { + @Test internal func testEnumWithoutRawValuesCreatesArray() { // Simulate the Options macro expansion for an enum without raw values let caseNames: [String] = ["red", "green", "blue"] @@ -75,7 +75,7 @@ struct OptionsMacroIntegrationTests { // MARK: - Complex Integration Tests - @Test func testCompleteOptionsMacroWorkflow() { + @Test internal func testCompleteOptionsMacroWorkflow() { // This test demonstrates the complete workflow that the Options macro would use // Step 1: Determine if enum has raw values (simulated) @@ -110,7 +110,7 @@ struct OptionsMacroIntegrationTests { #expect(generated.contains("3: \"third\"")) } - @Test func testOptionsMacroWorkflowWithoutRawValues() { + @Test internal func testOptionsMacroWorkflowWithoutRawValues() { // Test the workflow for enums without raw values let hasRawValues = false @@ -140,7 +140,7 @@ struct OptionsMacroIntegrationTests { // MARK: - Edge Cases - @Test func testEmptyEnumCases() { + @Test internal func testEmptyEnumCases() { let caseNames: [String] = [] let extensionDecl = Extension("EmptyEnum") { @@ -156,7 +156,7 @@ struct OptionsMacroIntegrationTests { #expect(generated.contains("static let mappedValues: [String] = []")) } - @Test func testEmptyDictionary() { + @Test internal func testEmptyDictionary() { let keyValues: [Int: String] = [:] let extensionDecl = Extension("EmptyDictEnum") { @@ -173,7 +173,7 @@ struct OptionsMacroIntegrationTests { #expect(generated.contains("static let mappedValues: [Int: String] = []")) } - @Test func testSpecialCharactersInCaseNames() { + @Test internal func testSpecialCharactersInCaseNames() { let caseNames: [String] = ["case_with_underscore", "case-with-dash", "caseWithCamelCase"] let extensionDecl = Extension("SpecialEnum") { @@ -194,7 +194,7 @@ struct OptionsMacroIntegrationTests { // MARK: - API Validation Tests - @Test func testNewSyntaxKitAPICompleteness() { + @Test internal func testNewSyntaxKitAPICompleteness() { // Verify that all the new API components work together correctly // Test LiteralValue protocol diff --git a/Tests/SyntaxKitTests/ProtocolTests.swift b/Tests/SyntaxKitTests/ProtocolTests.swift index 31a3c55..dec6071 100644 --- a/Tests/SyntaxKitTests/ProtocolTests.swift +++ b/Tests/SyntaxKitTests/ProtocolTests.swift @@ -2,8 +2,8 @@ import Testing @testable import SyntaxKit -struct ProtocolTests { - @Test func testSimpleProtocol() { +internal struct ProtocolTests { + @Test internal func testSimpleProtocol() { let vehicleProtocol = Protocol("Vehicle") { PropertyRequirement("numberOfWheels", type: "Int", access: .get) PropertyRequirement("brand", type: "String", access: .getSet) @@ -27,7 +27,7 @@ struct ProtocolTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testEmptyProtocol() { + @Test internal func testEmptyProtocol() { let emptyProtocol = Protocol("EmptyProtocol") {} let expected = """ @@ -40,7 +40,7 @@ struct ProtocolTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testProtocolWithInheritance() { + @Test internal func testProtocolWithInheritance() { let protocolWithInheritance = Protocol("MyProtocol") { PropertyRequirement("value", type: "String", access: .getSet) }.inherits("Equatable", "Hashable") @@ -56,7 +56,7 @@ struct ProtocolTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testFunctionRequirementWithParameters() { + @Test internal func testFunctionRequirementWithParameters() { let protocolWithFunction = Protocol("Calculator") { FunctionRequirement("add", returns: "Int") { Parameter(name: "a", type: "Int") @@ -75,7 +75,7 @@ struct ProtocolTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testStaticFunctionRequirement() { + @Test internal func testStaticFunctionRequirement() { let protocolWithStaticFunction = Protocol("Factory") { FunctionRequirement("create", returns: "Self").static() } @@ -91,7 +91,7 @@ struct ProtocolTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testMutatingFunctionRequirement() { + @Test internal func testMutatingFunctionRequirement() { let protocolWithMutatingFunction = Protocol("Resettable") { FunctionRequirement("reset").mutating() } @@ -107,7 +107,7 @@ struct ProtocolTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testPropertyRequirementGetOnly() { + @Test internal func testPropertyRequirementGetOnly() { let propertyReq = PropertyRequirement("readOnlyProperty", type: "String", access: .get) let prtcl = Protocol("TestProtocol") { propertyReq @@ -124,7 +124,7 @@ struct ProtocolTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testPropertyRequirementGetSet() { + @Test internal func testPropertyRequirementGetSet() { let propertyReq = PropertyRequirement("readWriteProperty", type: "Int", access: .getSet) let prtcl = Protocol("TestProtocol") { propertyReq @@ -141,7 +141,7 @@ struct ProtocolTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testFunctionRequirementWithDefaultParameters() { + @Test internal func testFunctionRequirementWithDefaultParameters() { let functionReq = FunctionRequirement("process", returns: "String") { Parameter(name: "input", type: "String") Parameter(name: "options", type: "ProcessingOptions", defaultValue: "ProcessingOptions()") @@ -161,7 +161,7 @@ struct ProtocolTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testComplexProtocolWithMixedRequirements() { + @Test internal func testComplexProtocolWithMixedRequirements() { let complexProtocol = Protocol("ComplexProtocol") { PropertyRequirement("id", type: "UUID", access: .get) PropertyRequirement("name", type: "String", access: .getSet) diff --git a/Tests/SyntaxKitTests/String+Normalize.swift b/Tests/SyntaxKitTests/String+Normalize.swift index 5343b37..bc1c614 100644 --- a/Tests/SyntaxKitTests/String+Normalize.swift +++ b/Tests/SyntaxKitTests/String+Normalize.swift @@ -1,7 +1,7 @@ import Foundation extension String { - func normalize() -> String { + internal func normalize() -> String { self .replacingOccurrences(of: "//.*$", with: "", options: .regularExpression) .replacingOccurrences(of: "\\s*:\\s*", with: ": ", options: .regularExpression) diff --git a/Tests/SyntaxKitTests/StructTests.swift b/Tests/SyntaxKitTests/StructTests.swift index 9aaf4df..61ba952 100644 --- a/Tests/SyntaxKitTests/StructTests.swift +++ b/Tests/SyntaxKitTests/StructTests.swift @@ -2,8 +2,8 @@ import Testing @testable import SyntaxKit -struct StructTests { - @Test func testGenericStruct() { +internal struct StructTests { + @Test internal func testGenericStruct() { let stackStruct = Struct("Stack") { Variable(.var, name: "items", type: "[Element]", equals: "[]") @@ -63,7 +63,7 @@ struct StructTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testGenericStructWithInheritance() { + @Test internal func testGenericStructWithInheritance() { let containerStruct = Struct("Container") { Variable(.var, name: "value", type: "T") }.generic("T").inherits("Equatable") @@ -79,7 +79,7 @@ struct StructTests { #expect(normalizedGenerated == normalizedExpected) } - @Test func testNonGenericStruct() { + @Test internal func testNonGenericStruct() { let simpleStruct = Struct("Point") { Variable(.var, name: "x", type: "Double") Variable(.var, name: "y", type: "Double") diff --git a/Tests/SyntaxKitTests/TypeAliasTests.swift b/Tests/SyntaxKitTests/TypeAliasTests.swift index c67c4eb..62f47cf 100644 --- a/Tests/SyntaxKitTests/TypeAliasTests.swift +++ b/Tests/SyntaxKitTests/TypeAliasTests.swift @@ -31,31 +31,31 @@ import Testing @testable import SyntaxKit -struct TypeAliasTests { +internal struct TypeAliasTests { // MARK: - Basic TypeAlias Tests - @Test func testBasicTypeAlias() { + @Test internal func testBasicTypeAlias() { let typeAlias = TypeAlias("MappedType", equals: "String") let generated = typeAlias.generateCode().normalize() #expect(generated.contains("typealias MappedType = String")) } - @Test func testTypeAliasWithComplexType() { + @Test internal func testTypeAliasWithComplexType() { let typeAlias = TypeAlias("ResultType", equals: "Result") let generated = typeAlias.generateCode().normalize() #expect(generated.contains("typealias ResultType = Result")) } - @Test func testTypeAliasWithGenericType() { + @Test internal func testTypeAliasWithGenericType() { let typeAlias = TypeAlias("ArrayType", equals: "Array") let generated = typeAlias.generateCode().normalize() #expect(generated.contains("typealias ArrayType = Array")) } - @Test func testTypeAliasWithOptionalType() { + @Test internal func testTypeAliasWithOptionalType() { let typeAlias = TypeAlias("OptionalString", equals: "String?") let generated = typeAlias.generateCode().normalize() @@ -64,7 +64,7 @@ struct TypeAliasTests { // MARK: - TypeAlias in Context Tests - @Test func testTypeAliasInExtension() { + @Test internal func testTypeAliasInExtension() { let extensionDecl = Extension("MyEnum") { TypeAlias("MappedType", equals: "String") Variable(.let, name: "test", type: "MappedType", equals: "value") @@ -77,7 +77,7 @@ struct TypeAliasTests { #expect(generated.contains("let test: MappedType = value")) } - @Test func testTypeAliasInStruct() { + @Test internal func testTypeAliasInStruct() { let structDecl = Struct("Container") { TypeAlias("ElementType", equals: "String") Variable(.let, name: "element", type: "ElementType") @@ -90,7 +90,7 @@ struct TypeAliasTests { #expect(generated.contains("let element: ElementType")) } - @Test func testTypeAliasInEnum() { + @Test internal func testTypeAliasInEnum() { let enumDecl = Enum("Result") { TypeAlias("SuccessType", equals: "String") TypeAlias("FailureType", equals: "Error") @@ -109,35 +109,35 @@ struct TypeAliasTests { // MARK: - Edge Cases - @Test func testTypeAliasWithSpecialCharacters() { + @Test internal func testTypeAliasWithSpecialCharacters() { let typeAlias = TypeAlias("GenericType", equals: "Array") let generated = typeAlias.generateCode().normalize() #expect(generated.contains("typealias GenericType = Array")) } - @Test func testTypeAliasWithProtocolComposition() { + @Test internal func testTypeAliasWithProtocolComposition() { let typeAlias = TypeAlias("ProtocolType", equals: "Protocol1 & Protocol2") let generated = typeAlias.generateCode().normalize() #expect(generated.contains("typealias ProtocolType = Protocol1 & Protocol2")) } - @Test func testTypeAliasWithFunctionType() { + @Test internal func testTypeAliasWithFunctionType() { let typeAlias = TypeAlias("Handler", equals: "(String) -> Void") let generated = typeAlias.generateCode().normalize() #expect(generated.contains("typealias Handler = (String) -> Void")) } - @Test func testTypeAliasWithTupleType() { + @Test internal func testTypeAliasWithTupleType() { let typeAlias = TypeAlias("Coordinate", equals: "(x: Double, y: Double)") let generated = typeAlias.generateCode().normalize() #expect(generated.contains("typealias Coordinate = (x: Double, y: Double)")) } - @Test func testTypeAliasWithClosureType() { + @Test internal func testTypeAliasWithClosureType() { let typeAlias = TypeAlias("Callback", equals: "@escaping (Result) -> Void") let generated = typeAlias.generateCode().normalize() @@ -146,7 +146,7 @@ struct TypeAliasTests { // MARK: - Integration Tests - @Test func testTypeAliasWithStaticVariable() { + @Test internal func testTypeAliasWithStaticVariable() { let extensionDecl = Extension("MyEnum") { TypeAlias("MappedType", equals: "String") Variable(.let, name: "mappedValues", equals: ["a", "b", "c"]).static() @@ -159,7 +159,7 @@ struct TypeAliasTests { #expect(generated.contains("static let mappedValues: [String] = [\"a\", \"b\", \"c\"]")) } - @Test func testTypeAliasWithDictionaryVariable() { + @Test internal func testTypeAliasWithDictionaryVariable() { let extensionDecl = Extension("MyEnum") { TypeAlias("MappedType", equals: "String") Variable(.let, name: "mappedValues", equals: [1: "a", 2: "b"]).static() diff --git a/Tests/SyntaxKitTests/VariableStaticTests.swift b/Tests/SyntaxKitTests/VariableStaticTests.swift index 38e1936..54612d1 100644 --- a/Tests/SyntaxKitTests/VariableStaticTests.swift +++ b/Tests/SyntaxKitTests/VariableStaticTests.swift @@ -31,17 +31,17 @@ import Testing @testable import SyntaxKit -struct VariableStaticTests { +internal struct VariableStaticTests { // MARK: - Static Variable Tests - @Test func testStaticVariableWithStringLiteral() { + @Test internal func testStaticVariableWithStringLiteral() { let variable = Variable(.let, name: "test", type: "String", equals: "hello").static() let generated = variable.generateCode().normalize() #expect(generated.contains("static let test: String = hello")) } - @Test func testStaticVariableWithArrayLiteral() { + @Test internal func testStaticVariableWithArrayLiteral() { let array: [String] = ["a", "b", "c"] let variable = Variable(.let, name: "mappedValues", equals: array).static() let generated = variable.generateCode().normalize() @@ -49,7 +49,7 @@ struct VariableStaticTests { #expect(generated.contains("static let mappedValues: [String] = [\"a\", \"b\", \"c\"]")) } - @Test func testStaticVariableWithDictionaryLiteral() { + @Test internal func testStaticVariableWithDictionaryLiteral() { let dict: [Int: String] = [1: "a", 2: "b", 3: "c"] let variable = Variable(.let, name: "mappedValues", equals: dict).static() let generated = variable.generateCode().normalize() @@ -60,7 +60,7 @@ struct VariableStaticTests { #expect(generated.contains("3: \"c\"")) } - @Test func testStaticVariableWithVar() { + @Test internal func testStaticVariableWithVar() { let variable = Variable(.var, name: "counter", type: "Int", equals: "0").static() let generated = variable.generateCode().normalize() @@ -69,7 +69,7 @@ struct VariableStaticTests { // MARK: - Non-Static Variable Tests - @Test func testNonStaticVariableWithLiteral() { + @Test internal func testNonStaticVariableWithLiteral() { let array: [String] = ["x", "y", "z"] let variable = Variable(.let, name: "values", equals: array) let generated = variable.generateCode().normalize() @@ -78,7 +78,7 @@ struct VariableStaticTests { #expect(!generated.contains("static")) } - @Test func testNonStaticVariableWithDictionary() { + @Test internal func testNonStaticVariableWithDictionary() { let dict: [Int: String] = [10: "ten", 20: "twenty"] let variable = Variable(.let, name: "lookup", equals: dict) let generated = variable.generateCode().normalize() @@ -91,7 +91,7 @@ struct VariableStaticTests { // MARK: - Static Method Tests - @Test func testStaticMethodReturnsNewInstance() { + @Test internal func testStaticMethodReturnsNewInstance() { let original = Variable(.let, name: "test", type: "String", equals: "value") let staticVersion = original.static() @@ -107,7 +107,7 @@ struct VariableStaticTests { #expect(staticGenerated.contains("static")) } - @Test func testStaticMethodPreservesOtherProperties() { + @Test internal func testStaticMethodPreservesOtherProperties() { let original = Variable(.var, name: "test", type: "String", equals: "value") let staticVersion = original.static() @@ -127,7 +127,7 @@ struct VariableStaticTests { // MARK: - Edge Cases - @Test func testEmptyArrayLiteral() { + @Test internal func testEmptyArrayLiteral() { let array: [String] = [] let variable = Variable(.let, name: "empty", equals: array).static() let generated = variable.generateCode().normalize() @@ -135,7 +135,7 @@ struct VariableStaticTests { #expect(generated.contains("static let empty: [String] = []")) } - @Test func testEmptyDictionaryLiteral() { + @Test internal func testEmptyDictionaryLiteral() { let dict: [Int: String] = [:] let variable = Variable(.let, name: "empty", equals: dict).static() let generated = variable.generateCode().normalize() @@ -143,7 +143,7 @@ struct VariableStaticTests { #expect(generated.contains("static let empty: [Int: String] = []")) } - @Test func testMultipleStaticCalls() { + @Test internal func testMultipleStaticCalls() { let variable = Variable(.let, name: "test", type: "String", equals: "value").static().static() let generated = variable.generateCode().normalize()