diff options
Diffstat (limited to 'test/lisp/cedet')
33 files changed, 3119 insertions, 179 deletions
diff --git a/test/lisp/cedet/cedet-files-tests.el b/test/lisp/cedet/cedet-files-tests.el new file mode 100644 index 00000000000..5502d424314 --- /dev/null +++ b/test/lisp/cedet/cedet-files-tests.el @@ -0,0 +1,54 @@ +;;; cedet-files-tests.el --- Tests for cedet-files.el -*- lexical-binding:t -*- + +;; Copyright (C) 2008-2021 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Moved here from test/manual/cedet/cedet-utests.el + +;;; Code: + +(require 'ert) +(require 'cedet-files) + +(defvar cedet-files-utest-list + '( + ( "/home/me/src/myproj/src/foo.c" . "!home!me!src!myproj!src!foo.c" ) + ( "c:/work/myproj/foo.el" . "!drive_c!work!myproj!foo.el" ) + ( "//windows/proj/foo.java" . "!!windows!proj!foo.java" ) + ( "/home/me/proj!bang/foo.c" . "!home!me!proj!!bang!foo.c" ) + ) + "List of different file names to test. +Each entry is a cons cell of ( FNAME . CONVERTED ) +where FNAME is some file name, and CONVERTED is what it should be +converted into.") + +(ert-deftest cedet-files-utest () + "Test out some file name conversions." + (interactive) + (dolist (FT cedet-files-utest-list) + (let ((dir->file (cedet-directory-name-to-file-name (car FT) t)) + (file->dir (cedet-file-name-to-directory-name (cdr FT) t))) + (should (string= (cdr FT) dir->file)) + (should (string= file->dir (car FT)))))) + +(provide 'cedet-files-tests) + +;;; cedet-files-tests.el ends here diff --git a/test/lisp/cedet/semantic-utest-c.el b/test/lisp/cedet/semantic-utest-c.el index a7cbe116c2e..d08c79cad3e 100644 --- a/test/lisp/cedet/semantic-utest-c.el +++ b/test/lisp/cedet/semantic-utest-c.el @@ -43,7 +43,6 @@ (defvar semantic-lex-c-nested-namespace-ignore-second) ;;; Code: -;;;###autoload (ert-deftest semantic-test-c-preprocessor-simulation () "Run parsing test for C from the test directory." :tags '(:expensive-test) diff --git a/test/lisp/cedet/semantic-utest-fmt.el b/test/lisp/cedet/semantic-utest-fmt.el deleted file mode 100644 index d6e5ce7a0fd..00000000000 --- a/test/lisp/cedet/semantic-utest-fmt.el +++ /dev/null @@ -1,127 +0,0 @@ -;;; cedet/semantic-utest-fmt.el --- Parsing / Formatting tests -*- lexical-binding:t -*- - -;;; Copyright (C) 2003-2004, 2007-2021 Free Software Foundation, Inc. - -;; Author: Eric M. Ludlam <zappo@gnu.org> - -;; This file is part of GNU Emacs. - -;; GNU Emacs 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. - -;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. - -;;; Commentary: -;; -;; Unit tests for the formatting feature. -;; -;; Using test code from the tests source directory, parse the source -;; file. After parsing, read the comments for each signature, and -;; make sure that the semantic-tag-format-* functions in question -;; created the desired output. - -(require 'semantic) -(require 'semantic/format) - -;;; Code: - -(defvar cedet-utest-directory - (let* ((C (file-name-directory (locate-library "cedet"))) - (D (expand-file-name "../../test/manual/cedet/" C))) - D) - "Location of test files for this test suite.") - -(defvar semantic-fmt-utest-file-list - '("tests/test-fmt.cpp" - ;; "tests/test-fmt.el" - add this when elisp is support by dflt in Emacs - ) - "List of files to run unit tests in.") - -(defvar semantic-fmt-utest-error-log-list nil - "Log errors during testing in this variable.") - -(ert-deftest semantic-fmt-utest () - "Visit all file entries, and run formatting test. -Files to visit are in `semantic-fmt-utest-file-list'." - (save-current-buffer - (semantic-mode 1) - (let ((fl semantic-fmt-utest-file-list) - (fname nil) - ) - - (dolist (FILE fl) - - (save-current-buffer - (setq fname (expand-file-name FILE cedet-utest-directory)) - - ;; Make sure we have the files we think we have. - (should (file-exists-p fname)) - ;; (error "Cannot find unit test file: %s" fname)) - - ;; Run the tests. - (let ((fb (find-buffer-visiting fname)) - (b (semantic-find-file-noselect fname)) - (tags nil)) - - (save-current-buffer - (set-buffer b) - (should (semantic-active-p)) - ;;(error "Cannot open %s for format tests" fname)) - - ;; This will force a reparse, removing any chance of semanticdb cache - ;; using stale data. - (semantic-clear-toplevel-cache) - ;; Force the reparse - (setq tags (semantic-fetch-tags)) - - (save-excursion - (while tags - (let* ((T (car tags)) - (start (semantic-tag-end T)) - (end (if (cdr tags) - (semantic-tag-start (car (cdr tags))) - (point-max))) - (TESTS nil) - ) - (goto-char start) - ;; Scan the space between tags for all test condition matches. - (while (re-search-forward "## \\([a-z-]+\\) \"\\([^\n\"]+\\)\"$" end t) - (push (cons (match-string 1) (match-string 2)) TESTS)) - (setq TESTS (nreverse TESTS)) - - (dolist (TST TESTS) - (let* ( ;; For each test, convert CAR into a semantic-format-tag* fcn - (sym (intern (concat "semantic-format-tag-" (car TST)))) - ;; Convert the desired result from a string syntax to a string. - (desired (cdr TST)) - ;; What does the fmt function do? - (actual (funcall sym T)) - ) - (when (not (string= desired actual)) - (should-not (list "Desired" desired - "Actual" actual - "Formatter" (car TST)))) - ))) - (setq tags (cdr tags))) - - )) - - ;; If it wasn't already in memory, whack it. - (when (and b (not fb)) - (kill-buffer b))) - )) - - ))) - - -(provide 'cedet/semantic/fmt-utest) - -;;; semantic-fmt-utest.el ends here diff --git a/test/lisp/cedet/semantic-utest-ia-resources/test.mk b/test/lisp/cedet/semantic-utest-ia-resources/test.mk new file mode 100644 index 00000000000..edea97e7b98 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/test.mk @@ -0,0 +1,18 @@ +# A Test Makefile. -*-makefile-*- + +# This test is for a file in this test directory. Just a random one. +FILES=testdoub # -1- +# #1# ("testdoublens.cpp" "testdoublens.hpp" ) + +all: optional + +# This one completes on a variable name. +optional: $FIL # -2- + # #2# ("FILES") + compile $@ + +notoptional: opt # -3- + # #3# ("optional") + echo "Done." + +#end diff --git a/test/lisp/cedet/semantic-utest-ia-resources/test.srt b/test/lisp/cedet/semantic-utest-ia-resources/test.srt new file mode 100644 index 00000000000..38e6f9ed7b7 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/test.srt @@ -0,0 +1,64 @@ +;; test.srt --- unit test support file for semantic-utest-ia + +;; Copyright (C) 2008-2021 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. +;; + +set mode "c++-mode" +set escape_start "{{" +set escape_end "}}" + +context file + +template class :blank +"A test template for emacs lisp" +---- +---- + +template classic :blank +"A test template for emacs lisp" +---- +---- + +template variable :blank +"A test template for emacs lisp" +---- +---- + +template function :blank +"A test template for emacs lisp" +---- +---- + +template testarea :blank +"A test template for emacs lisp" +---- +{{<A:cla}} -1- + }} #1# ( "class" "classic" ) + {{^}} + +{{/A}} +---- + +;; This is a bad hack - In order for the text to parse, but also get a completion +;; moniker into the right spot, we need to pretend a comment is the same as the +;; escape_end. +;; Local variables: +;; comment-start-skip: "}}" +;; End: diff --git a/test/lisp/cedet/semantic-utest-ia-resources/test.texi b/test/lisp/cedet/semantic-utest-ia-resources/test.texi new file mode 100644 index 00000000000..37d303c8b48 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/test.texi @@ -0,0 +1,40 @@ +\input texinfo +@setfilename test.info +@set TITLE TEST +@set AUTHOR Eric Ludlam +@settitle @value{TITLE} + +@ifinfo +@format +START-INFO-DIR-ENTRY +* test: (test). TEST +END-INFO-DIR-ENTRY +@end format +@end ifinfo + +@titlepage +@sp 10 +@center @titlefont{test} +@vskip 0pt plus 1 fill +Copyright @copyright{} 2015 Eric Ludlam +@end titlepage + +@node Top +@top @value{TITLE} + +This is a simple manual filled with stuff that should test completion in texinfo mode. + +@m@c -1- +@c #1# ( "@majorheading" "@macro" "@menu" "@multitable" ) + +@menu +* Index:: +@end menu + + +@node Index +@chapter Index + +@contents + +@bye diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testdoublens.cpp b/test/lisp/cedet/semantic-utest-ia-resources/testdoublens.cpp new file mode 100644 index 00000000000..ea3afc72a69 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testdoublens.cpp @@ -0,0 +1,214 @@ +// testdoublens.cpp --- semantic-ia-utest completion engine unit tests + +// Copyright (C) 2008-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +#include "testdoublens.hpp" + +namespace Name1 { + namespace Name2 { + + Foo::Foo() + { + p// -1- + // #1# ( "pMumble" "publishStuff" ) + ; + } + + int Foo::get() // ^1^ + { + p// -2- + // #2# ( "pMumble" "publishStuff" ) + ; + return 0; + } + + void Foo::publishStuff(int a, int b) // ^2^ + { + int foo = a; + int bar = b; + } + + // Test polymorphism on arg types. Note that order is + // mixed to maximize failure cases + void Foo::publishStuff(char a, char b) // ^4^ + { + int foo = a; + int bar = b; + } + + void Foo::sendStuff(int a, int b) // ^3^ + { + int foo = a; + int bar = b; + + Foo::publishStuff(1,2) + + } + + } // namespace Name2 +} // namespace Name1 + +// Test multiple levels of metatype expansion +int test_fcn () { + stage3_Foo MyFoo; + + MyFoo.// -3- + // #3# ( "Mumble" "get" ) + ; + + Name1::Name2::F//-4- + // #4# ( "Foo" ) + ; + + // @TODO - get this working... + Name1::stage2_Foo::M//-5- + /// #5# ( "Mumble" ) + ; +} + +stage3_Foo foo_fcn() { + // Can we go "up" to foo with senator-go-to-up-reference? +} + + +// Second test from Ravikiran Rajagopal + +namespace A { + class foo { + public: + void aa(); + void bb(); + }; +} +namespace A { + class bar { + public: + void xx(); + public: + foo myFoo; + }; + + void bar::xx() + { + myFoo.// -6- <--- cursor is here after the dot + // #6# ( "aa" "bb" ) + ; + } +} + +// Double namespace example from Hannu Koivisto +// +// This is tricky because the parent class "Foo" is found within the +// scope of B, so the scope calculation needs to put that together +// before searching for parents in scope. +namespace a { + namespace b { + + class Bar : public Foo + { + int baz(); + }; + + int Bar::baz() + { + return dum// -7- + // #7# ( "dumdum" ) + ; + } + + } // namespace b +} // namespace a + +// Three namespace example from Hannu Koivisto +// +// This one is special in that the name e::Foo, where "e" is in +// the scope, and not referenced from the global namespace. This +// wasn't previously handled, so the fullscope needed to be added +// to the list of things searched when in split-name decent search mode +// for scopes. + +namespace d { + namespace e { + + class Foo + { + public: + int write(); + }; + + } // namespace d +} // namespace e + + +namespace d { + namespace f { + + class Bar + { + public: + int baz(); + + private: + e::Foo &foo; + }; + + int Bar::baz() + { + return foo.w// -8- + // #8# ( "write" ) + ; + } + + } // namespace f +} // namespace d + +// Fully qualified const struct function arguments +class ContainsStruct +{ + struct TheStruct + { + int memberOne; + int memberTwo; + }; +}; + +void someFunc(const struct ContainsStruct::TheStruct *foo) +{ + foo->// -9- + // #9# ("memberOne" "memberTwo") +} + +// Class with structure tag +class ContainsNamedStruct +{ + struct _fooStruct + { + int memberOne; + int memberTwo; + } member; +}; + +void someOtherFunc(void) +{ + ContainsNamedStruct *someClass; + // This has to find ContainsNamedStruct::_fooStruct + someClass->member.// -10- + // #10# ("memberOne" "memberTwo") +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testdoublens.hpp b/test/lisp/cedet/semantic-utest-ia-resources/testdoublens.hpp new file mode 100644 index 00000000000..e8c9b345b28 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testdoublens.hpp @@ -0,0 +1,71 @@ +// testdoublens.hpp --- Header file used in one of the Semantic tests + +// Copyright (C) 2008-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +namespace Name1 { + namespace Name2 { + + class Foo + { + typedef unsigned int Mumble; + public: + Foo(); + ~Foo(); + int get(); + + private: + void publishStuff(char /* a */, char /* b */); + + void publishStuff(int q, int r); // Purposely different names. + + void sendStuff(int a, int b); + + Mumble* pMumble; + }; + + typedef Foo stage1_Foo; + + } // namespace Name2 + + typedef Name2::stage1_Foo stage2_Foo; + + typedef Name2::Foo decl_stage1_Foo; + +} // namespace Name1 + +typedef Name1::stage2_Foo stage3_Foo; + + +// Double namespace from Hannu Koivisto +namespace a { + namespace b { + + class Foo + { + struct Dum { + int diDum; + }; + + protected: + mutable a::b::Foo::Dum dumdum; + }; + + } // namespace b +} // namespace a diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testfriends.cpp b/test/lisp/cedet/semantic-utest-ia-resources/testfriends.cpp new file mode 100644 index 00000000000..f84ed5a2190 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testfriends.cpp @@ -0,0 +1,37 @@ +// Test parsing of friends and how they are used in completion. +/* + >> Thanks Damien Profeta for the nice example. + > + > I paste a small example. + > It would be great if friend can be well parsed and even greater if + > class B can access to all the members of A. +*/ + +class Af // %2% ( ( "testfriends.cpp" ) ( "Af" "B::testB" ) ) +{ +public: + int pubVar; +private: + int privateVar; + + friend class B; + +}; + +class B +{ +public: + int testB(); + int testAB(); + +}; + + +int B::testB() { + Af classA; + classA.//-1- + ; //#1# ( "privateVar" "pubVar" ) +} + +int B::testAB() { // %1% ( ( "testfriends.cpp" ) ( "B" "B::testAB" ) ) +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testjavacomp.java b/test/lisp/cedet/semantic-utest-ia-resources/testjavacomp.java new file mode 100644 index 00000000000..bfc016903c8 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testjavacomp.java @@ -0,0 +1,77 @@ +// testjavacomp.java --- Semantic unit test for Java + +// Copyright (C) 2009-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +package tests.testjavacomp; + +class secondClass { + private void scFuncOne() { } + public void scFuncOne() { } + + int package_protected_field; + public int public_protected_field; + private int private_protected_field; +} + + +public class testjavacomp { + + private int funcOne() { } + private int funcTwo() { } + private char funcThree() { } + + class nestedClass { + private void ncFuncOne() { } + public void ncFuncOne() { } + } + + public void publicFunc() { + + int i; + + i = fu// -1- + // #1# ( "funcOne" "funcTwo" ) + ; + + fu// -2- + // #2# ( "funcOne" "funcThree" "funcTwo" ) + ; + + secondClass SC; + + SC.s//-3- + // #3# ( "scFuncOne" ) + ; + + // @TODO - to make this test complete, we need an import + // with a package protected field that is excluded + // from the completion list. + SC.p//-4- + // #4# ( "package_protected_field" "public_protected_field" ) + + nestedClass NC; + + // @todo - need to fix this? I don't know if this is legal java. + NC.// - 5- + // #5# ( "ncFuncOne" ) + ; + } + +} // testjavacomp diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testlocalvars.cpp b/test/lisp/cedet/semantic-utest-ia-resources/testlocalvars.cpp new file mode 100644 index 00000000000..9d2329a0fa8 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testlocalvars.cpp @@ -0,0 +1,54 @@ +// testlocalvars.java --- Semantic unit test for Java + +// Copyright (C) 2009-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + + +class foo { + foo *member; + char anArray[10]; +}; + +void func() +{ + foo local1; + foo* local2 = localvar.member; + foo* local3 = new foo(); + foo local4[10]; + char local5[5] = {'1','2','3','4','5'}; + char *local6 = "12345"; + char local7 = local.anArray[0]; + char local8 = true ? 10 : 11 ; + + // Check that all of the above was parsed + local//-1- + ; //#1# ("local1" "local2" "local3" "local4" "local5" "local6" "local7" "local8" ) + + local1.//-2- + ; //#2# ("anArray" "member") + + local2->//-3- + ; //#3# ("anArray" "member") + + local3->//-4- + ; //#4# ("anArray" "member") + + local4[0].//-5- + ; //#5# ("anArray" "member") +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testnsp.cpp b/test/lisp/cedet/semantic-utest-ia-resources/testnsp.cpp new file mode 100644 index 00000000000..db1603cead2 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testnsp.cpp @@ -0,0 +1,122 @@ +/* testnsp.cpp --- semantic-ia-utest completion engine unit tests + + Copyright (C) 2008-2021 Free Software Foundation, Inc. + + Author: Eric M. Ludlam <zappo@gnu.org> + + This file is part of GNU Emacs. + + GNU Emacs 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. + + GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. +*/ + +namespace nsp { + + class rootclass { + public: + int fromroot() {}; + }; + +} + +namespace nsp { + class childclass : public rootclass { + public: + int fromchild() {}; + }; +} + +void myfcn_not_in_ns (void) { + nsp::childclass test; + + test.// -1- + ; // #1# ( "fromchild" "fromroot" ) +} + +// Test a class declared in a class, where the contents +// are in a qualified name. +// +// Thanks Michael Reiher for the concise example. + +class AAA +{ +public: + AAA(); + + void aaa(); + +private: + class Private; + Private * const d; +}; + +class AAA::Private +{ + Private() : bbb(0) { + } + + BBB* bbb; +}; + +void AAA::aaa() +{ + d->// -2- + ; // #2# ( "bbb" ) +} + +// #include files inside a namespace +// David Engster <deng@randomsample.de> +// See revisions 8034-8037 which implement this. + +namespace another { + #include "testdoublens.hpp" +} + +void foo(void) { + + another::// -3- + ; // #3# ( "Name1" "a" "stage3_Foo" ) + + another::Name1::Name2::Foo a; + + a.// -4- + ; // #4# ( "Mumble" "get" ) +} + +// What happens if a type your looking for is scoped within a type, +// but you are one level into the completion so the originating scope +// excludes the type of the variable you are completing through? +// Thanks Martin Stein for this nice example. + +namespace ms_structs +{ + struct ms_aaa + { + int xx; + }; + + struct ms_bbb + { + struct ms_aaa yy; + }; +}; + +int fun() +{ + using namespace ms_structs; + struct ms_bbb mszz; + int uu = mszz.// -5- + ; // #5# ( "yy" ) + int kk = mszz.yy.// - 6- @TODO - bring in patch from SF + ; // #6# ( "xx" ) +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testsppcomplete.c b/test/lisp/cedet/semantic-utest-ia-resources/testsppcomplete.c new file mode 100644 index 00000000000..084d6a8687d --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testsppcomplete.c @@ -0,0 +1,66 @@ +/* testesppcomplete.cpp --- semantic-ia-utest completion engine unit tests + + Copyright (C) 2008-2021 Free Software Foundation, Inc. + + Author: Eric M. Ludlam <zappo@gnu.org> + + This file is part of GNU Emacs. + + GNU Emacs 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. + + GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. +*/ + +/* Example provided by Hannes Janetzek */ + +struct Test { int test; }; + +#define BLA(_type) \ + _type *bla = (_type*) malloc(sizeof(_type)); + +#define BLUB(_type) \ + (_type*)malloc(sizeof(_type)); + +#define FOO(_type) \ + _type *foo = BLUB(_type); + +#define BAR(_type) \ + _type *bar = (*_type)BLUB(_type); + +int main(int argc, char *argv[]) { + BLA(Test); + bla->// -1- + ; // #1# ( "test" ) + + FOO(Test); + foo->// -2- + ; // #2# ( "test" ) + + BAR(Test); + bar->// -3- + ; // #3# ( "test" ) +} + +/* Test symref and macros together. */ + +// This function exists only so we can have a comment in a tag with this name. +void function_with_macro_name () +// %1% ( ( "testsppcomplete.c" ) ( "function_with_macro_name" "function_with_macro_name" "use_macro") ) +// Note: fwmn is in twice, once for function, and once for the constant macro below. +{ +} + +#define function_with_macro_name 1 + +int use_macro () { + int a = function_with_macro_name; +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/teststruct.cpp b/test/lisp/cedet/semantic-utest-ia-resources/teststruct.cpp new file mode 100644 index 00000000000..6659b5557b8 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/teststruct.cpp @@ -0,0 +1,86 @@ +// teststruct.cpp --- semantic-ia-utest completion engine unit tests + +// Copyright (C) 2008-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + + +// Note: initially provided by by Alex Ott. + +template <typename DerivedT> +struct grammar { +public: + typedef grammar<DerivedT> self_t; + typedef DerivedT const& embed_t; + grammar() {} + ~grammar() { } + void use_parser() const { } + void test1() { } +}; + +struct PDFbool_parser : public grammar<PDFbool_parser> { + PDFbool_parser() {} + template <typename scannerT> struct definition { + typedef typename scannerT::iterator_t iterator_t; + int top; + definition(const PDFbool_parser& /*self*/) { + return ; + } + const int start() const { + return top; + } + }; +}; + +int main(void) { + PDFbool_parser PDFbool_p = PDFbool_parser(); + PDFbool_p.//-1- + ; + // #1# ("definition" "embed_t" "self_t" "test1" "use_parser") +} + +// ---------------------------------------------------------------------- + +template <class Derived> struct Base { +public: + void interface() + { + // ... + static_cast<Derived*>(this)->implementation(); + // ... + } + + static void static_func() + { + // ... + Derived::static_sub_func(); + // ... + } +}; + +struct Derived : Base<Derived> { + void implementation() { } + static void static_sub_func() { } +}; + +int foo () { + Derived d; + d.//-2- + ; + // #2# ("implementation" "interface" "static_func" "static_sub_func") +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testsubclass.cpp b/test/lisp/cedet/semantic-utest-ia-resources/testsubclass.cpp new file mode 100644 index 00000000000..409950cce2f --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testsubclass.cpp @@ -0,0 +1,248 @@ +// testsubclass.cpp --- unit test for analyzer and complex C++ inheritance + +// Copyright (C) 2007-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +//#include <iostream> +#include "testsubclass.hh" + +void animal::moose::setFeet(int numfeet) //^1^ +{ + if (numfeet > 4) { + std::cerr << "Why would a moose have more than 4 feet?" << std::endl; + return; + } + + fFeet = numfeet; +} + +int animal::moose::getFeet() //^2^ +{ + return fFeet; +} + +void animal::moose::doNothing() //^3^ +{ + animal::moose foo(); + + fFeet = N// -15- + ; // #15# ( "NAME1" "NAME2" "NAME3" ) +} + + +void deer::moose::setAntlers(bool have_antlers) //^4^ +{ + fAntlers = have_antlers; +} + +bool deer::moose::getAntlers() //^5^ +// %1% ( ( "testsubclass.cpp" "testsubclass.hh" ) ( "deer::moose::doSomething" "deer::moose::getAntlers" "moose" ) ) +{ + return fAntlers; +} + +bool i_dont_have_symrefs() +// %2% ( ("testsubclass.cpp" ) ("i_dont_have_symrefs")) +{ +} + +void deer::moose::doSomething() //^6^ +{ + // All these functions should be identified by semantic analyzer. + getAntlers(); + setAntlers(true); + + getFeet(); + setFeet(true); + + doNothing(); + + fSomeField = true; + + fIsValid = true; +} + +void deer::alces::setLatin(bool l) { + fLatin = l; +} + +bool deer::alces::getLatin() { + return fLatin; +} + +void deer::alces::doLatinStuff(moose moosein) { + // All these functions should be identified by semantic analyzer. + getFeet(); + setFeet(true); + + getLatin(); + setLatin(true); + + doNothing(); + + deer::moose foo(); + + +} + +moose deer::alces::createMoose() +{ + moose MooseVariableName; + bool tmp; + int itmp; + bool fool; + int fast; + + MooseVariableName = createMoose(); + + doLatinStuff(MooseVariableName); + + tmp = this.f// -1- + // #1# ( "fAlcesBool" "fIsValid" "fLatin" ) + ; + + itmp = this.f// -2- + // #2# ( "fAlcesInt" "fGreek" "fIsProtectedInt" ) + ; + + tmp = f// -3- + // #3# ( "fAlcesBool" "fIsValid" "fLatin" "fool" ) + ; + + itmp = f// -4- + // #4# ( "fAlcesInt" "fGreek" "fIsProtectedInt" "fast" ) + ; + + MooseVariableName = m// -5- + // #5# ( "moose" ) + + return MooseVariableName; +} + +/** Test Scope Changes + * + * This function is rigged to make sure the scope changes to account + * for different locations in local variable parsing. + */ +int someFunction(int mPickle) +{ + moose mMoose = deer::alces::createMoose(); + + if (mPickle == 1) { + + int mOption1 = 2; + + m// -5- + // #5# ( "mMoose" "mOption1" "mPickle" ) + ; + + } else { + + int mOption2 = 2; + + m// -6- + // #6# ( "mMoose" "mOption2" "mPickle" ) + ; + } + +} + +// Thanks Ming-Wei Chang for this next example. + +namespace pub_priv { + + class A{ + private: + void private_a(){} + public: + void public_a(); + }; + + void A::public_a() { + A other_a; + + other_a.p// -7- + // #7# ( "private_a" "public_a" ) + ; + } + + int some_regular_function(){ + A a; + a.p// -8- + // #8# ( "public_a" ) + ; + return 0; + } + +} + + +/** Test Scope w/in a function (non-method) with classes using + * different levels of inheritance. + */ +int otherFunction() +{ + sneaky::antelope Antelope(1); + sneaky::jackalope Jackalope(1); + sneaky::bugalope Bugalope(1); + + Antelope.// -9- + // #9# ( "fAntyPublic" "fQuadPublic" "testAccess") + ; + + Jackalope.// -10- + // #10# ( "fBunnyPublic" "testAccess") + ; + + Jackalope// @1@ 6 + ; + Jackalope; + Jackalope; + Jackalope; + + Bugalope.// -11- + // #11# ( "fBugPublic" "testAccess") + ; + Bugalope// @2@ 3 + ; +} + +/** Test methods within each class for types of access to the baseclass. + */ + +bool sneaky::antelope::testAccess() //^7^ +{ + this.// -12- + // #12# ( "fAntyPrivate" "fAntyProtected" "fAntyPublic" "fQuadProtected" "fQuadPublic" "testAccess" ) + ; +} + +bool sneaky::jackalope::testAccess() //^8^ +{ + this.// -13- + // #13# ( "fBunnyPrivate" "fBunnyProtected" "fBunnyPublic" "fQuadProtected" "fQuadPublic" "testAccess" ) + ; +} + +bool sneaky::bugalope::testAccess() //^9^ +{ + this.// -14- + // #14# ( "fBugPrivate" "fBugProtected" "fBugPublic" "fQuadPublic" "testAccess" ) + ; +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testsubclass.hh b/test/lisp/cedet/semantic-utest-ia-resources/testsubclass.hh new file mode 100644 index 00000000000..5d795b32b10 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testsubclass.hh @@ -0,0 +1,190 @@ +// testsubclass.hh --- unit test for analyzer and complex C++ inheritance + +// Copyright (C) 2007-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +//#include <cmath> +// #include <stdio.h> + +#ifndef TESTSUBCLASS_HH +#define TESTSUBCLASS_HH + +namespace animal { + + class moose { + public: + moose() : fFeet(0), + fIsValid(false) + { } + + virtual void setFeet(int); + int getFeet(); + + void doNothing(); + + enum moose_enum { + NAME1, NAME2, NAME3 }; + + + protected: + + bool fIsValid; + int fIsProtectedInt; + + private: + int fFeet; // Usually 2 or 4. + bool fIsPrivateBool; + + }; // moose + + int two_prototypes(); + int two_prototypes(); + + class quadruped { + public: + quadruped(int a) : fQuadPrivate(a) + { } + + int fQuadPublic; + + protected: + int fQuadProtected; + + private: + int fQuadPrivate; + + }; + +} + + +namespace deer { + + class moose : public animal::moose { + public: + moose() : fAntlers(false) + { } + + void setAntlers(bool); + bool getAntlers(); + + void doSomething(); + + protected: + + bool fSomeField; + + private: + bool fAntlers; + + }; + +} // deer + +// A second namespace of the same name will test the +// namespace merging needed to resolve deer::alces +namespace deer { + + class alces : public animal::moose { + public: + alces(int lat) : fLatin(lat) + { } + + void setLatin(bool); + bool getLatin(); + + void doLatinStuff(moose moosein); // for completion testing + + moose createMoose(); // for completion testing. + + protected: + bool fAlcesBool; + int fAlcesInt; + + private: + bool fLatin; + int fGreek; + }; + +}; + +// A third namespace with classes that does protected and private inheritance. +namespace sneaky { + + class antelope : public animal::quadruped { + + public: + antelope(int a) : animal::quadruped(), + fAntyProtected(a) + {} + + int fAntyPublic; + + bool testAccess(); + + protected: + int fAntyProtected; + + private : + int fAntyPrivate; + + }; + + class jackalope : protected animal::quadruped { + + public: + jackalope(int a) : animal::quadruped(), + fBunny(a) + {} + + int fBunnyPublic; + + bool testAccess(); + + protected: + bool fBunnyProtected; + + private : + bool fBunnyPrivate; + + }; + + // Nothing specified means private. + class bugalope : /* private*/ animal::quadruped { + + public: + bugalope(int a) : animal::quadruped(), + fBug(a) + {} + + int fBugPublic; + + bool testAccess(); + protected: + bool fBugProtected; + + private : + bool fBugPrivate; + + }; + + +}; + +#endif diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testtemplates.cpp b/test/lisp/cedet/semantic-utest-ia-resources/testtemplates.cpp new file mode 100644 index 00000000000..ed7a057df0b --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testtemplates.cpp @@ -0,0 +1,149 @@ +// testtemplates.cpp --- semantic-ia-utest completion engine unit tests + +// Copyright (C) 2008-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + + +// TODO - this probably means can't be part of emacs, as I don't know who this guy is. +// Written by 'Raf' + +template <class T, int U, class V> +class read_ref { +public: + const T* read_ref_member_one( T); + const V* read_ref_member_two(); +}; + +namespace NS { + template <class T, int U, class V> + class ref { + public: + read_ref<T,10,V> operator->() { + m_// -1- + ; + // #1# ( "m_datas" ) + } + + private: + T m_datas[U]; + }; + +} + +class FooOne { +public: + int fooOneMember(); +}; + +class FooTwo { +public: + int fooTwoMember(); +}; + +class FooThree { +public: + int fooThreeMember(); + + FooOne * operator->(); +}; + +typedef ref<FooOne, 10,FooTwo> Test; + +using NS; + +void +main(void) { + ref<FooOne, 10, FooTwo> v; + + v->read_ref_member_one()-> // -2- + ; + // #2# ( "fooOneMember" ) + + v->read_ref_member_two()-> // -3- + ; + // #3# ( "fooTwoMember" ) + + v-> // -4- + ; + // #4# ( "read_ref_member_one" "read_ref_member_two" ) + + Test t; + + t->read_ref_member_two()-> // -5- + ; + // #5# ( "fooTwoMember" ) + + ref<FooOne, 10, FooThree> v2; + + v2->read_ref_member_two()-> // -6- + ; + // #6# ( "fooOneMember" ) + + /* Try all these things by also specifying the namespace in the name. */ + NS::ref<FooOne, 10, FooTwo> v3; + + v3->read_ref_member_one()-> // -7- + ; + // #7# ( "fooOneMember" ) + + v3->read_ref_member_two()-> // -8- + ; + // #8# ( "fooTwoMember" ) + + v3->read_ref_member_two// @1@ 5 + ; + +} + +// More Namespace Magic using member constants. + +template<typename T> +struct isFooLike { + static const bool value = false; +}; + +template <> +struct isFooLike<int> { + static const bool value = true; +}; + + +template <typename T, bool isFoo> +class A { +public: + A(); + void foo() {}; +}; + + +template <typename T> +class FooFour : public A<T, isPodLike<T>::value> { +public: + bool bar() {} +}; + + +int main2() { + + FooFour<int> ff; + + ff.// - 9- @ TODO - bring over patch from SF + ; // #9# ( "bar" "foo" ); + +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testtypedefs.cpp b/test/lisp/cedet/semantic-utest-ia-resources/testtypedefs.cpp new file mode 100644 index 00000000000..c82535f9581 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testtypedefs.cpp @@ -0,0 +1,155 @@ +// testtypedefs.cpp --- Sample with some fake bits out of std::string + +// Copyright (C) 2008-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +// Thanks Ming-Wei Chang for these examples. + +namespace std { + template <T>class basic_string { + public: + void resize(int); + }; +} + +typedef std::basic_string<char> mstring; + +using namespace std; +typedef basic_string<char> bstring; + +int main(){ + mstring a; + a.// -1- + ; + // #1# ( "resize" ) + bstring b; + // It doesn't work here. + b.// -2- + ; + // #2# ( "resize" ) + return 0; +} + +// ------------------ + +class Bar +{ +public: + void someFunc() {} +}; + +typedef Bar new_Bar; + +template <class mytype> +class TBar +{ +public: + void otherFunc() {} +}; + +typedef TBar<char> new_TBar; + +int main() +{ + new_Bar nb; + new_TBar ntb; + + nb.// -3- + ; + // #3# ("someFunc") + ntb.// -4- + ; + // #4# ("otherFunc") + + return 0; +} + +// ------------------ +// Example from Yupeng. + +typedef struct epd_info { + int a; +} epd_info_t; + +static int epd_probe(struct platform_device *pdev) +{ + struct epd_info *db; + epd_info_t db1; + + db.// -5- + ; // #5# ("a") + db1.// -6- + ;// #6# ("a") + + return 1; +} + +// ------------------ +// Example from Michel LAFON-PUYO + +typedef enum +{ + ENUM1, + ENUM2 +} e_toto; + +typedef struct +{ + int field_a; + int field_b; +} t_toto; + +// Note: Error condition from anonymous types in a typedef +// was that the first (ie - the enum) would be used in +// place of the struct. +int func(void) +{ + t_toto t; + t. // -7- + ; // #7# ( "field_a" "field_b" ) + return 0; +} + + +// ------------------ +// Example from Dixon Ryan + + +namespace NS2 { + class MyClass { + + public: + void myFunction() { } + }; +} + +typedef class NS2::MyClass* MyClassHandle; + +int dixon ( void ) { + MyClassHandle mch = getMyClassHandle(); + NS2::MyClass* mcptr = getMyClassHandle(); + + mcptr-> // -8- + ; // #8# ( "myFunction" ) + mch-> // - 9- TODO bring over patch from SF + ; // #9# ( "myFunction" ) + deleteMyClassHandle(mch); + + return 0; +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testusing.cpp b/test/lisp/cedet/semantic-utest-ia-resources/testusing.cpp new file mode 100644 index 00000000000..6f6c8542633 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testusing.cpp @@ -0,0 +1,265 @@ +// testusing.cpp --- semantic-ia-utest completion engine unit tests + +// Copyright (C) 2008-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + + +#include <adstdio.h> + +#include <testusing.hh> + +namespace moose { + + class MyClass; + class Point; + + typedef MyClass snerk; +} + +namespace moose { + + class Point; + class MyClass; + +} + +namespace { + + int global_variable = 0; + +}; + +using moose::MyClass; + +void someFcn() { + + MyClass f; + + f.//-1- + ; //#1# ( "getVal" "setVal" ) + +} + +// Code from Zhiqiu Kong + +namespace panda { + + using namespace bread_name; + + int func() + { + bread test; + test.//-2- + ;// #2# ( "geta" ) + return 0; + } +} + +namespace togglemoose { + + MyOtherClass::testToggle1() { //^1^ + // Impl for testToggle1 + } +} + +togglemoose::MyOtherClass::testToggle2() { //^3^ + // Impl for testToggle2 +} + +using togglemoose; + +MyOtherClass::testToggle3() { //^3^ + // Impl for testToggle3 +} + +// Local using statements and aliased types +// Code from David Engster + +void func2() +{ + using namespace somestuff; + OneClass f; + f.//-3- + ; //#3# ( "aFunc" "anInt" ) +} + +void func3() +{ + using somestuff::OneClass; + OneClass f; + f.//-4- + ; //#4# ( "aFunc" "anInt" ) +} + +// Dereferencing alias types created through 'using' statements + +// Alias with fully qualified name +void func4() +{ + otherstuff::OneClass f; + f. //-5- + ; //#5# ( "aFunc" "anInt" ) +} + +// Alias through namespace directive +void func5() +{ + using namespace otherstuff; + OneClass f; + f. //-6- + ; //#6# ( "aFunc" "anInt" ) +} + +// Check name hiding +void func6() +{ + using namespace morestuff; + OneClass f; // Alias for somestuff::OneClass + f. //-7- + ; //#7# ( "aFunc" "anInt" ) + aStruct g; // This however is morestuff::aStruct ! + g. //-8- + ; //#8# ( "anotherBar" "anotherFoo" ) +} + +// Alias of an alias +// Currently doesn't work interactively for some reason. +void func6() +{ + using namespace evenmorestuff; + OneClass f; + f. //-7- + ; //#7# ( "aFunc" "anInt" ) +} + +// Alias for struct in nested namespace, fully qualified +void func7() +{ + outer::StructNested f; + f.//-8- + ; //#8# ( "one" "two" ) +} + +// Alias for nested namespace +void func8() +{ + using namespace outerinner; + StructNested f; + AnotherStruct g; + f.//-9- + ; //#9# ( "one" "two" ) + g.//-10- + ; //#10# ( "four" "three" ) +} + +// Check conventional namespace aliases +// - fully qualified - +void func9() +{ + alias_for_somestuff::OneClass c; + c.//-11- + ; //#11# ( "aFunc" "anInt" ) + alias_for_outerinner::AnotherStruct s; + s. //-12- + ; //#12# ( "four" "three" ) +} + +// - unqualified - +void func10() +{ + using namespace alias_for_somestuff; + OneClass c2; + c2.//-13- + ; //#13# ( "aFunc" "anInt" ) + using namespace alias_for_outerinner; + AnotherStruct s2; + s2.//-14- + ; //#14# ( "four" "three" ) +} + +// Completion on namespace aliases +void func11() +{ + alias_for_somestuff:://-15- + ; //#15# ( "OneClass" "aStruct") + alias_for_outerinner:://-16- + ; //#16# ( "AnotherStruct" "StructNested" ) +} + +// make sure unfound using statements don't crash stuff. +using something::cantbe::Found; + +void unfoundfunc() +{ + NotFound notfound; // Variable can't be found. + + notfound.//-17- + ; //#17# ( ) Nothing here since this is an undefined class + +} + +// Using statements can depend on previous ones... + +void acc_using() +{ + using namespace outer; + // This is effectively like 'using namespace outer::inner' + using namespace inner; + + StructNested sn; + sn.//-18- + ; //#18# ( "one" "two" ) +} + +// Check the same outside of function scope + +using namespace outer; +using namespace inner; + +void acc_using2() +{ + StructNested sn; + sn.//-19- + ; //#19# ( "one" "two" ) +} + +// Check if scope gets correctly generated, i.e., without us providing any +// hints in the form of an existing type + +void check_scope() +{ + using namespace first; + AAA//-20- + ; //#20# ( "AAA1" "AAA2" ) +} + +void check_scope2() +{ + using namespace third; + AAA//-21- + ; //#21# ( "AAA1" "AAA2" "AAA3" ) +} + +// Make sure this also works not only in functions + +namespace check_scope3 { + using namespace first; + AAA//-22- + ; //#22# ( "AAA1" "AAA2" ) +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testusing.hh b/test/lisp/cedet/semantic-utest-ia-resources/testusing.hh new file mode 100644 index 00000000000..d3b690f8542 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testusing.hh @@ -0,0 +1,176 @@ +// testusing.hh --- semantic-ia-utest completion engine unit tests + +// Copyright (C) 2008-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +namespace moose { + + class Point; + + class MyClass; + +} + + +namespace moose { + + class Point; + + class MyClass { + public: + MyClass() : fVal(0) { + } + + ~MyClass() {}; + + /** + * fVal Accessors + * @{ + */ + int getVal() const { + return fVal; + } + void setVal(int Val) const { + fVal = Val; + } + /** + * @} + */ + + private: + int fVal; + }; + +} + +namespace togglemoose { + + class MyOtherClass { + public: + int testToggle1(); + int testToggle2(); + int testToggle3(); + }; +} + +namespace deer { + + class Pickle; + +}; + +// Code from Zhiqiu Kong + +#ifndef BREAD_H +#define BREAD_H + +namespace bread_name { + class bread + { + public: + void geta(); + private: + int m_a; + int m_b; + }; +} + +#endif + +// Code from David Engster +// Creating alias types through 'using' trickery + +namespace somestuff { + class OneClass { + public: + void aFunc(); + int anInt; + }; + struct aStruct { + int foo; + int bar; + }; +} + +namespace otherstuff { + // make otherstuff::OneClass an alias for somestuff::OneClass + using somestuff::OneClass; +} + +namespace morestuff { + // make morestuff an alias namespace for somestuff + using namespace somestuff; + // but hide aStruct with own type + struct aStruct { + int anotherFoo; + int anotherBar; + }; +} + +// We can also create an alias for an alias +namespace evenmorestuff { + using otherstuff::OneClass; +} + +// Now with nested namespaces +namespace outer { + namespace inner { + struct StructNested { + int one; + int two; + }; + struct AnotherStruct { + int three; + int four; + }; + } +} + +// Namespace which pulls in one of its own nested namespaces +namespace first { + class AAA1; + namespace second { + class AAA2; + } + // Elevate nested namespace into first one + using namespace second; +} + +namespace third { + using namespace first; + class AAA3; +} + + +// Elevate the first struct into 'outer' +// so that we can access it via 'outer::StructNested' +namespace outer { + using outer::inner::StructNested; +} + +// Create an alias for a nested namespace +namespace outerinner { + // equivalent to 'namespace outerinner = outer::inner;' + using namespace outer::inner; +} + +// Create namespace alias +namespace alias_for_somestuff = somestuff; +// Same for nested namespace +namespace alias_for_outerinner = outer::inner; diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testvarnames.c b/test/lisp/cedet/semantic-utest-ia-resources/testvarnames.c new file mode 100644 index 00000000000..e796eb285c6 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testvarnames.c @@ -0,0 +1,104 @@ +/* testvarnames.cpp --- semantic-ia-utest completion engine unit tests + + Copyright (C) 2008-2021 Free Software Foundation, Inc. + + Author: Eric M. Ludlam <zappo@gnu.org> + + This file is part of GNU Emacs. + + GNU Emacs 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. + + GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +*/ + +struct independent { + int indep_1; + int indep_2; +}; + +struct independent var_indep_struct; + +struct { + int unnamed_1; + int unnamed_2; +} var_unnamed_struct; + +struct { + int unnamed_3; + int unnamed_4; +} var_un_2, var_un_3; + +struct inlinestruct { + int named_1; + int named_2; +} var_named_struct; + +struct inline2struct { + int named_3; + int named_4; +} var_n_2, var_n_3; + +/* Structures with names that then declare variables + * should also be completable. + * + * Getting this to work is the bugfix in semantic-c.el CVS v 1.122 + */ +struct inlinestruct in_var1; +struct inline2struct in_var2; + +/* + * Structures (or any types) could have the same name as a variable. + * Make sure we complete vars over types. + * + * See cedet-devel mailing list Dec 23, 2013 for details. + */ +struct varorstruct {}; +int varorstruct; + +int assigntovarorstruct; + +int test_1(int var_arg1) { + + var_// -1- + ; // #1# ("var_arg1" "var_indep_struct" "var_n_2" "var_n_3" "var_named_struct" "var_un_2" "var_un_3" "var_unnamed_struct") + + var_indep_struct.// -2- + ; // #2# ( "indep_1" "indep_2" ) + + var_unnamed_struct.// -3- + ; // #3# ( "unnamed_1" "unnamed_2" ) + + var_named_struct.// -4- + ; // #4# ( "named_1" "named_2" ) + + var_un_2.// -5- + ; // #5# ( "unnamed_3" "unnamed_4" ) + var_un_3.// -6- + ; // #6# ( "unnamed_3" "unnamed_4" ) + + var_n_2.// -7- + ; // #7# ( "named_3" "named_4" ) + var_n_3.// -8- + ; // #8# ( "named_3" "named_4" ) + + in_// -9- + ; // #9# ( "in_var1" "in_var2" ) + + in_var1.// -10- + ; // #10# ( "named_1" "named_2") + in_var2.// -11- + ; // #11# ( "named_3" "named_4") + + varorstruct = assign// -12- + ; // #12# ( "assigntovarorstruct" ) +} diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testvarnames.java b/test/lisp/cedet/semantic-utest-ia-resources/testvarnames.java new file mode 100644 index 00000000000..7ed9785fc07 --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testvarnames.java @@ -0,0 +1,60 @@ +// testvarnames.java --- Semantic unit test for Java + +// Copyright (C) 2009-2021 Free Software Foundation, Inc. + +// Author: Eric M. Ludlam <zappo@gnu.org> + +// This file is part of GNU Emacs. + +// GNU Emacs 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. + +// GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +package tests; + +/** + * + * + * Created: 02/17/14 + * + * @author Eric M. Ludlam + * @version + * @since + */ +public class testvarnames { + + public class varorclass { + public static long misclongvalue; + }; + + public static varorclass varoftypevarorclass = NULL; + + public static long varorclass = 1; + + public static long assignintovar = 1; + + public static varorclass classassign = NULL; + + static public void main(String [] args) { + + varorclass = assign// -1- + // #1# ( "assignintovar" ) + ; + + varoftypevarorclass = clas// -2- + // #2# ( "classassign" ) + + varoftypevarorclass.misc//-3- + // #3# ( "misclongvalue" ) + } + +} // testvarnames diff --git a/test/lisp/cedet/semantic-utest-ia-resources/testwisent.wy b/test/lisp/cedet/semantic-utest-ia-resources/testwisent.wy new file mode 100644 index 00000000000..49eb5780f4b --- /dev/null +++ b/test/lisp/cedet/semantic-utest-ia-resources/testwisent.wy @@ -0,0 +1,85 @@ +;; testwisent.wy --- unit test support file for semantic-utest-ia + +;; Copyright (C) 2008-2021 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; Parser for nothing in particular mode + +%languagemode nothing-mode +%parsetable wisent-nothing-parser-tables +%keywordtable wisent-nothing-keywords +%tokentable wisent-nothing-tokens +%languagemode nothing-mode +%setupfunction wisent-nothing-default-setup + +%start goal + +;;; Punctuation +%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string + +%token <punctuation> DOT "." +%token <punctuation> COMA "," +%token <punctuation> COLONCOLON "::" +%token <punctuation> COLON ":" +%token <punctuation> SEMICOLON ";" + +;;; KEYWORDS +%type <keyword> + +%keyword COLONOSCOPY "colonoscopy" +%keyword SEMISOMETHING "semisomething" + +%% + +goal + ;; Misc + : COLON ;; -1- + ;; #1# ( "COLONCOLON" "COLON" "COLONOSCOPY" ) + | SEMI ;; -2- + ;; #2# ( "SEMI_useless_rule" "SEMICOLON" "SEMISOMETHING" ) + | thing ;; -3- + ;; #3# ( "thing_term_1" "thing_term_2" ) + ; + +SEMI_useless_rule + : + ; + +thing_term_1 + : + ; + +thing_term_2 + : + ; + +%% +(define-lex wisent-nothing-lexer + "Lexical analyzer to handle nothing in particular buffers." + ;; semantic-lex-newline + semantic-lex-ignore-whitespace + semantic-lex-ignore-newline + semantic-lex-ignore-comments + + semantic-lex-default-action + ) + +;; testwisent.wy ends here
\ No newline at end of file diff --git a/test/lisp/cedet/semantic-utest-ia.el b/test/lisp/cedet/semantic-utest-ia.el index 7210f66b0a7..122c431d472 100644 --- a/test/lisp/cedet/semantic-utest-ia.el +++ b/test/lisp/cedet/semantic-utest-ia.el @@ -30,121 +30,94 @@ ;; (Replace // with contents of comment-start for the language being tested.) ;;; Code: +(require 'ert) +(require 'ert-x) (require 'semantic) (require 'semantic/analyze) (require 'semantic/analyze/refs) (require 'semantic/symref) (require 'semantic/symref/filter) -(defvar cedet-utest-directory - (let* ((C (file-name-directory (locate-library "cedet"))) - (D (expand-file-name "../../test/manual/cedet/" C))) - D) - "Location of test files for this test suite.") - -(defvar semantic-utest-test-directory (expand-file-name "tests" cedet-utest-directory) - "Location of test files.") - (ert-deftest semantic-utest-ia-doublens.cpp () - (let ((tst (expand-file-name "testdoublens.cpp" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testdoublens.cpp"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-subclass.cpp () - (let ((tst (expand-file-name "testsubclass.cpp" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testsubclass.cpp"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-typedefs.cpp () - (let ((tst (expand-file-name "testtypedefs.cpp" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testtypedefs.cpp"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-struct.cpp () - (let ((tst (expand-file-name "teststruct.cpp" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "teststruct.cpp"))) (should-not (semantic-ia-utest tst)))) ;;(ert-deftest semantic-utest-ia-union.cpp () -;; (let ((tst (expand-file-name "testunion.cpp" semantic-utest-test-directory))) -;; (should (file-exists-p tst)) +;; (let ((tst (ert-resource-file "testunion.cpp"))) ;; (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-templates.cpp () - (let ((tst (expand-file-name "testtemplates.cpp" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testtemplates.cpp"))) (should-not (semantic-ia-utest tst)))) ;;(ert-deftest semantic-utest-ia-friends.cpp () -;; (let ((tst (expand-file-name "testfriends.cpp" semantic-utest-test-directory))) -;; (should (file-exists-p tst)) +;; (let ((tst (ert-resource-file "testfriends.cpp"))) ;; (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-using.cpp () - (let ((tst (expand-file-name "testusing.cpp" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testusing.cpp"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-nsp.cpp () (skip-unless (executable-find "g++")) - (let ((tst (expand-file-name "testnsp.cpp" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testnsp.cpp"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-localvars.cpp () - (let ((tst (expand-file-name "testlocalvars.cpp" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testlocalvars.cpp"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-namespace.cpp () (skip-unless (executable-find "g++")) - (let ((tst (expand-file-name "testnsp.cpp" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testnsp.cpp"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-sppcomplete.c () - (let ((tst (expand-file-name "testsppcomplete.c" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testsppcomplete.c"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-varnames.c () - (let ((tst (expand-file-name "testvarnames.c" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testvarnames.c"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-javacomp.java () - (let ((tst (expand-file-name "testjavacomp.java" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testjavacomp.java"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-varnames.java () - (let ((tst (expand-file-name "testvarnames.java" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testvarnames.java"))) (should-not (semantic-ia-utest tst)))) ;;(ert-deftest semantic-utest-ia-f90.f90 () -;; (let ((tst (expand-file-name "testf90.f90" semantic-utest-test-directory))) -;; (should (file-exists-p tst)) +;; (let ((tst (ert-resource-file "testf90.f90"))) ;; (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-wisent.wy () - (let ((tst (expand-file-name "testwisent.wy" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "testwisent.wy"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-texi () - (let ((tst (expand-file-name "test.texi" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "test.texi"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-make () - (let ((tst (expand-file-name "test.mk" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "test.mk"))) (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-srecoder () - (let ((tst (expand-file-name "test.srt" semantic-utest-test-directory))) - (should (file-exists-p tst)) + (let ((tst (ert-resource-file "test.srt"))) (should-not (semantic-ia-utest tst)))) ;;; Core testing utility diff --git a/test/lisp/cedet/semantic-utest.el b/test/lisp/cedet/semantic-utest.el index 67de4a5b02d..172ab62f895 100644 --- a/test/lisp/cedet/semantic-utest.el +++ b/test/lisp/cedet/semantic-utest.el @@ -1,6 +1,6 @@ ;;; semantic-utest.el --- Tests for semantic's parsing system. -*- lexical-binding:t -*- -;;; Copyright (C) 2003-2004, 2007-2021 Free Software Foundation, Inc. +;; Copyright (C) 2003-2021 Free Software Foundation, Inc. ;; Author: Eric M. Ludlam <zappo@gnu.org> diff --git a/test/lisp/cedet/semantic/bovine/gcc-tests.el b/test/lisp/cedet/semantic/bovine/gcc-tests.el new file mode 100644 index 00000000000..93677d6c871 --- /dev/null +++ b/test/lisp/cedet/semantic/bovine/gcc-tests.el @@ -0,0 +1,129 @@ +;;; gcc-tests.el --- Tests for semantic/bovine/gcc.el -*- lexical-binding:t -*- + +;; Copyright (C) 2003-2021 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Moved here from test/manual/cedet/semantic-tests.el + +;;; Code: + +(require 'ert) +(require 'semantic/bovine/gcc) + +;;; From bovine-gcc: + +;; Example output of "gcc -v" +(defvar semantic-gcc-test-strings + '(;; My old box: + "Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs +Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux +Thread model: posix +gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)" + ;; Alex Ott: + "Using built-in specs. +Target: i486-linux-gnu +Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.1-9ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu +Thread model: posix +gcc version 4.3.1 (Ubuntu 4.3.1-9ubuntu1)" + ;; My debian box: + "Using built-in specs. +Target: x86_64-unknown-linux-gnu +Configured with: ../../../sources/gcc/configure --prefix=/usr/local/glibc-2.3.6/x86_64/apps/gcc-4.2.3 --with-gmp=/usr/local/gcc/gmp --with-mpfr=/usr/local/gcc/mpfr --enable-languages=c,c++,fortran --with-as=/usr/local/glibc-2.3.6/x86_64/apps/gcc-4.2.3/bin/as --with-ld=/usr/local/glibc-2.3.6/x86_64/apps/gcc-4.2.3/bin/ld --disable-multilib +Thread model: posix +gcc version 4.2.3" + ;; My mac: + "Using built-in specs. +Target: i686-apple-darwin8 +Configured with: /private/var/tmp/gcc/gcc-5341.obj~1/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=powerpc-apple-darwin8 --with-arch=pentium-m --with-tune=prescott --program-prefix= --host=i686-apple-darwin8 --target=i686-apple-darwin8 +Thread model: posix +gcc version 4.0.1 (Apple Computer, Inc. build 5341)" + ;; Ubuntu Intrepid + "Using built-in specs. +Target: x86_64-linux-gnu +Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu +Thread model: posix +gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12)" + ;; Red Hat EL4 + "Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs +Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux +Thread model: posix +gcc version 3.4.6 20060404 (Red Hat 3.4.6-10)" + ;; Red Hat EL5 + "Using built-in specs. +Target: x86_64-redhat-linux +Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux +Thread model: posix +gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)" + ;; David Engster's german gcc on ubuntu 4.3 + "Es werden eingebaute Spezifikationen verwendet. +Ziel: i486-linux-gnu +Konfiguriert mit: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu +Thread-Modell: posix +gcc-Version 4.3.2 (Ubuntu 4.3.2-1ubuntu12)" + ;; Damien Deville bsd + "Using built-in specs. +Target: i386-undermydesk-freebsd +Configured with: FreeBSD/i386 system compiler +Thread model: posix +gcc version 4.2.1 20070719 [FreeBSD]" + ) + "A bunch of sample gcc -v outputs from different machines.") + +(defvar semantic-gcc-test-strings-fail + '(;; A really old solaris box I found + "Reading specs from /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/specs +gcc version 2.95.2 19991024 (release)" + ) + "A bunch of sample gcc -v outputs that fail to provide the info we want.") + +(defun semantic-gcc-test-output-parser () + "Test the output parser against some collected strings." + (dolist (S semantic-gcc-test-strings) + (let* ((fields (semantic-gcc-fields S)) + (v (cdr (assoc 'version fields))) + (h (or (cdr (assoc 'target fields)) + (cdr (assoc '--target fields)) + (cdr (assoc '--host fields)))) + (p (cdr (assoc '--prefix fields)))) + ;; No longer test for prefixes. + (when (not (and v h)) + (let ((strs (split-string S "\n"))) + (error "Test failed on %S\nV H P:\n%S %S %S" (car strs) v h p))))) + (dolist (S semantic-gcc-test-strings-fail) + (let* ((fields (semantic-gcc-fields S)) + (v (cdr (assoc 'version fields))) + (h (or (cdr (assoc '--host fields)) + (cdr (assoc 'target fields)))) + (p (cdr (assoc '--prefix fields))) + ) + (when (and v h p) + (error "Negative test failed on %S" S))))) + +(ert-deftest semantic-gcc-test-output-parser () + (semantic-gcc-test-output-parser)) + +(ert-deftest semantic-gcc-test-output-parser-this-machine () + "Test the output parser against the machine currently running Emacs." + (skip-unless (executable-find "gcc")) + (let ((semantic-gcc-test-strings (list (semantic-gcc-query "gcc" "-v")))) + (semantic-gcc-test-output-parser))) + +;;; gcc-tests.el ends here diff --git a/test/lisp/cedet/semantic/format-resources/test-fmt.cpp b/test/lisp/cedet/semantic/format-resources/test-fmt.cpp new file mode 100644 index 00000000000..ab869c1ce00 --- /dev/null +++ b/test/lisp/cedet/semantic/format-resources/test-fmt.cpp @@ -0,0 +1,108 @@ +/** test-fmt.cpp --- Signatures, and format answers for testing + * + * Copyright (C) 2012, 2016, 2019-2021 Free Software Foundation, Inc. + * + * Author: Eric M. Ludlam <zappo@gnu.org> + * + * This file is part of GNU Emacs. + * + * GNU Emacs 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. + * + * GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + */ + +/* + * About semantic-fmt-utest : + * + * These tests validate two features: + * 1) The C++ parser can parse the different signatures + * 2) The semantic-tag-format-* functions can recreate them. + * + */ + +void basic_fcn() { } +/* + * ## name "basic_fcn" + * ## abbreviate "basic_fcn()" + * ## prototype "void basic_fcn ()" + * ## uml-prototype "basic_fcn () : void" + */ + +int twoargs_fcn(int a, char b) { } +/* + * ## name "twoargs_fcn" + * ## abbreviate "twoargs_fcn()" + * ## prototype "int twoargs_fcn (int a,char b)" + * ## uml-prototype "twoargs_fcn (a : int,b : char) : int" + */ + +struct moose { + int field1; + char field2; +}; +/* + * ## name "moose" + * ## abbreviate "moose{}" + * ## prototype "struct moose {}" + * ## uml-prototype "moose{} : struct" + */ + +struct moose struct_fcn ( struct moose in, char *out); +/* + * ## name "struct_fcn" + * ## abbreviate "struct_fcn()" + * ## prototype "struct moose struct_fcn (struct moose in,char* out)" + * ## uml-prototype "struct_fcn (in : struct moose,out : char*) : struct moose" + */ + +struct moose *var_one = NULL; +/* + * ## name "var_one" + * ## summarize "Variables: struct moose* var_one[=NULL]" + * ## prototype "struct moose* var_one[=NULL]" + * ## uml-prototype "var_one : struct moose*" + */ + +const int var_two = 1; +/* + * ## name "var_two" + * ## summarize "Variables: const int var_two[=1]" + * ## prototype "const int var_two[=1]" + * ## uml-prototype "var_two : int" + */ + +namespace NS { + enum TestEnum {a,b}; +} +/* + * ## name "NS" + * ## summarize "Types: namespace NS {}" + * ## prototype "namespace NS {}" + * ## uml-prototype "NS{} : namespace" + */ + + +// void func_ns_arg(NS::TestEnum v = NS::a); <<--- TODO - bring FIX from CEDET on SF +/* + * # # name "func_ns_arg" + * # # summarize "Functions: void func_ns_arg (NS::TestEnum v[=NS::a])" + * # # prototype "void func_ns_arg (NS::TestEnum v[=NS::a])" + * # # uml-prototype "func_ns_arg (v : NS::TestEnum) : void" + */ + +//int const var_three = 1; +/* + * # # name "var_three" + * # # summarize "Variables: int const var_three" <-- this fails + * # # prototype "int const var_three" <-- this fails + * # # uml-prototype "var_three : int" + */ diff --git a/test/lisp/cedet/semantic/format-resources/test-fmt.el b/test/lisp/cedet/semantic/format-resources/test-fmt.el new file mode 100644 index 00000000000..8458a8e6510 --- /dev/null +++ b/test/lisp/cedet/semantic/format-resources/test-fmt.el @@ -0,0 +1,65 @@ +;;; test-fmt.el --- test semantic tag formatting -*- lexical-binding: t -*- + +;; Copyright (C) 2012-2021 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; + +;;; Code: +(require 'semantic) +;; +;; ## name "semantic" +;; ## abbreviate "semantic<>" +;; ## summarize "Requires: semantic" + +(defun test-fmt-1 (a) + "Function with 1 arg.") +;; +;; ## name "test-fmt-1" +;; ## abbreviate "(test-fmt-1)" +;; ## summarize "Defuns: (test-fmt-1 a)" +;; ## short-doc "Function with 1 arg." +;; ## uml-prototype "(test-fmt-1 a)" <-- That is probably wrong. + +(defvar test-fmt-var nil + "Variable test.") +;; +;; ## name "test-fmt-var" +;; ## abbreviate "test-fmt-var" +;; ## summarize "Variables: test-fmt-var" +;; ## short-doc "Variable test." +;; ## uml-prototype "test-fmt-var" + +(defclass test-fmt-class () + ((slot1 :initarg :slot1)) + "Class for testing.") +;; +;; ## name "test-fmt-class" +;; ## abbreviate "test-fmt-class{}" +;; ## summarize "Types: class test-fmt-class {}" +;; ## short-doc "Class for testing." +;; ## uml-prototype "class test-fmt-class {}" + + + +(provide 'test-fmt) + +;;; test-fmt.el ends here diff --git a/test/lisp/cedet/semantic/format-tests.el b/test/lisp/cedet/semantic/format-tests.el new file mode 100644 index 00000000000..149f408af15 --- /dev/null +++ b/test/lisp/cedet/semantic/format-tests.el @@ -0,0 +1,95 @@ +;;; semantic/format-tests.el --- Parsing / Formatting tests -*- lexical-binding:t -*- + +;; Copyright (C) 2003-2021 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Unit tests for the formatting feature. +;; +;; Using test code from the tests source directory, parse the source +;; file. After parsing, read the comments for each signature, and +;; make sure that the semantic-tag-format-* functions in question +;; created the desired output. + +;;; Code: + +(require 'ert) +(require 'ert-x) +(require 'semantic/format) + +(defvar semantic-fmt-utest-file-list + (list (ert-resource-file "test-fmt.cpp") + ;; "tests/test-fmt.el" - add this when elisp is support by dflt in Emacs + ) + "List of files to run unit tests in.") + +(ert-deftest semantic-fmt-utest () + "Visit all file entries, and run formatting test. " + (save-current-buffer + (semantic-mode 1) + (dolist (fname semantic-fmt-utest-file-list) + (let ((fb (find-buffer-visiting fname)) + (b (semantic-find-file-noselect fname)) + (tags nil)) + (save-current-buffer + (set-buffer b) + (should (semantic-active-p)) + ;;(error "Cannot open %s for format tests" fname)) + + ;; This will force a reparse, removing any chance of semanticdb cache + ;; using stale data. + (semantic-clear-toplevel-cache) + ;; Force the reparse + (setq tags (semantic-fetch-tags)) + + (save-excursion + (while tags + (let* ((T (car tags)) + (start (semantic-tag-end T)) + (end (if (cdr tags) + (semantic-tag-start (car (cdr tags))) + (point-max))) + (TESTS nil)) + (goto-char start) + ;; Scan the space between tags for all test condition matches. + (while (re-search-forward "## \\([a-z-]+\\) \"\\([^\n\"]+\\)\"$" end t) + (push (cons (match-string 1) (match-string 2)) TESTS)) + (setq TESTS (nreverse TESTS)) + + (dolist (TST TESTS) + (let* ( ;; For each test, convert CAR into a semantic-format-tag* fcn + (sym (intern (concat "semantic-format-tag-" (car TST)))) + ;; Convert the desired result from a string syntax to a string. + (desired (cdr TST)) + ;; What does the fmt function do? + (actual (funcall sym T))) + (when (not (string= desired actual)) + (should-not (list "Desired" desired + "Actual" actual + "Formatter" (car TST))))))) + (setq tags (cdr tags))))) + + ;; If it wasn't already in memory, whack it. + (when (and b (not fb)) + (kill-buffer b)))))) + +(provide 'format-tests) + +;;; format-tests.el ends here diff --git a/test/lisp/cedet/semantic/fw-tests.el b/test/lisp/cedet/semantic/fw-tests.el new file mode 100644 index 00000000000..7b1cd21bd1b --- /dev/null +++ b/test/lisp/cedet/semantic/fw-tests.el @@ -0,0 +1,45 @@ +;;; fw-tests.el --- Tests for semantic/fw.el -*- lexical-binding:t -*- + +;; Copyright (C) 2003-2021 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Moved here from test/manual/cedet/semantic-tests.el + +;;; Code: + +(require 'ert) +(require 'semantic/fw) + +;;; From semantic-fw: + +(ert-deftest semantic-test-data-cache () + "Test the data cache." + (let ((data '(a b c))) + (with-current-buffer (get-buffer-create " *semantic-test-data-cache*") + (erase-buffer) + (insert "The Moose is Loose") + (goto-char (point-min)) + (semantic-cache-data-to-buffer (current-buffer) (point) (+ (point) 5) + data 'moose 'exit-cache-zone) + ;; retrieve cached data + (should (equal (semantic-get-cache-data 'moose) data))))) + +;;; gw-tests.el ends here diff --git a/test/lisp/cedet/srecode-utest-template.el b/test/lisp/cedet/srecode-utest-template.el index f97ff18320e..087dcfd8996 100644 --- a/test/lisp/cedet/srecode-utest-template.el +++ b/test/lisp/cedet/srecode-utest-template.el @@ -1,4 +1,4 @@ -;;; srecode/test.el --- SRecode Core Template tests. -*- lexical-binding:t -*- +;;; srecode-utest-template.el --- SRecode Core Template tests. -*- lexical-binding:t -*- ;; Copyright (C) 2008-2021 Free Software Foundation, Inc. diff --git a/test/lisp/cedet/srecode/document-tests.el b/test/lisp/cedet/srecode/document-tests.el new file mode 100644 index 00000000000..0bc6e10d7a7 --- /dev/null +++ b/test/lisp/cedet/srecode/document-tests.el @@ -0,0 +1,80 @@ +;;; document-tests.el --- Tests for srecode/document.el -*- lexical-binding:t -*- + +;; Copyright (C) 2008-2021 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Extracted from srecode-document.el in the CEDET distribution. + +;; Converted to ert from test/manual/cedet/srecode-tests.el + +;;; Code: + +(require 'ert) +(require 'srecode/document) + +;; FIXME: This test fails even before conversion to ert. +(ert-deftest srecode-document-function-comment-extract-test () + "Test old comment extraction. +Dump out the extracted dictionary." + :tags '(:unstable) + (interactive) + + (srecode-load-tables-for-mode major-mode) + (srecode-load-tables-for-mode major-mode 'document) + + (should (srecode-table)) + ;; (error "No template table found for mode %s" major-mode) + + (let* ((temp (srecode-template-get-table (srecode-table) + "function-comment" + "declaration" + 'document)) + (fcn-in (semantic-current-tag))) + + (should temp) + ;; (error "No templates for function comments") + + ;; Try to figure out the tag we want to use. + (should fcn-in) + (should (semantic-tag-of-class-p fcn-in 'function)) + ;; (error "No tag of class 'function to insert comment for") + + (let ((lextok (semantic-documentation-comment-preceding-tag fcn-in 'lex))) + + (should lextok) + ;; (error "No comment to attempt an extraction") + + (let ((s (semantic-lex-token-start lextok)) + (e (semantic-lex-token-end lextok)) + (extract nil)) + + (pulse-momentary-highlight-region s e) + + ;; Extract text from the existing comment. + (setq extract (srecode-extract temp s e)) + + (with-output-to-temp-buffer "*SRECODE DUMP*" + (princ "EXTRACTED DICTIONARY FOR ") + (princ (semantic-tag-name fcn-in)) + (princ "\n--------------------------------------------\n") + (srecode-dump extract)))))) + +;;; document-tests.el ends here diff --git a/test/lisp/cedet/srecode/fields-tests.el b/test/lisp/cedet/srecode/fields-tests.el new file mode 100644 index 00000000000..5f634a5e4ce --- /dev/null +++ b/test/lisp/cedet/srecode/fields-tests.el @@ -0,0 +1,238 @@ +;;; srecode/fields-tests.el --- Tests for srecode/fields.el -*- lexical-binding: t -*- + +;; Copyright (C) 2008-2021 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Extracted from srecode-fields.el in the CEDET distribution. + +;; Converted to ert from test/manual/cedet/srecode-tests.el + +;;; Code: + +;;; From srecode-fields: + +(require 'ert) +(require 'srecode/fields) + +(defvar srecode-field-utest-text + "This is a test buffer. + +It is filled with some text." + "Text for tests.") + +;; FIXME: This test fails even before conversion to ert. +(ert-deftest srecode-field-utest-impl () + "Implementation of the SRecode field utest." + :tags '(:unstable) + (save-excursion + (find-file "/tmp/srecode-field-test.txt") + + (erase-buffer) + (goto-char (point-min)) + (insert srecode-field-utest-text) + (set-buffer-modified-p nil) + + ;; Test basic field generation. + (let ((srecode-field-archive nil) + (f nil)) + + (end-of-line) + (forward-word -1) + + (setq f (srecode-field "Test" + :name "TEST" + :start 6 + :end 8)) + + (when (or (not (slot-boundp f 'overlay)) (not (oref f overlay))) + (error "Field test: Overlay info not created for field")) + + (when (and (overlayp (oref f overlay)) + (not (overlay-get (oref f overlay) 'srecode-init-only))) + (error "Field creation overlay is not tagged w/ init flag")) + + (srecode-overlaid-activate f) + + (when (or (not (overlayp (oref f overlay))) + (overlay-get (oref f overlay) 'srecode-init-only)) + (error "New field overlay not created during activation")) + + (when (not (= (length srecode-field-archive) 1)) + (error "Field test: Incorrect number of elements in the field archive")) + (when (not (eq f (car srecode-field-archive))) + (error "Field test: Field did not auto-add itself to the field archive")) + + (when (not (overlay-get (oref f overlay) 'keymap)) + (error "Field test: Overlay keymap not set")) + + (when (not (string= "is" (srecode-overlaid-text f))) + (error "Field test: Expected field text 'is', not %s" + (srecode-overlaid-text f))) + + ;; Test deletion. + (srecode-delete f) + + (when (slot-boundp f 'overlay) + (error "Field test: Overlay not deleted after object delete")) + ) + + ;; Test basic region construction. + (let* ((srecode-field-archive nil) + (reg nil) + (fields + (list + (srecode-field "Test1" :name "TEST-1" :start 5 :end 10) + (srecode-field "Test2" :name "TEST-2" :start 15 :end 20) + (srecode-field "Test3" :name "TEST-3" :start 25 :end 30) + + (srecode-field "Test4" :name "TEST-4" :start 35 :end 35)) + )) + + (when (not (= (length srecode-field-archive) 4)) + (error "Region Test: Found %d fields. Expected 4" + (length srecode-field-archive))) + + (setq reg (srecode-template-inserted-region "REG" + :start 4 + :end 40)) + + (srecode-overlaid-activate reg) + + ;; Make sure it was cleared. + (when srecode-field-archive + (error "Region Test: Did not clear field archive")) + + ;; Auto-positioning. + (when (not (eq (point) 5)) + (error "Region Test: Did not reposition on first field")) + + ;; Active region + (when (not (eq (srecode-active-template-region) reg)) + (error "Region Test: Active region not set")) + + ;; Various sizes + (mapc (lambda (T) + (if (string= (eieio-object-name-string T) "Test4") + (progn + (when (not (srecode-empty-region-p T)) + (error "Field %s is not empty" + (eieio-object-name T))) + ) + (when (not (= (srecode-region-size T) 5)) + (error "Calculated size of %s was not 5" + (eieio-object-name T))))) + fields) + + ;; Make sure things stay up after a 'command'. + (srecode-field-post-command) + (when (not (eq (srecode-active-template-region) reg)) + (error "Region Test: Active region did not stay up")) + + ;; Test field movement. + (when (not (eq (srecode-overlaid-at-point 'srecode-field) + (nth 0 fields))) + (error "Region Test: Field %s not under point" + (eieio-object-name (nth 0 fields)))) + + (srecode-field-next) + + (when (not (eq (srecode-overlaid-at-point 'srecode-field) + (nth 1 fields))) + (error "Region Test: Field %s not under point" + (eieio-object-name (nth 1 fields)))) + + (srecode-field-prev) + + (when (not (eq (srecode-overlaid-at-point 'srecode-field) + (nth 0 fields))) + (error "Region Test: Field %s not under point" + (eieio-object-name (nth 0 fields)))) + + ;; Move cursor out of the region and have everything cleaned up. + (goto-char 42) + (srecode-field-post-command) + (when (srecode-active-template-region) + (error "Region Test: Active region did not clear on move out")) + + (mapc (lambda (T) + (when (slot-boundp T 'overlay) + (error "Overlay did not clear off of field %s" + (eieio-object-name T)))) + fields) + + ;; End of LET + ) + + ;; Test variable linkage. + (let* ((srecode-field-archive nil) + (f1 (srecode-field "Test1" :name "TEST" :start 6 :end 8)) + (f2 (srecode-field "Test2" :name "TEST" :start 28 :end 30)) + (f3 (srecode-field "Test3" :name "NOTTEST" :start 35 :end 40)) + (reg (srecode-template-inserted-region "REG" :start 4 :end 40))) + (srecode-overlaid-activate reg) + + (when (not (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f2))) + (error "Linkage Test: Init strings are not =")) + (when (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f3)) + (error "Linkage Test: Init string on dissimilar fields is now the same")) + + (goto-char 7) + (insert "a") + + (when (not (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f2))) + (error "Linkage Test: mid-insert strings are not =")) + (when (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f3)) + (error "Linkage Test: mid-insert string on dissimilar fields is now the same")) + + (goto-char 9) + (insert "t") + + (when (not (string= (srecode-overlaid-text f1) "iast")) + (error "Linkage Test: tail-insert failed to captured added char")) + (when (not (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f2))) + (error "Linkage Test: tail-insert strings are not =")) + (when (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f3)) + (error "Linkage Test: tail-insert string on dissimilar fields is now the same")) + + (goto-char 6) + (insert "b") + + (when (not (string= (srecode-overlaid-text f1) "biast")) + (error "Linkage Test: tail-insert failed to captured added char")) + (when (not (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f2))) + (error "Linkage Test: tail-insert strings are not =")) + (when (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f3)) + (error "Linkage Test: tail-insert string on dissimilar fields is now the same")) + + ;; Cleanup + (srecode-delete reg)) + + (set-buffer-modified-p nil))) + +;;; srecode/fields-tests.el ends here |