branch: elpa/swift-mode commit 0eca818cc83ab87d14844e85f0edd27620489a3b Author: taku0 <mxxouy6x3m_git...@tatapa.org> Commit: taku0 <mxxouy6x3m_git...@tatapa.org>
Add test for Imenu --- test/swift-files/imenu/imenu-expected.el | 40 ++++++++++ test/swift-files/imenu/imenu.swift | 121 +++++++++++++++++++++++++++++++ test/swift-mode-test-imenu.el | 84 +++++++++++++++++++++ test/swift-mode-test.el | 4 +- 4 files changed, 248 insertions(+), 1 deletion(-) diff --git a/test/swift-files/imenu/imenu-expected.el b/test/swift-files/imenu/imenu-expected.el new file mode 100644 index 0000000..da1ac2d --- /dev/null +++ b/test/swift-files/imenu/imenu-expected.el @@ -0,0 +1,40 @@ +((precedencegroup (identifier "precedenceGroup" 2669 2684) nil) + (operator (identifier "*****" 2629 2634) nil) + (operator (identifier "-----" 2589 2594) nil) + (operator (identifier "+++++" 2550 2555) nil) + (extension (identifier "FooClass" 2385 2393) + ((class (identifier "NestedClass1" 2425 2437) + ((class (identifier "NestedClass2" 2454 2466) + ((class (identifier "NestedClass3" 2487 2499) nil))))))) + (protocol (identifier "FooProtocol" 2125 2136) + ((var (identifier "protocolProperty" 2152 2168) nil) + (func (identifier "protocolMethod(a:b:)" 2194 2208) nil) + (init (identifier "init(a:b:c:)" 2236 2240) nil) + (subscript (identifier "subscript(_:bbb:)" 2271 2280) nil) + (associatedtype (identifier "AssociatedType" 2352 2366) nil))) + (struct (identifier "FooStruct" 2096 2105) nil) + (enum (identifier "FooEnum2" 2031 2039) + ((case (identifier "case1" 2056 2061) nil) + (case (identifier "case2" 2076 2081) nil))) + (enum (identifier "FooEnum1" 1896 1904) + ((case (identifier "case1" 1943 1948) nil) + (case (identifier "case2" 1974 1979) nil) + (case (identifier "case3" 2003 2008) nil))) + (class (identifier "FooClass" 530 538) + ((var (identifier "classVariable1" 607 621) nil) + (class (identifier "final" 657 662) nil) + (var (identifier "compuatedProperty" 685 702) nil) + (var (identifier "observedProperty" 844 860) nil) + (typealias (identifier "TypeAlias" 1008 1017) nil) + (func (identifier "function1(aaa:_:ddd:eee:)" 1072 1081) nil) + (func (identifier "function2()" 1277 1286) nil) + (func (identifier "function3(a:)" 1360 1369) nil) + (func (identifier "+(_:_:)" 1504 1505) nil) + (subscript (identifier "subscript(_:bbb:)" 1666 1675) nil) + (init (identifier "init(a:)" 1814 1818) nil) + (init (identifier "init(b:)" 1841 1845) nil) + (deinit (identifier "deinit" 1868 1874) nil))) + (var (identifier "globalVariable2" 493 508) nil) + (var (identifier "globalVariable1" 463 478) nil) + (let (identifier "globalConstant2" 429 444) nil) + (let (identifier "globalConstant1" 399 414) nil)) diff --git a/test/swift-files/imenu/imenu.swift b/test/swift-files/imenu/imenu.swift new file mode 100644 index 0000000..3a6ed38 --- /dev/null +++ b/test/swift-files/imenu/imenu.swift @@ -0,0 +1,121 @@ +@AAA import FooModule1 +@BBB(1, 2, 3) import FooModule2.SubModule1 +import typealias FooModule3.ImportedTypeAlias +import struct FooModule3.ImportedStruct +import class FooModule3.ImportedClass +import enum FooModule3.ImportedEnum +import protocol FooModule3.ImportedProtocol +import let FooModule3.importedConstant +import var FooModule3.importedVariable +import func FooModule3.importedFunction + +@AAA let globalConstant1 = 1, + globalConstant2: Int = 2 +@AAA var globalVariable1 = 1, + globalVariable2: Int = 2 + +@AAA class FooClass<A, B, C>: AAA { + @AAA private unowned(safe) lazy class final var classVariable1: AAA = AAA() + @AAA public class final { + } + + @AAA var compuatedProperty: Int { + get { + return 1 + } + + set { + let a = 1 + var b = 2 + } + } + + @AAA var observedProperty Int { + willSet(a) { + let a = 1 + var b = 2 + } + + didSet(a) { + } + } + + @AAA internal typealias TypeAlias<A: AA, B: BB, C: CC> = AAA + + @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 { + let a = 1 + var b = 2 + + return AAA() + } + @AAA class final func function2() rethrows -> AAA { + return AAA() + } + @AAA class final func function3(a: Int...) rethrows -> AAA { + return AAA() + } + + // Argument labels of operators are always "_" + @AAA class final func + <A: AA, B: BB, C: CC>(lhs: FooClass1<A, B, C>, rhs: Int) rethrows -> AAA { + return AAA() + } + + // Default argument labels of subscript are "_". + subscript<A: AA, B: BB, C: CC>(aaa: Int, bbb ccc: Int) -> AAA { + get { + return AAA() + } + set { + } + } + + init?(a: Int) { + } + + init!(b: Int) { + } + + deinit { + } +} + +@AAA enum FooEnum1<A, B, C>: FooProtocol { + @AAA case case1(aaa: Int, bbb ccc: Int), case2 + @AAA indirect case case3(eee: FooEnum) +} + +enum FooEnum2: Int { + case case1 = 1, + case2 = 2 +} + +struct FooStruct: AAA { +} + +protocol FooProtocol: AAA { + var protocolProperty: Int { get set} + func protocolMethod(a: Int, b: Int) -> Int + init(a: Int, b: Int, c d: Int) + subscript<A: AA, B: BB, C: CC>(aaa: Int, bbb ccc: Int) -> AAA + associatedtype AssociatedType: AAA +} + +extension FooClass: BBB where A = Int { + class NestedClass1 { + class NestedClass2 { + class NestedClass3 { + } + } + } +} + +infix operator +++++: precedenceGroup +prefix operator -----: precedenceGroup +postfix operator *****: precedenceGroup + +precedencegroup precedenceGroup { + higherThan: a + lowerThan: a + associativity: left + assignment: true +} diff --git a/test/swift-mode-test-imenu.el b/test/swift-mode-test-imenu.el new file mode 100644 index 0000000..046dff5 --- /dev/null +++ b/test/swift-mode-test-imenu.el @@ -0,0 +1,84 @@ +;;; swift-mode-test-imenu.el --- Test for swift-mode: Imenu -*- lexical-binding: t -*- + +;; Copyright (C) 2019 taku0 + +;; Authors: taku0 (http://github.com/taku0) +;; +;; Version: 7.1.0 +;; Package-Requires: ((emacs "24.4") (seq "2.3")) +;; Keywords: languages swift +;; URL: https://github.com/swift-emacs/swift-mode + +;; This file is not part of GNU Emacs. + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Test for swift-mode: Imenu. +;; Execute swift-mode:run-test:imenu interactively or in batch mode. + +;;; Code: + +(require 'swift-mode) +(require 'swift-mode-imenu) + +(defun swift-mode:run-test:imenu + (&optional error-buffer error-counts progress-reporter) + "Run `imenu' test for `swift-mode'. + +ERROR-BUFFER is the buffer to output errors. +ERROR-COUNTS is a association list holding counts of errors. Updated +destructively. +PROGRESS-REPORTER is the progress-reporter." + (interactive) + (if (not swift-mode:test:running) + (swift-mode:run-test '(swift-mode:run-test:imenu)) + (setq default-directory + (concat (file-name-as-directory swift-mode:test:basedir) + (file-name-as-directory "swift-files") + "imenu")) + (dolist (swift-file (file-expand-wildcards "*.swift")) + (redisplay) + (with-temp-buffer + (switch-to-buffer (current-buffer)) + (insert-file-contents-literally swift-file) + (swift-mode) + (let* ((actual (swift-mode:scan-declarations)) + (expected-file-name (concat + (file-name-sans-extension swift-file) + "-expected.el")) + (expected + (with-temp-buffer + (insert-file-contents-literally expected-file-name) + (read (current-buffer)))) + (status (if (equal actual expected) 'ok 'error)) + (count-assoc (assq status error-counts))) + (when (eq status 'error) + (swift-mode:show-error + error-buffer swift-file 0 + "error" + (concat + "expected: " + (prin1-to-string expected) + " but: " + (prin1-to-string actual)))) + (setcdr count-assoc (1+ (cdr count-assoc))))) + (when (not noninteractive) + (progress-reporter-update progress-reporter))))) + +(provide 'swift-mode-test-imenu) + +;;; swift-mode-test-imenu.el ends here + diff --git a/test/swift-mode-test.el b/test/swift-mode-test.el index 7bd665e..8facd3d 100644 --- a/test/swift-mode-test.el +++ b/test/swift-mode-test.el @@ -33,6 +33,7 @@ (require 'swift-mode-test-indent) (require 'swift-mode-test-beginning-of-defun) +(require 'swift-mode-test-imenu) (defvar swift-mode:test:basedir (file-name-directory (or load-file-name buffer-file-name))) @@ -51,7 +52,8 @@ Return the error-buffer" (defvar swift-mode:tests '(swift-mode:run-test:indent - swift-mode:run-test:beginning-of-defun)) + swift-mode:run-test:beginning-of-defun + swift-mode:run-test:imenu)) (defun swift-mode:run-test (&optional tests) "Run TESTS for `swift-mode'."