1import Foundation
2
3class FileImporter {
4    func scanImports(atContent content: String) -> Set<String> {
5        var imports = Set<String>()
6        let lines = content.components(separatedBy: .newlines)
7
8        for line in lines {
9            if line.hasPrefix("import ") {
10                let importStatement = line.dropFirst(7)
11                imports.insert(String(importStatement))
12            }
13        }
14
15        return imports
16    }
17}
18
19func tests() {
20    let sut = FileImporter()
21    let code = """
22    import a.swift
23    import b.swift
24    import some_really_long_named_file.swift
25
26    let a = B()
27    """
28
29    let output = sut.scanImports(atContent: code)
30    let expectedOutput: Set<String> = ["a.swift", "b.swift", "some_really_long_named_file.swift"]
31
32    assert(output == expectedOutput)
33}
34
35tests()
36
37import Foundation
38
39class FileImporter {
40    func scanImports(atContent content: String) -> Set<String> {
41        var imports = Set<String>()
42        let lines = content.components(separatedBy: .newlines)
43
44        for line in lines {
45            if line.hasPrefix("import ") {
46                let importStatement = line.dropFirst(7)
47                imports.insert(String(importStatement))
48            }
49        }
50
51        return imports
52    }
53}
54
55func tests() {
56    let sut = FileImporter()
57    let code = """
58    import a.swift
59    import b.swift
60    import some_really_long_named_file.swift
61
62    let a = B()
63    """
64
65    let output = sut.scanImports(atContent: code)
66    let expectedOutput: Set<String> = ["a.swift", "b.swift", "some_really_long_named_file.swift"]
67
68    assert(output == expectedOutput)
69}
70
71tests() func tests() {
72	let sut = FileImporter()
73	let code = """
74	import a.swift
75	import b.swift
76	import some_really_long_named_file.swift
77
78	let a = B()
79	"""
80	
81	let output = sut.scanImports(atContent: code)
82	let expectedOutput: Set<String> = ["a.swift", "b.swift", "some_really_long_named_file.swift"]
83	
84	assert(output == expectedOutput)
85}
86
87tests()
/var/folders/m9/xbnrbp5d1qb1pm_45jmsr5380000gn/T/fileimporter.swift.no-extension:71:8: error: consecutive statements on a line must be separated by ';'
69 | }
70 | 
71 | tests() func tests() {
   |        `- error: consecutive statements on a line must be separated by ';'
72 | 	let sut = FileImporter()
73 | 	let code = """

/var/folders/m9/xbnrbp5d1qb1pm_45jmsr5380000gn/T/fileimporter.swift.no-extension:35:1: error: ambiguous use of 'tests()'
17 | }
18 | 
19 | func tests() {
   |      `- note: found this candidate 
20 |     let sut = FileImporter()
21 |     let code = """
   :
33 | }
34 | 
35 | tests()
   | `- error: ambiguous use of 'tests()'
36 | 
37 | import Foundation
   :
53 | }
54 | 
55 | func tests() {
   |      `- note: found this candidate 
56 |     let sut = FileImporter()
57 |     let code = """
   :
69 | }
70 | 
71 | tests() func tests() {
   |              `- note: found this candidate 
72 | 	let sut = FileImporter()
73 | 	let code = """

/var/folders/m9/xbnrbp5d1qb1pm_45jmsr5380000gn/T/fileimporter.swift.no-extension:39:7: error: invalid redeclaration of 'FileImporter'
37 | import Foundation
38 | 
39 | class FileImporter {
   |       `- error: invalid redeclaration of 'FileImporter'
40 |     func scanImports(atContent content: String) -> Set {
41 |         var imports = Set()

/var/folders/m9/xbnrbp5d1qb1pm_45jmsr5380000gn/T/fileimporter.swift.no-extension:55:6: error: invalid redeclaration of 'tests()'
53 | }
54 | 
55 | func tests() {
   |      `- error: invalid redeclaration of 'tests()'
56 |     let sut = FileImporter()
57 |     let code = """

/var/folders/m9/xbnrbp5d1qb1pm_45jmsr5380000gn/T/fileimporter.swift.no-extension:71:1: error: ambiguous use of 'tests()'
17 | }
18 | 
19 | func tests() {
   |      `- note: found this candidate 
20 |     let sut = FileImporter()
21 |     let code = """
   :
69 | }
70 | 
71 | tests() func tests() {
   | |            `- note: found this candidate 
   | `- error: ambiguous use of 'tests()'
72 | 	let sut = FileImporter()
73 | 	let code = """

/var/folders/m9/xbnrbp5d1qb1pm_45jmsr5380000gn/T/fileimporter.swift.no-extension:71:14: error: invalid redeclaration of 'tests()'
69 | }
70 | 
71 | tests() func tests() {
   |              `- error: invalid redeclaration of 'tests()'
72 | 	let sut = FileImporter()
73 | 	let code = """