Skip to content

Commit 0eca818

Browse files
committed
Add test for Imenu
1 parent 2e9bdc6 commit 0eca818

File tree

4 files changed

+248
-1
lines changed

4 files changed

+248
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
((precedencegroup (identifier "precedenceGroup" 2669 2684) nil)
2+
(operator (identifier "*****" 2629 2634) nil)
3+
(operator (identifier "-----" 2589 2594) nil)
4+
(operator (identifier "+++++" 2550 2555) nil)
5+
(extension (identifier "FooClass" 2385 2393)
6+
((class (identifier "NestedClass1" 2425 2437)
7+
((class (identifier "NestedClass2" 2454 2466)
8+
((class (identifier "NestedClass3" 2487 2499) nil)))))))
9+
(protocol (identifier "FooProtocol" 2125 2136)
10+
((var (identifier "protocolProperty" 2152 2168) nil)
11+
(func (identifier "protocolMethod(a:b:)" 2194 2208) nil)
12+
(init (identifier "init(a:b:c:)" 2236 2240) nil)
13+
(subscript (identifier "subscript(_:bbb:)" 2271 2280) nil)
14+
(associatedtype (identifier "AssociatedType" 2352 2366) nil)))
15+
(struct (identifier "FooStruct" 2096 2105) nil)
16+
(enum (identifier "FooEnum2" 2031 2039)
17+
((case (identifier "case1" 2056 2061) nil)
18+
(case (identifier "case2" 2076 2081) nil)))
19+
(enum (identifier "FooEnum1" 1896 1904)
20+
((case (identifier "case1" 1943 1948) nil)
21+
(case (identifier "case2" 1974 1979) nil)
22+
(case (identifier "case3" 2003 2008) nil)))
23+
(class (identifier "FooClass" 530 538)
24+
((var (identifier "classVariable1" 607 621) nil)
25+
(class (identifier "final" 657 662) nil)
26+
(var (identifier "compuatedProperty" 685 702) nil)
27+
(var (identifier "observedProperty" 844 860) nil)
28+
(typealias (identifier "TypeAlias" 1008 1017) nil)
29+
(func (identifier "function1(aaa:_:ddd:eee:)" 1072 1081) nil)
30+
(func (identifier "function2()" 1277 1286) nil)
31+
(func (identifier "function3(a:)" 1360 1369) nil)
32+
(func (identifier "+(_:_:)" 1504 1505) nil)
33+
(subscript (identifier "subscript(_:bbb:)" 1666 1675) nil)
34+
(init (identifier "init(a:)" 1814 1818) nil)
35+
(init (identifier "init(b:)" 1841 1845) nil)
36+
(deinit (identifier "deinit" 1868 1874) nil)))
37+
(var (identifier "globalVariable2" 493 508) nil)
38+
(var (identifier "globalVariable1" 463 478) nil)
39+
(let (identifier "globalConstant2" 429 444) nil)
40+
(let (identifier "globalConstant1" 399 414) nil))

test/swift-files/imenu/imenu.swift

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
@AAA import FooModule1
2+
@BBB(1, 2, 3) import FooModule2.SubModule1
3+
import typealias FooModule3.ImportedTypeAlias
4+
import struct FooModule3.ImportedStruct
5+
import class FooModule3.ImportedClass
6+
import enum FooModule3.ImportedEnum
7+
import protocol FooModule3.ImportedProtocol
8+
import let FooModule3.importedConstant
9+
import var FooModule3.importedVariable
10+
import func FooModule3.importedFunction
11+
12+
@AAA let globalConstant1 = 1,
13+
globalConstant2: Int = 2
14+
@AAA var globalVariable1 = 1,
15+
globalVariable2: Int = 2
16+
17+
@AAA class FooClass<A, B, C>: AAA {
18+
@AAA private unowned(safe) lazy class final var classVariable1: AAA = AAA()
19+
@AAA public class final {
20+
}
21+
22+
@AAA var compuatedProperty: Int {
23+
get {
24+
return 1
25+
}
26+
27+
set {
28+
let a = 1
29+
var b = 2
30+
}
31+
}
32+
33+
@AAA var observedProperty Int {
34+
willSet(a) {
35+
let a = 1
36+
var b = 2
37+
}
38+
39+
didSet(a) {
40+
}
41+
}
42+
43+
@AAA internal typealias TypeAlias<A: AA, B: BB, C: CC> = AAA
44+
45+
@AAA class final func function1<A: AA, B: BB, C: CC>(aaa bbb: Int, _ ccc: Int, ddd: Int = 1, eee: inout Int = 2) throws -> AAA {
46+
let a = 1
47+
var b = 2
48+
49+
return AAA()
50+
}
51+
@AAA class final func function2() rethrows -> AAA {
52+
return AAA()
53+
}
54+
@AAA class final func function3(a: Int...) rethrows -> AAA {
55+
return AAA()
56+
}
57+
58+
// Argument labels of operators are always "_"
59+
@AAA class final func + <A: AA, B: BB, C: CC>(lhs: FooClass1<A, B, C>, rhs: Int) rethrows -> AAA {
60+
return AAA()
61+
}
62+
63+
// Default argument labels of subscript are "_".
64+
subscript<A: AA, B: BB, C: CC>(aaa: Int, bbb ccc: Int) -> AAA {
65+
get {
66+
return AAA()
67+
}
68+
set {
69+
}
70+
}
71+
72+
init?(a: Int) {
73+
}
74+
75+
init!(b: Int) {
76+
}
77+
78+
deinit {
79+
}
80+
}
81+
82+
@AAA enum FooEnum1<A, B, C>: FooProtocol {
83+
@AAA case case1(aaa: Int, bbb ccc: Int), case2
84+
@AAA indirect case case3(eee: FooEnum)
85+
}
86+
87+
enum FooEnum2: Int {
88+
case case1 = 1,
89+
case2 = 2
90+
}
91+
92+
struct FooStruct: AAA {
93+
}
94+
95+
protocol FooProtocol: AAA {
96+
var protocolProperty: Int { get set}
97+
func protocolMethod(a: Int, b: Int) -> Int
98+
init(a: Int, b: Int, c d: Int)
99+
subscript<A: AA, B: BB, C: CC>(aaa: Int, bbb ccc: Int) -> AAA
100+
associatedtype AssociatedType: AAA
101+
}
102+
103+
extension FooClass: BBB where A = Int {
104+
class NestedClass1 {
105+
class NestedClass2 {
106+
class NestedClass3 {
107+
}
108+
}
109+
}
110+
}
111+
112+
infix operator +++++: precedenceGroup
113+
prefix operator -----: precedenceGroup
114+
postfix operator *****: precedenceGroup
115+
116+
precedencegroup precedenceGroup {
117+
higherThan: a
118+
lowerThan: a
119+
associativity: left
120+
assignment: true
121+
}

test/swift-mode-test-imenu.el

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
;;; swift-mode-test-imenu.el --- Test for swift-mode: Imenu -*- lexical-binding: t -*-
2+
3+
;; Copyright (C) 2019 taku0
4+
5+
;; Authors: taku0 (http://github.com/taku0)
6+
;;
7+
;; Version: 7.1.0
8+
;; Package-Requires: ((emacs "24.4") (seq "2.3"))
9+
;; Keywords: languages swift
10+
;; URL: https://github.com/swift-emacs/swift-mode
11+
12+
;; This file is not part of GNU Emacs.
13+
14+
;; This program is free software: you can redistribute it and/or modify
15+
;; it under the terms of the GNU General Public License as published by
16+
;; the Free Software Foundation, either version 3 of the License, or
17+
;; (at your option) any later version.
18+
19+
;; This program is distributed in the hope that it will be useful,
20+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
;; GNU General Public License for more details.
23+
24+
;; You should have received a copy of the GNU General Public License
25+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
27+
;;; Commentary:
28+
29+
;; Test for swift-mode: Imenu.
30+
;; Execute swift-mode:run-test:imenu interactively or in batch mode.
31+
32+
;;; Code:
33+
34+
(require 'swift-mode)
35+
(require 'swift-mode-imenu)
36+
37+
(defun swift-mode:run-test:imenu
38+
(&optional error-buffer error-counts progress-reporter)
39+
"Run `imenu' test for `swift-mode'.
40+
41+
ERROR-BUFFER is the buffer to output errors.
42+
ERROR-COUNTS is a association list holding counts of errors. Updated
43+
destructively.
44+
PROGRESS-REPORTER is the progress-reporter."
45+
(interactive)
46+
(if (not swift-mode:test:running)
47+
(swift-mode:run-test '(swift-mode:run-test:imenu))
48+
(setq default-directory
49+
(concat (file-name-as-directory swift-mode:test:basedir)
50+
(file-name-as-directory "swift-files")
51+
"imenu"))
52+
(dolist (swift-file (file-expand-wildcards "*.swift"))
53+
(redisplay)
54+
(with-temp-buffer
55+
(switch-to-buffer (current-buffer))
56+
(insert-file-contents-literally swift-file)
57+
(swift-mode)
58+
(let* ((actual (swift-mode:scan-declarations))
59+
(expected-file-name (concat
60+
(file-name-sans-extension swift-file)
61+
"-expected.el"))
62+
(expected
63+
(with-temp-buffer
64+
(insert-file-contents-literally expected-file-name)
65+
(read (current-buffer))))
66+
(status (if (equal actual expected) 'ok 'error))
67+
(count-assoc (assq status error-counts)))
68+
(when (eq status 'error)
69+
(swift-mode:show-error
70+
error-buffer swift-file 0
71+
"error"
72+
(concat
73+
"expected: "
74+
(prin1-to-string expected)
75+
" but: "
76+
(prin1-to-string actual))))
77+
(setcdr count-assoc (1+ (cdr count-assoc)))))
78+
(when (not noninteractive)
79+
(progress-reporter-update progress-reporter)))))
80+
81+
(provide 'swift-mode-test-imenu)
82+
83+
;;; swift-mode-test-imenu.el ends here
84+

test/swift-mode-test.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
(require 'swift-mode-test-indent)
3535
(require 'swift-mode-test-beginning-of-defun)
36+
(require 'swift-mode-test-imenu)
3637

3738
(defvar swift-mode:test:basedir
3839
(file-name-directory (or load-file-name buffer-file-name)))
@@ -51,7 +52,8 @@ Return the error-buffer"
5152

5253
(defvar swift-mode:tests
5354
'(swift-mode:run-test:indent
54-
swift-mode:run-test:beginning-of-defun))
55+
swift-mode:run-test:beginning-of-defun
56+
swift-mode:run-test:imenu))
5557

5658
(defun swift-mode:run-test (&optional tests)
5759
"Run TESTS for `swift-mode'."

0 commit comments

Comments
 (0)