File: cursor_groups.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (85 lines) | stat: -rw-r--r-- 3,108 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// RUN: %empty-directory(%t)
// RUN: mkdir -p %t/mods
// RUN: split-file --leading-lines %s %t

// RUN: %target-swift-frontend -module-name Foo -emit-module -emit-module-path %t/mods/Foo.swiftmodule -emit-module-doc -emit-module-doc-path %t/mods/Foo.swiftdoc -group-info-path %t/group.json %t/Foo.swift
// RUN: %target-swift-frontend -module-name Bar -emit-module -emit-module-path %t/mods/Bar.swiftmodule -emit-module-doc -emit-module-doc-path %t/mods/Bar.swiftdoc -I%t/mods %t/Bar.swift

//--- group.json
{
  "TestGroup": [
    "Foo.swift",
  ]
}

//--- Foo.swift
public protocol FooProto {
  associatedtype T
}

public extension FooProto {
  func fooExt() {}
}

public extension FooProto {
  func fooExt2() {}
}

public extension FooProto where T == Int {
  func fooIntExt() {}
}

public struct FooStruct: FooProto {
  public typealias T = Int
  public func foo() {}
}

//--- Bar.swift
import Foo

public extension FooProto {
  func barExt() {}
}

public extension FooProto where T == Int {
  func barIntExt() {}
}

//--- Baz.swift
import Foo
import Bar

// The generated interface for Foo will contain all the extensions as well
// as the "synthesized extension" on FooStruct itself, ie. the extension
// functions are added to FooStruct as if they were written there in the source.
//
// We prefer jumping to these declarations rather than the one in the extension,
// but also have to be careful not to attempt to do so for extensions outside
// of the original module - these will *not* have "synthesized extensions"
// in their generated interface.
func test(f: FooStruct) {
  // RUN: %sourcekitd-test -req=cursor -pos=%(line+1):5 %t/Baz.swift -- %t/Baz.swift -I %t/mods -target %target-triple | %FileCheck --check-prefix=CHECK-EXT %t/Baz.swift
  f.fooExt()
  // CHECK-EXT: 3Foo0A5ProtoPAAE6fooExtyyF::SYNTHESIZED::s:3Foo0A6StructV
  // CHECK-EXT: <Group>TestGroup</Group>

  // RUN: %sourcekitd-test -req=cursor -pos=%(line+1):5 %t/Baz.swift -- %t/Baz.swift -I %t/mods -target %target-triple | %FileCheck --check-prefix=CHECK-EXT2 %t/Baz.swift
  f.fooExt2()
  // CHECK-EXT2: s:3Foo0A5ProtoPAAE7fooExt2yyF::SYNTHESIZED::s:3Foo0A6StructV
  // CHECK-EXT2: <Group>TestGroup</Group>

  // RUN: %sourcekitd-test -req=cursor -pos=%(line+1):5 %t/Baz.swift -- %t/Baz.swift -I %t/mods -target %target-triple | %FileCheck --check-prefix=CHECK-INTEXT %t/Baz.swift
  f.fooIntExt()
  // CHECK-INTEXT: s:3Foo0A5ProtoPAASi1TRtzrlE9fooIntExtyyF::SYNTHESIZED::s:3Foo0A6StructV
  // CHECK-INTEXT: <Group>TestGroup</Group>

  // RUN: %sourcekitd-test -req=cursor -pos=%(line+1):5 %t/Baz.swift -- %t/Baz.swift -I %t/mods -target %target-triple | %FileCheck --check-prefix=CHECK-BAREXT %t/Baz.swift
  f.barExt()
  // CHECK-BAREXT: s:3Foo0A5ProtoP3BarE6barExtyyF
  // CHECK-BAREXT-NOT: <Group>TestGroup</Group>

  // RUN: %sourcekitd-test -req=cursor -pos=%(line+1):5 %t/Baz.swift -- %t/Baz.swift -I %t/mods -target %target-triple | %FileCheck --check-prefix=CHECK-BARINTEXT %t/Baz.swift
  f.barIntExt()
  // CHECK-BARINTEXT: s:3Foo0A5ProtoP3BarSi1TRtzrlE9barIntExtyyF
  // CHECK-BARINTEXT-NOT: <Group>TestGroup</Group>
}