|
| 1 | +@testable import Core |
| 2 | +import Foundation |
| 3 | +import Testing |
| 4 | + |
| 5 | +struct DeclarationTests { |
| 6 | + /// Sort by file name, line number, and name. |
| 7 | + @Test func testModifiers() async throws { |
| 8 | + let foo = Declaration(file: "a.swift", line: "var foo = 0", at: 0, type: "var", name: "foo", modifiers: [ |
| 9 | + "private", |
| 10 | + "@IBOutlet", |
| 11 | + "override", |
| 12 | + ]) |
| 13 | + #expect(foo.isOverride == true) |
| 14 | + #expect(foo.isPrivate == true) |
| 15 | + #expect(foo.isIBLinked == true) |
| 16 | + |
| 17 | + let foo2 = Declaration(file: "a.swift", line: "var foo = 0", at: 0, type: "var", name: "foo", modifiers: [ |
| 18 | + "override", |
| 19 | + ]) |
| 20 | + #expect(foo2.isOverride == true) |
| 21 | + #expect(foo2.isPrivate == false) |
| 22 | + #expect(foo2.isIBLinked == false) |
| 23 | + |
| 24 | + let foo3 = Declaration(file: "a.swift", line: "var foo = 0", at: 0, type: "var", name: "foo", modifiers: [ |
| 25 | + "private", |
| 26 | + ]) |
| 27 | + #expect(foo3.isOverride == false) |
| 28 | + #expect(foo3.isPrivate == true) |
| 29 | + #expect(foo3.isIBLinked == false) |
| 30 | + |
| 31 | + let foo4 = Declaration(file: "a.swift", line: "var foo = 0", at: 0, type: "var", name: "foo", modifiers: [ |
| 32 | + "@IBOutlet", |
| 33 | + ]) |
| 34 | + #expect(foo4.isOverride == false) |
| 35 | + #expect(foo4.isPrivate == false) |
| 36 | + #expect(foo4.isIBLinked == true) |
| 37 | + } |
| 38 | + |
| 39 | + /// Sort by file name, line number, and name. |
| 40 | + @Test func testDeclarationsSortCorrectly() async throws { |
| 41 | + let a1 = Declaration(file: "a.swift", line: "var foo = 0", at: 0, type: "var", name: "foo", modifiers: []) |
| 42 | + let a2 = Declaration(file: "a.swift", line: "var bar = 0, var baz = 1", at: 1, type: "var", name: "bar", modifiers: []) |
| 43 | + let a3 = Declaration(file: "a.swift", line: "var bar = 0, var baz = 1", at: 1, type: "var", name: "baz", modifiers: []) |
| 44 | + let b = Declaration(file: "b.swift", line: "var bar = 0", at: 0, type: "var", name: "bar", modifiers: []) |
| 45 | + let c = Declaration(file: "c.swift", line: "var bar = 0", at: 0, type: "var", name: "bar", modifiers: []) |
| 46 | + let declarations: [Declaration] = [a1, a2, a3, b, c].shuffled().sorted() |
| 47 | + #expect(declarations == [a1, a2, a3, b, c]) |
| 48 | + } |
| 49 | +} |
0 commit comments