diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index adb0eec4..7e343d58 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -20,12 +20,14 @@ module Linguist end # .h extensions are ambigious between C, C++, and Objective-C. - # We want to shortcut look for Objective-C. + # We want to shortcut look for Objective-C _and_ now C++ too! # # Returns an array of Languages or [] + # TODO rename this method as we're not strictly disambiguating between .h files here. def self.disambiguate_h(data, languages) matches = [] matches << Language["Objective-C"] if data.include?("@interface") + matches << Language["C++"] if data.include?("#include ") matches end diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index 7935bd56..fc8b6755 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -511,8 +511,8 @@ ".gemrc" ] }, - "tokens_total": 436395, - "languages_total": 507, + "tokens_total": 436401, + "languages_total": 508, "tokens": { "ABAP": { "*/**": 1, @@ -8562,7 +8562,7 @@ "C++": { "class": 40, "Bar": 2, - "{": 580, + "{": 581, "protected": 4, "char": 127, "*name": 6, @@ -8572,7 +8572,7 @@ "hello": 2, "(": 2729, ")": 2731, - "}": 580, + "}": 581, "//": 278, "///": 843, "mainpage": 1, @@ -9245,7 +9245,7 @@ "#ifndef": 27, "BCM2835_H": 3, "#define": 341, - "#include": 120, + "#include": 121, "": 2, "defgroup": 7, "constants": 1, @@ -10120,7 +10120,7 @@ "": 4, "": 4, "": 2, - "namespace": 30, + "namespace": 31, "std": 52, "DEFAULT_DELIMITER": 1, "CsvStreamer": 5, @@ -11276,6 +11276,8 @@ "wrapMode": 2, "wmode.": 1, "wmode": 1, + "": 2, + "Gui": 1, "rpc_init": 1, "rpc_server_loop": 1, "v8": 9, @@ -11573,7 +11575,6 @@ "desc": 2, "look": 1, "ahead": 1, - "": 1, "smallPrime_t": 1, "UTILS_H": 3, "": 1, @@ -46342,7 +46343,7 @@ "Bluespec": 1298, "Brightscript": 579, "C": 58858, - "C++": 31175, + "C++": 31181, "Ceylon": 50, "Clojure": 510, "COBOL": 90, @@ -46478,7 +46479,7 @@ "Bluespec": 2, "Brightscript": 1, "C": 26, - "C++": 26, + "C++": 27, "Ceylon": 1, "Clojure": 7, "COBOL": 4, @@ -46600,5 +46601,5 @@ "Xtend": 2, "YAML": 1 }, - "md5": "7ab5683c610f7e81d6ea5fb470111bbe" + "md5": "4bd97c3aa060155c82b903fea0fecc57" } \ No newline at end of file diff --git a/samples/C++/render_adapter.cpp b/samples/C++/render_adapter.cpp new file mode 100644 index 00000000..4a18f6f6 --- /dev/null +++ b/samples/C++/render_adapter.cpp @@ -0,0 +1,6 @@ +#include + +namespace Gui +{ + +} diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index 07a7565f..6a5a748c 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -27,6 +27,12 @@ class TestHeuristcs < Test::Unit::TestCase assert_equal Language["Objective-C"], results.first end end + + def test_cpp_by_heuristics + languages = ["C++", "Objective-C"] + results = Heuristics.disambiguate_h(fixture("C++/render_adapter.cpp"), languages) + assert_equal Language["C++"], results.first + end def test_detect_still_works_if_nothing_matches match = Language.detect("Hello.m", fixture("Objective-C/hello.m"))