Commit a6837d24da56845a14b6f7f042093e735cc99966

Golmote 2018-03-24T12:25:27

C#: More generic class-name highlighting. Fix #1365

diff --git a/components/prism-csharp.js b/components/prism-csharp.js
index d804ade..84a36e6 100644
--- a/components/prism-csharp.js
+++ b/components/prism-csharp.js
@@ -13,7 +13,17 @@ Prism.languages.csharp = Prism.languages.extend('clike', {
 	'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i
 });
 
-Prism.languages.insertBefore('csharp', 'keyword', {
+if (Prism.util.type(Prism.languages.csharp['class-name']) !== 'Array') {
+	Prism.languages.csharp['class-name'] = [Prism.languages.csharp['class-name']];
+}
+Prism.languages.csharp['class-name'].push({
+	pattern: /\b[A-Z]\w*(?:\.\w+)*\b(?!\()/,
+	inside: {
+		punctuation: /\./
+	}
+});
+
+Prism.languages.insertBefore('csharp', 'class-name', {
 	'generic-method': {
 		pattern: /[a-z0-9_]+\s*<[^>\r\n]+?>\s*(?=\()/i,
 		alias: 'function',
diff --git a/components/prism-csharp.min.js b/components/prism-csharp.min.js
index 02a664e..00f441b 100644
--- a/components/prism-csharp.min.js
+++ b/components/prism-csharp.min.js
@@ -1 +1 @@
-Prism.languages.csharp=Prism.languages.extend("clike",{keyword:/\b(?:abstract|add|alias|as|ascending|async|await|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|global|goto|group|if|implicit|in|int|interface|internal|into|is|join|let|lock|long|namespace|new|null|object|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|remove|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|value|var|virtual|void|volatile|where|while|yield)\b/,string:[{pattern:/@("|')(?:\1\1|\\[\s\S]|(?!\1)[^\\])*\1/,greedy:!0},{pattern:/("|')(?:\\.|(?!\1)[^\\\r\n])*?\1/,greedy:!0}],number:/\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i}),Prism.languages.insertBefore("csharp","keyword",{"generic-method":{pattern:/[a-z0-9_]+\s*<[^>\r\n]+?>\s*(?=\()/i,alias:"function",inside:{keyword:Prism.languages.csharp.keyword,punctuation:/[<>(),.:]/}},preprocessor:{pattern:/(^\s*)#.*/m,lookbehind:!0,alias:"property",inside:{directive:{pattern:/(\s*#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,lookbehind:!0,alias:"keyword"}}}}),Prism.languages.dotnet=Prism.languages.csharp;
\ No newline at end of file
+Prism.languages.csharp=Prism.languages.extend("clike",{keyword:/\b(?:abstract|add|alias|as|ascending|async|await|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|global|goto|group|if|implicit|in|int|interface|internal|into|is|join|let|lock|long|namespace|new|null|object|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|remove|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|value|var|virtual|void|volatile|where|while|yield)\b/,string:[{pattern:/@("|')(?:\1\1|\\[\s\S]|(?!\1)[^\\])*\1/,greedy:!0},{pattern:/("|')(?:\\.|(?!\1)[^\\\r\n])*?\1/,greedy:!0}],number:/\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i}),"Array"!==Prism.util.type(Prism.languages.csharp["class-name"])&&(Prism.languages.csharp["class-name"]=[Prism.languages.csharp["class-name"]]),Prism.languages.csharp["class-name"].push({pattern:/\b[A-Z]\w*(?:\.\w+)*\b(?!\()/,inside:{punctuation:/\./}}),Prism.languages.insertBefore("csharp","class-name",{"generic-method":{pattern:/[a-z0-9_]+\s*<[^>\r\n]+?>\s*(?=\()/i,alias:"function",inside:{keyword:Prism.languages.csharp.keyword,punctuation:/[<>(),.:]/}},preprocessor:{pattern:/(^\s*)#.*/m,lookbehind:!0,alias:"property",inside:{directive:{pattern:/(\s*#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,lookbehind:!0,alias:"keyword"}}}}),Prism.languages.dotnet=Prism.languages.csharp;
\ No newline at end of file
diff --git a/tests/languages/csharp+aspnet/directive_feature.test b/tests/languages/csharp+aspnet/directive_feature.test
index f19c2a8..7e5ff3a 100644
--- a/tests/languages/csharp+aspnet/directive_feature.test
+++ b/tests/languages/csharp+aspnet/directive_feature.test
@@ -10,59 +10,65 @@
 [
 	["directive tag", [
 		["directive tag", "<%:"],
-		" Page",
-		["punctuation", "."],
-		"Title ",
+		["class-name", [
+			"Page",
+			["punctuation", "."],
+			"Title"
+		]],
 		["directive tag", "%>"]
 	]],
 
 	["directive tag", [
-        ["directive tag", "<%#:"],
-        "Item",
-        ["punctuation", "."],
-        "ProductID",
-        ["directive tag", "%>"]
-    ]],
+		["directive tag", "<%#:"],
+		["class-name", [
+			"Item",
+			["punctuation", "."],
+			"ProductID"
+		]],
+		["directive tag", "%>"]
+	]],
 
-    ["tag", [
-        ["tag", [
-            ["punctuation", "<"],
-            "a"
-        ]],
-        ["attr-name", [
-            "href"
-        ]],
-        ["attr-value", [
-            ["punctuation", "="],
-            ["punctuation", "\""],
-            "ProductDetails.aspx?productID=",
-            ["directive tag", [
-                ["directive tag", "<%#:"],
-                "Item",
-		        ["punctuation", "."],
-		        "ProductID",
-		        ["directive tag", "%>"]
-            ]],
-            ["punctuation", "\""]
-        ]],
-        ["punctuation", ">"]
-    ]],
+	["tag", [
+		["tag", [
+			["punctuation", "<"],
+			"a"
+		]],
+		["attr-name", [
+			"href"
+		]],
+		["attr-value", [
+			["punctuation", "="],
+			["punctuation", "\""],
+			"ProductDetails.aspx?productID=",
+			["directive tag", [
+				["directive tag", "<%#:"],
+				["class-name", [
+					"Item",
+					["punctuation", "."],
+					"ProductID"
+				]],
+				["directive tag", "%>"]
+			]],
+			["punctuation", "\""]
+		]],
+		["punctuation", ">"]
+	]],
 
-    ["directive tag", [
-        ["directive tag", "<%"],
-        ["keyword", "if"],
-        ["punctuation", "("],
-        "foo",
-        ["punctuation", ")"],
-        ["punctuation", "{"],
-        ["directive tag", "%>"]
-    ]],
-    "\r\n\tfoobar\r\n",
-    ["directive tag", [
-        ["directive tag", "<%"],
-        ["punctuation", "}"],
-        ["directive tag", "%>"]
-    ]]
+	["directive tag", [
+		["directive tag", "<%"],
+		["keyword", "if"],
+		["punctuation", "("],
+		"foo",
+		["punctuation", ")"],
+		["punctuation", "{"],
+		["directive tag", "%>"]
+	]],
+	"\r\n\tfoobar\r\n",
+	["directive tag", [
+		["directive tag", "<%"],
+		["punctuation", "}"],
+		["directive tag", "%>"]
+	]]
 ]
 
 ----------------------------------------------------
diff --git a/tests/languages/csharp/class-name_feature.test b/tests/languages/csharp/class-name_feature.test
new file mode 100644
index 0000000..1f8bfa1
--- /dev/null
+++ b/tests/languages/csharp/class-name_feature.test
@@ -0,0 +1,21 @@
+class Foo
+interface BarBaz
+Foo.Barbaz
+
+----------------------------------------------------
+
+[
+	["keyword", "class"],
+	["class-name", ["Foo"]],
+	["keyword", "interface"],
+	["class-name", ["BarBaz"]],
+	["class-name", [
+		"Foo",
+		["punctuation", "."],
+		"Barbaz"
+	]]
+]
+
+----------------------------------------------------
+
+Checks for class names.
\ No newline at end of file
diff --git a/tests/languages/csharp/issue1365.test b/tests/languages/csharp/issue1365.test
new file mode 100644
index 0000000..6aaf3c7
--- /dev/null
+++ b/tests/languages/csharp/issue1365.test
@@ -0,0 +1,39 @@
+interface ILogger {
+    void Init(SomeClass file);
+	void LogInfo(string message);
+}
+public class SomeClass : BaseClass {}
+
+----------------------------------------------------
+
+[
+	["keyword", "interface"],
+	["class-name", ["ILogger"]],
+	["punctuation", "{"],
+	["keyword", "void"],
+	["function", "Init"],
+	["punctuation", "("],
+	["class-name", ["SomeClass"]],
+	" file",
+	["punctuation", ")"],
+	["punctuation", ";"],
+	["keyword", "void"],
+	["function", "LogInfo"],
+	["punctuation", "("],
+	["keyword", "string"],
+	" message",
+	["punctuation", ")"],
+	["punctuation", ";"],
+	["punctuation", "}"],
+	["keyword", "public"],
+	["keyword", "class"],
+	["class-name", ["SomeClass"]],
+	["punctuation", ":"],
+	["class-name", ["BaseClass"]],
+	["punctuation", "{"],
+	["punctuation", "}"]
+]
+
+----------------------------------------------------
+
+Checks for class names. See #1365
\ No newline at end of file