From b2a5c30a44e2750276e12ba2edc40cd5e4849e05 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 20 Dec 2013 22:28:25 -0600 Subject: [PATCH] A C++ shibboleth? --- lib/linguist/heuristics.rb | 4 +- lib/linguist/samples.json | 69 +++++++++++++++++++++++++++++----- samples/C++/render_adapter.cpp | 6 +++ test/test_heuristics.rb | 6 +++ 4 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 samples/C++/render_adapter.cpp diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 01e12e78..1b85108e 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -16,12 +16,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 end diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index aedb3d84..84c86f83 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -163,6 +163,9 @@ ".json", ".lock" ], + "JSON5": [ + ".json5" + ], "Julia": [ ".jl" ], @@ -509,8 +512,8 @@ ".gemrc" ] }, - "tokens_total": 428226, - "languages_total": 503, + "tokens_total": 428289, + "languages_total": 506, "tokens": { "ABAP": { "*/**": 1, @@ -8560,7 +8563,7 @@ "C++": { "class": 40, "Bar": 2, - "{": 562, + "{": 563, "protected": 4, "char": 126, "*name": 6, @@ -8570,15 +8573,15 @@ "hello": 2, "(": 2498, ")": 2500, - "}": 562, + "}": 563, "#pragma": 2, "once": 2, - "#include": 117, + "#include": 118, "": 4, "": 4, "": 2, "using": 4, - "namespace": 30, + "namespace": 31, "std": 52, "#define": 197, "DEFAULT_DELIMITER": 1, @@ -9957,6 +9960,8 @@ "wrapMode": 2, "wmode.": 1, "wmode": 1, + "": 1, + "Gui": 1, "v8": 9, "Scanner": 16, "UnicodeCache*": 4, @@ -23686,6 +23691,50 @@ "}": 73, "true": 3 }, + "JSON5": { + "{": 6, + "foo": 1, + "while": 1, + "true": 1, + "this": 1, + "here": 1, + "//": 2, + "inline": 1, + "comment": 1, + "hex": 1, + "xDEADbeef": 1, + "half": 1, + ".5": 1, + "delta": 1, + "+": 1, + "to": 1, + "Infinity": 1, + "and": 1, + "beyond": 1, + "finally": 1, + "oh": 1, + "[": 3, + "]": 3, + "}": 6, + "name": 1, + "version": 1, + "description": 1, + "keywords": 1, + "author": 1, + "contributors": 1, + "main": 1, + "bin": 1, + "dependencies": 1, + "devDependencies": 1, + "mocha": 1, + "scripts": 1, + "build": 1, + "test": 1, + "homepage": 1, + "repository": 1, + "type": 1, + "url": 1 + }, "Julia": { "##": 5, "Test": 1, @@ -45100,7 +45149,7 @@ "Bluespec": 1298, "Brightscript": 579, "C": 58858, - "C++": 22665, + "C++": 22671, "Ceylon": 50, "Clojure": 510, "COBOL": 90, @@ -45134,6 +45183,7 @@ "Java": 8987, "JavaScript": 76934, "JSON": 183, + "JSON5": 57, "Julia": 247, "Kotlin": 155, "KRL": 25, @@ -45235,7 +45285,7 @@ "Bluespec": 2, "Brightscript": 1, "C": 26, - "C++": 23, + "C++": 24, "Ceylon": 1, "Clojure": 7, "COBOL": 4, @@ -45269,6 +45319,7 @@ "Java": 6, "JavaScript": 20, "JSON": 4, + "JSON5": 2, "Julia": 1, "Kotlin": 1, "KRL": 1, @@ -45356,5 +45407,5 @@ "Xtend": 2, "YAML": 1 }, - "md5": "7e305e6e7267f7d227fa871bf83546b8" + "md5": "1b96eb81ded03f57c14ee681d73d5db6" } \ 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 e499cf7e..0fea2933 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.find_by_heuristics(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"))