From 8feb299b037c48a1a67697ba868ccc939a851ba0 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sun, 10 Oct 2021 12:29:14 +0300 Subject: text/x-objc++src: new type This MIME type name is used in Qt Creator [1] and KDevelop [2]. A different name - text/x-objcpp-src - is used in KSyntaxHighlighting [3]. The name text/x-objc++src is consistent with the existing MIME type names text/x-c++src and text/x-objcsrc. So KSyntaxHighlighting's name will have to be replaced later. The Objective-C Wikipedia article and the KSyntaxHighlighting's data file [3] claim that *.M is one of the file extensions of Objective-C++ source files. But since macOS's file system is case-insensitive by default, *.mm is used almost universally. Thus there is no need to complicate the MIME type database with case-sensitive attributes. Make text/x-troff-mm a subclass of text/troff to reuse its magic element. As far as I can tell, these two file formats share the same comment syntax, which is encoded in text/troff's magic. Add Objective-C, Objective-C++, Troff, Troff MM and C tests to verify correct detection of the new MIME type and the absence of regressions. [1] https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src/plugins/cppeditor/CppEditor.json.in?id=2cc28dea65846153d16c213283ffac7af530590d#n100 [2] https://invent.kde.org/kdevelop/kdevelop/-/blob/ebd207cca2387b5734a591803381880505e39a30/plugins/astyle/astyle_plugin.cpp#L284 [3] https://invent.kde.org/frameworks/syntax-highlighting/-/blob/0b2c0dc5368de519c4e9517a4dec69017df4cd6c/data/syntax/objectivecpp.xml#L3 --- data/freedesktop.org.xml.in | 8 +++++++- tests/mime-detection/comment-objc.m | 6 ++++++ tests/mime-detection/import-objc++.mm | 6 ++++++ tests/mime-detection/import-objc.m | 8 ++++++++ tests/mime-detection/include-objc++.mm | 6 ++++++ tests/mime-detection/list | 12 ++++++++++-- tests/mime-detection/no-extension-c-comment | 1 + tests/mime-detection/simple-obj-c.m | 8 -------- tests/mime-detection/simple-troff.mm | 2 ++ tests/mime-detection/simple-troff.tr | 4 ++++ 10 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 tests/mime-detection/comment-objc.m create mode 100644 tests/mime-detection/import-objc++.mm create mode 100644 tests/mime-detection/import-objc.m create mode 100644 tests/mime-detection/include-objc++.mm create mode 100644 tests/mime-detection/no-extension-c-comment delete mode 100644 tests/mime-detection/simple-obj-c.m create mode 100644 tests/mime-detection/simple-troff.mm create mode 100644 tests/mime-detection/simple-troff.tr diff --git a/data/freedesktop.org.xml.in b/data/freedesktop.org.xml.in index 6a639c83..399e7e7f 100644 --- a/data/freedesktop.org.xml.in +++ b/data/freedesktop.org.xml.in @@ -6435,6 +6435,12 @@ command to generate the output files. + + Objective-C++ source code + + + + OCaml source code @@ -6686,7 +6692,7 @@ command to generate the output files. Troff MM input document - + diff --git a/tests/mime-detection/comment-objc.m b/tests/mime-detection/comment-objc.m new file mode 100644 index 00000000..c3801ed1 --- /dev/null +++ b/tests/mime-detection/comment-objc.m @@ -0,0 +1,6 @@ +/*********************************************** +** +** Copyright (C) 2021 name +** License +** +***********************************************/ diff --git a/tests/mime-detection/import-objc++.mm b/tests/mime-detection/import-objc++.mm new file mode 100644 index 00000000..b90b737e --- /dev/null +++ b/tests/mime-detection/import-objc++.mm @@ -0,0 +1,6 @@ +#import + +void functionName() +{ + [foo methodical:fixIt]; +} diff --git a/tests/mime-detection/import-objc.m b/tests/mime-detection/import-objc.m new file mode 100644 index 00000000..ae0e0e34 --- /dev/null +++ b/tests/mime-detection/import-objc.m @@ -0,0 +1,8 @@ +#import + +int main(int argc, const char *argv[]) +{ + printf("Hello, world!\n"); + return 0; +} + diff --git a/tests/mime-detection/include-objc++.mm b/tests/mime-detection/include-objc++.mm new file mode 100644 index 00000000..cfa569d9 --- /dev/null +++ b/tests/mime-detection/include-objc++.mm @@ -0,0 +1,6 @@ +#include "myheader.h" + +int Foo::bar() +{ + return rand() % max_; +} diff --git a/tests/mime-detection/list b/tests/mime-detection/list index f5ea935c..946a0575 100644 --- a/tests/mime-detection/list +++ b/tests/mime-detection/list @@ -359,8 +359,13 @@ isdir.m text/x-matlab x test.mo text/x-modelica xoo # From https://bugs.freedesktop.org/show_bug.cgi?id=29733 bibtex.bib text/x-bibtex -# hand-made -simple-obj-c.m text/x-objcsrc +# the following 6 test files are hand-made +import-objc.m text/x-objcsrc +comment-objc.m text/x-objcsrc ox +import-objc++.mm text/x-objc++src ox +include-objc++.mm text/x-objc++src ox +simple-troff.tr text/troff +simple-troff.mm text/x-troff-mm xx # Copied from LLVM project test suite test.cl text/x-opencl-src ox # hand-made @@ -800,8 +805,11 @@ SConscript text/x-scons oxo SConscript.buildinfo text/x-scons oxo # Source code +# the following 3 test files are hand-made cplusplusfile.C text/x-c++src oxo cfile.c text/x-csrc oxo +no-extension-c-comment text/x-csrc x +test-gettext.c text/x-csrc # Common Lisp source code common-lisp.asd text/x-common-lisp oxo diff --git a/tests/mime-detection/no-extension-c-comment b/tests/mime-detection/no-extension-c-comment new file mode 100644 index 00000000..ee8cde08 --- /dev/null +++ b/tests/mime-detection/no-extension-c-comment @@ -0,0 +1 @@ +// Doc diff --git a/tests/mime-detection/simple-obj-c.m b/tests/mime-detection/simple-obj-c.m deleted file mode 100644 index ae0e0e34..00000000 --- a/tests/mime-detection/simple-obj-c.m +++ /dev/null @@ -1,8 +0,0 @@ -#import - -int main(int argc, const char *argv[]) -{ - printf("Hello, world!\n"); - return 0; -} - diff --git a/tests/mime-detection/simple-troff.mm b/tests/mime-detection/simple-troff.mm new file mode 100644 index 00000000..1b00a3a8 --- /dev/null +++ b/tests/mime-detection/simple-troff.mm @@ -0,0 +1,2 @@ +\" Example +.HU "macro" diff --git a/tests/mime-detection/simple-troff.tr b/tests/mime-detection/simple-troff.tr new file mode 100644 index 00000000..0ad4e921 --- /dev/null +++ b/tests/mime-detection/simple-troff.tr @@ -0,0 +1,4 @@ +.\" table +.TS +text example +.TE -- cgit v1.2.1