File: callsites.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 (90 lines) | stat: -rw-r--r-- 4,578 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
86
87
88
89
90
func /*defaults:def*/withDefaults(_ xx: Int = 4, y: Int = 2, x: Int = 1) {}

// valid
/*defaults:call*/withDefaults()
/*defaults:call*/withDefaults(2)
/*defaults:call*/withDefaults(y: 2)
/*defaults:call*/withDefaults(2, x: 3)
/*defaults:call*/withDefaults(y: 2, x: 3)
/*defaults:call*/withDefaults(2, y: 1, x: 4)

// false positives
/*defaults:call*/withDefaults(y: 2, 3)
/*defaults:call*/withDefaults(y: 2, 4, x: 3)

// invalid
/*defaults:call*/withDefaults(x: 2, y: 3)


func /*trailing:def*/withTrailingClosure(x: Int, y: () -> Int) {}

// valid
/*trailing:call*/withTrailingClosure(x: 2, y: { return 1})
/*trailing:call*/withTrailingClosure(x: 2) { return 1}
/*trailing:call*/withTrailingClosure(x: 2)
{ return 1}
// invalid
/*trailing:call*/withTrailingClosure(x: 1, y: 2) { return 1}
/*trailing:call*/withTrailingClosure(x: 1, y: 2) { return 1}

func /*trailing-only:def*/trailingOnly(a: () -> ()) {}
/*trailing-only:call*/trailingOnly(a: {})
/*trailing-only:call*/trailingOnly {}


func /*varargs:def*/withVarargs(x: Int..., y: Int, _: Int) {}

// valid
/*varargs:call*/withVarargs(x: 1, 2, 3, y: 2, 4)
/*varargs:call*/withVarargs(y: 2, 4)

// false positives
/*varargs:call*/withVarargs(x: 1, y: 2, 4, 5)

//invalid
/*varargs:call*/withVarargs(2, y: 2)


func /*varargs2:def*/withVarargs(x: Int, y: Int, _: Int...) {}

// valid
/*varargs2:call*/withVarargs(x: 1, y: 2, 4, 5)
/*varargs2:call*/withVarargs(x: 1, y: 2)

// false positive
/*varargs2:call*/withVarargs(x: 1, 2, y: 2, 4)


func /*mixed:def*/withAllOfTheAbove(x: Int = 2, _: Int..., z: Int = 2, c: () -> Int) {}

// valid
/*mixed:call*/withAllOfTheAbove(2){ return 1 }
/*mixed:call*/withAllOfTheAbove(x: 1, 2, c: {return 1})
/*mixed:call*/withAllOfTheAbove(x: 1, c: {return 1})
/*mixed:call*/withAllOfTheAbove(1, z: 1) { return 1 }
/*mixed:call*/withAllOfTheAbove(1, 2, c: {return 1})

// false positives
/*mixed:call*/withAllOfTheAbove(z: 1, 2, c: {return 1})

// REQUIRES: swift_swift_parser
// RUN: %empty-directory(%t.result)
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="defaults" -is-function-like -old-name "withDefaults(_:y:x:)" -new-name "betterName(x:y:z:)" >> %t.result/callsites_defaults.swift
// RUN: diff -u %S/Outputs/callsites/defaults.swift.expected %t.result/callsites_defaults.swift
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="trailing" -is-function-like -old-name "withTrailingClosure(x:y:)" -new-name "betterName(a:b:)" >> %t.result/callsites_trailing.swift
// RUN: diff -u %S/Outputs/callsites/trailing.swift.expected %t.result/callsites_trailing.swift
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="trailing-only" -is-function-like -old-name "trailingOnly(a:)" -new-name "betterName(b:)" >> %t.result/callsites_trailing_only.swift
// RUN: diff -u %S/Outputs/callsites/trailing_only.swift.expected %t.result/callsites_trailing_only.swift
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="varargs" -is-function-like -old-name "withVarargs(x:y:_:)" -new-name "betterName(a:b:c:)" >> %t.result/callsites_varargs.swift
// RUN: diff -u %S/Outputs/callsites/varargs.swift.expected %t.result/callsites_varargs.swift
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="varargs2" -is-function-like -old-name "withVarargs(x:y:_:)" -new-name "betterName(a:b:c:)" >> %t.result/callsites_varargs2.swift
// RUN: diff -u %S/Outputs/callsites/varargs2.swift.expected %t.result/callsites_varargs2.swift
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="mixed" -is-function-like -old-name "withAllOfTheAbove(x:_:z:c:)" -new-name "betterName(a:b:c:d:)" >> %t.result/callsites_mixed.swift
// RUN: diff -u %S/Outputs/callsites/mixed.swift.expected %t.result/callsites_mixed.swift
// RUN: %empty-directory(%t.ranges)
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="defaults" -is-function-like -old-name "withDefaults(_:y:x:)" >> %t.ranges/callsites_defaults.swift
// RUN: diff -u %S/Outputs/callsites/defaults.swift.expected %t.ranges/callsites_defaults.swift
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="trailing" -is-function-like -old-name "withTrailingClosure(x:y:)" >> %t.ranges/callsites_trailing.swift
// RUN: diff -u %S/Outputs/callsites/trailing.swift.expected %t.ranges/callsites_trailing.swift
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="trailing-only" -is-function-like -old-name "trailingOnly(a:)" >> %t.ranges/callsites_trailing_only.swift
// RUN: diff -u %S/Outputs/callsites/trailing_only.swift.expected %t.ranges/callsites_trailing_only.swift