Skip to content

Commit 6e6e520

Browse files
committed
fixing long file
1 parent 0ee2475 commit 6e6e520

File tree

2 files changed

+160
-155
lines changed

2 files changed

+160
-155
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import Testing
2+
3+
@testable import SyntaxKit
4+
5+
struct ClassTests {
6+
@Test func testClassWithInheritance() {
7+
let carClass = Class("Car") {
8+
Variable(.var, name: "brand", type: "String")
9+
Variable(.var, name: "numberOfWheels", type: "Int")
10+
}.inherits("Vehicle")
11+
12+
let expected = """
13+
class Car: Vehicle {
14+
var brand: String
15+
var numberOfWheels: Int
16+
}
17+
"""
18+
19+
let normalizedGenerated = carClass.generateCode().normalize()
20+
let normalizedExpected = expected.normalize()
21+
#expect(normalizedGenerated == normalizedExpected)
22+
}
23+
24+
@Test func testEmptyClass() {
25+
let emptyClass = Class("EmptyClass") {}
26+
27+
let expected = """
28+
class EmptyClass {
29+
}
30+
"""
31+
32+
let normalizedGenerated = emptyClass.generateCode().normalize()
33+
let normalizedExpected = expected.normalize()
34+
#expect(normalizedGenerated == normalizedExpected)
35+
}
36+
37+
@Test func testClassWithGenerics() {
38+
let genericClass = Class("Container", generics: ["T"]) {
39+
Variable(.var, name: "value", type: "T")
40+
}
41+
42+
let expected = """
43+
class Container<T> {
44+
var value: T
45+
}
46+
"""
47+
48+
let normalizedGenerated = genericClass.generateCode().normalize()
49+
let normalizedExpected = expected.normalize()
50+
#expect(normalizedGenerated == normalizedExpected)
51+
}
52+
53+
@Test func testClassWithMultipleGenerics() {
54+
let multiGenericClass = Class("Pair", generics: ["T", "U"]) {
55+
Variable(.var, name: "first", type: "T")
56+
Variable(.var, name: "second", type: "U")
57+
}
58+
59+
let expected = """
60+
class Pair<T, U> {
61+
var first: T
62+
var second: U
63+
}
64+
"""
65+
66+
let normalizedGenerated = multiGenericClass.generateCode().normalize()
67+
let normalizedExpected = expected.normalize()
68+
#expect(normalizedGenerated == normalizedExpected)
69+
}
70+
71+
@Test func testFinalClass() {
72+
let finalClass = Class("FinalClass") {
73+
Variable(.var, name: "value", type: "String")
74+
}.final()
75+
76+
let expected = """
77+
final class FinalClass {
78+
var value: String
79+
}
80+
"""
81+
82+
let normalizedGenerated = finalClass.generateCode().normalize()
83+
let normalizedExpected = expected.normalize()
84+
#expect(normalizedGenerated == normalizedExpected)
85+
}
86+
87+
@Test func testClassWithMultipleInheritance() {
88+
let classWithMultipleInheritance = Class("AdvancedVehicle") {
89+
Variable(.var, name: "speed", type: "Int")
90+
}.inherits("Vehicle", "Codable", "Equatable")
91+
92+
let expected = """
93+
class AdvancedVehicle: Vehicle, Codable, Equatable {
94+
var speed: Int
95+
}
96+
"""
97+
98+
let normalizedGenerated = classWithMultipleInheritance.generateCode().normalize()
99+
let normalizedExpected = expected.normalize()
100+
#expect(normalizedGenerated == normalizedExpected)
101+
}
102+
103+
@Test func testClassWithGenericsAndInheritance() {
104+
let genericClassWithInheritance = Class("GenericContainer", generics: ["T"]) {
105+
Variable(.var, name: "items", type: "[T]")
106+
}.inherits("Collection")
107+
108+
let expected = """
109+
class GenericContainer<T>: Collection {
110+
var items: [T]
111+
}
112+
"""
113+
114+
let normalizedGenerated = genericClassWithInheritance.generateCode().normalize()
115+
let normalizedExpected = expected.normalize()
116+
#expect(normalizedGenerated == normalizedExpected)
117+
}
118+
119+
@Test func testFinalClassWithInheritanceAndGenerics() {
120+
let finalGenericClass = Class("FinalGenericClass", generics: ["T"]) {
121+
Variable(.var, name: "value", type: "T")
122+
}.inherits("BaseClass").final()
123+
124+
let expected = """
125+
final class FinalGenericClass<T>: BaseClass {
126+
var value: T
127+
}
128+
"""
129+
130+
let normalizedGenerated = finalGenericClass.generateCode().normalize()
131+
let normalizedExpected = expected.normalize()
132+
#expect(normalizedGenerated == normalizedExpected)
133+
}
134+
135+
@Test func testClassWithFunctions() {
136+
let classWithFunctions = Class("Calculator") {
137+
Function("add", returns: "Int") {
138+
Parameter(name: "a", type: "Int")
139+
Parameter(name: "b", type: "Int")
140+
} _: {
141+
Return {
142+
VariableExp("a + b")
143+
}
144+
}
145+
}
146+
147+
let expected = """
148+
class Calculator {
149+
func add(a: Int, b: Int) -> Int {
150+
return a + b
151+
}
152+
}
153+
"""
154+
155+
let normalizedGenerated = classWithFunctions.generateCode().normalize()
156+
let normalizedExpected = expected.normalize()
157+
#expect(normalizedGenerated == normalizedExpected)
158+
}
159+
}

Tests/SyntaxKitTests/ClassAndProtocolTests.swift renamed to Tests/SyntaxKitTests/ProtocolTests.swift

Lines changed: 1 addition & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)