File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed
swift/ql/test/library-tests/dataflow/flowsources Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ // --- stubs ---
2
+
3
+ struct URL {
4
+ init ? ( string: String ) { }
5
+
6
+ struct AsyncBytes : AsyncSequence , AsyncIteratorProtocol {
7
+ typealias Element = UInt8
8
+
9
+ func makeAsyncIterator( ) -> AsyncBytes {
10
+ return AsyncBytes ( )
11
+ }
12
+
13
+ mutating func next( ) async -> Element ? { return nil }
14
+
15
+ var lines : AsyncLineSequence < Self > {
16
+ get {
17
+ return AsyncLineSequence < Self > ( )
18
+ }
19
+ }
20
+ }
21
+
22
+ var resourceBytes : URL . AsyncBytes {
23
+ get {
24
+ return AsyncBytes ( )
25
+ }
26
+ }
27
+
28
+ struct AsyncLineSequence < Base> : AsyncSequence , AsyncIteratorProtocol where Base : AsyncSequence , Base. Element == UInt8 {
29
+ typealias Element = String
30
+
31
+ func makeAsyncIterator( ) -> AsyncLineSequence < Base > {
32
+ return AsyncLineSequence < Base > ( )
33
+ }
34
+
35
+ mutating func next( ) async -> Element ? { return nil }
36
+ }
37
+
38
+ var lines : AsyncLineSequence < URL . AsyncBytes > {
39
+ get {
40
+ return AsyncLineSequence < URL . AsyncBytes > ( )
41
+ }
42
+ }
43
+ }
44
+
45
+ func print( _ items: Any ... ) { }
46
+
47
+ // --- tests ---
48
+
49
+ func testURLs( ) async {
50
+ do
51
+ {
52
+ let url = URL ( string: " http://example.com/ " ) !
53
+ let bytes = url. resourceBytes // SOURCE
54
+
55
+ for try await byte in bytes
56
+ {
57
+ print ( byte)
58
+ }
59
+
60
+ let lines = url. lines // SOURCE
61
+
62
+ for try await line in lines
63
+ {
64
+ print ( line)
65
+ }
66
+
67
+ let lines2 = bytes. lines // SOURCE
68
+
69
+ for try await line in lines2
70
+ {
71
+ print ( line)
72
+ }
73
+ } catch {
74
+ // ...
75
+ }
76
+ }
You can’t perform that action at this time.
0 commit comments