@@ -2,7 +2,7 @@ import Testing
22
33@testable import SyntaxKit
44
5- struct ClassAndProtocolTests {
5+ struct ProtocolTests {
66 @Test func testSimpleProtocol( ) {
77 let vehicleProtocol = Protocol ( " Vehicle " ) {
88 PropertyRequirement ( " numberOfWheels " , type: " Int " , access: . get)
@@ -27,24 +27,6 @@ struct ClassAndProtocolTests {
2727 #expect( normalizedGenerated == normalizedExpected)
2828 }
2929
30- @Test func testClassWithInheritance( ) {
31- let carClass = Class ( " Car " ) {
32- Variable ( . var, name: " brand " , type: " String " )
33- Variable ( . var, name: " numberOfWheels " , type: " Int " )
34- } . inherits ( " Vehicle " )
35-
36- let expected = """
37- class Car: Vehicle {
38- var brand: String
39- var numberOfWheels: Int
40- }
41- """
42-
43- let normalizedGenerated = carClass. generateCode ( ) . normalize ( )
44- let normalizedExpected = expected. normalize ( )
45- #expect( normalizedGenerated == normalizedExpected)
46- }
47-
4830 @Test func testEmptyProtocol( ) {
4931 let emptyProtocol = Protocol ( " EmptyProtocol " ) { }
5032
@@ -125,142 +107,6 @@ struct ClassAndProtocolTests {
125107 #expect( normalizedGenerated == normalizedExpected)
126108 }
127109
128- @Test func testEmptyClass( ) {
129- let emptyClass = Class ( " EmptyClass " ) { }
130-
131- let expected = """
132- class EmptyClass {
133- }
134- """
135-
136- let normalizedGenerated = emptyClass. generateCode ( ) . normalize ( )
137- let normalizedExpected = expected. normalize ( )
138- #expect( normalizedGenerated == normalizedExpected)
139- }
140-
141- @Test func testClassWithGenerics( ) {
142- let genericClass = Class ( " Container " , generics: [ " T " ] ) {
143- Variable ( . var, name: " value " , type: " T " )
144- }
145-
146- let expected = """
147- class Container<T> {
148- var value: T
149- }
150- """
151-
152- let normalizedGenerated = genericClass. generateCode ( ) . normalize ( )
153- let normalizedExpected = expected. normalize ( )
154- #expect( normalizedGenerated == normalizedExpected)
155- }
156-
157- @Test func testClassWithMultipleGenerics( ) {
158- let multiGenericClass = Class ( " Pair " , generics: [ " T " , " U " ] ) {
159- Variable ( . var, name: " first " , type: " T " )
160- Variable ( . var, name: " second " , type: " U " )
161- }
162-
163- let expected = """
164- class Pair<T, U> {
165- var first: T
166- var second: U
167- }
168- """
169-
170- let normalizedGenerated = multiGenericClass. generateCode ( ) . normalize ( )
171- let normalizedExpected = expected. normalize ( )
172- #expect( normalizedGenerated == normalizedExpected)
173- }
174-
175- @Test func testFinalClass( ) {
176- let finalClass = Class ( " FinalClass " ) {
177- Variable ( . var, name: " value " , type: " String " )
178- } . final ( )
179-
180- let expected = """
181- final class FinalClass {
182- var value: String
183- }
184- """
185-
186- let normalizedGenerated = finalClass. generateCode ( ) . normalize ( )
187- let normalizedExpected = expected. normalize ( )
188- #expect( normalizedGenerated == normalizedExpected)
189- }
190-
191- @Test func testClassWithMultipleInheritance( ) {
192- let classWithMultipleInheritance = Class ( " AdvancedVehicle " ) {
193- Variable ( . var, name: " speed " , type: " Int " )
194- } . inherits ( " Vehicle " , " Codable " , " Equatable " )
195-
196- let expected = """
197- class AdvancedVehicle: Vehicle, Codable, Equatable {
198- var speed: Int
199- }
200- """
201-
202- let normalizedGenerated = classWithMultipleInheritance. generateCode ( ) . normalize ( )
203- let normalizedExpected = expected. normalize ( )
204- #expect( normalizedGenerated == normalizedExpected)
205- }
206-
207- @Test func testClassWithGenericsAndInheritance( ) {
208- let genericClassWithInheritance = Class ( " GenericContainer " , generics: [ " T " ] ) {
209- Variable ( . var, name: " items " , type: " [T] " )
210- } . inherits ( " Collection " )
211-
212- let expected = """
213- class GenericContainer<T>: Collection {
214- var items: [T]
215- }
216- """
217-
218- let normalizedGenerated = genericClassWithInheritance. generateCode ( ) . normalize ( )
219- let normalizedExpected = expected. normalize ( )
220- #expect( normalizedGenerated == normalizedExpected)
221- }
222-
223- @Test func testFinalClassWithInheritanceAndGenerics( ) {
224- let finalGenericClass = Class ( " FinalGenericClass " , generics: [ " T " ] ) {
225- Variable ( . var, name: " value " , type: " T " )
226- } . inherits ( " BaseClass " ) . final ( )
227-
228- let expected = """
229- final class FinalGenericClass<T>: BaseClass {
230- var value: T
231- }
232- """
233-
234- let normalizedGenerated = finalGenericClass. generateCode ( ) . normalize ( )
235- let normalizedExpected = expected. normalize ( )
236- #expect( normalizedGenerated == normalizedExpected)
237- }
238-
239- @Test func testClassWithFunctions( ) {
240- let classWithFunctions = Class ( " Calculator " ) {
241- Function ( " add " , returns: " Int " ) {
242- Parameter ( name: " a " , type: " Int " )
243- Parameter ( name: " b " , type: " Int " )
244- } _: {
245- Return {
246- VariableExp ( " a + b " )
247- }
248- }
249- }
250-
251- let expected = """
252- class Calculator {
253- func add(a: Int, b: Int) -> Int {
254- return a + b
255- }
256- }
257- """
258-
259- let normalizedGenerated = classWithFunctions. generateCode ( ) . normalize ( )
260- let normalizedExpected = expected. normalize ( )
261- #expect( normalizedGenerated == normalizedExpected)
262- }
263-
264110 @Test func testPropertyRequirementGetOnly( ) {
265111 let propertyReq = PropertyRequirement ( " readOnlyProperty " , type: " String " , access: . get)
266112 let prtcl = Protocol ( " TestProtocol " ) {
0 commit comments