2
// SyntaxHighlightingTests.cs
5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2009 Mike Krüger
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using NUnit.Framework;
29
using Mono.TextEditor.Highlighting;
31
namespace Mono.TextEditor.Tests
34
public class SyntaxHighlightingTests
37
public void ValidateSyntaxModes ()
39
Assert.IsTrue (SyntaxModeService.ValidateAllSyntaxModes ());
42
static void TestOutput (string input, string expectedMarkup)
44
TestOutput (input, expectedMarkup, "text/x-csharp");
47
public static string GetMarkup (string input, string syntaxMode)
49
var data = new TextEditorData ();
50
data.Document.SyntaxMode = SyntaxModeService.GetSyntaxMode (data.Document, syntaxMode);
52
data.ColorStyle = SyntaxModeService.GetColorStyle (null, "TangoLight");
53
return data.GetMarkup (0, data.Length, false);
56
static void TestOutput (string input, string expectedMarkup, string syntaxMode)
58
string markup = GetMarkup (input, syntaxMode);
59
Assert.AreEqual (expectedMarkup, markup, "expected:" + expectedMarkup + Environment.NewLine + "But got:" + markup);
63
public void TestSpans ()
65
TestOutput ("/* TestMe */",
66
"<span foreground=\"#4D9A06\">/* TestMe */</span>");
70
public void TestStringEscapes ()
72
TestOutput ("\"Escape:\\\" \"outtext",
73
"<span foreground=\"#75507B\">\"Escape:\\\" \"</span><span foreground=\"#000000\">outtext</span>");
77
public void TestVerbatimStringEscapes ()
79
TestOutput ("@\"Escape:\"\" \"outtext",
80
"<span foreground=\"#75507B\">@\"Escape:\"\" \"</span><span foreground=\"#000000\">outtext</span>");
84
public void TestHexDigit ()
86
TestOutput ("0x12345679AFFEuL",
87
"<span foreground=\"#75507B\">0x12345679AFFEuL</span>");
91
public void TestDoubleDigit ()
93
TestOutput ("123.45678e-09d",
94
"<span foreground=\"#75507B\">123.45678e-09d</span>");
98
public void TestCDATASection ()
100
string markup = GetMarkup ("<![CDATA[ test ]]>", "application/xml");
101
if (markup != "<span foreground=\"#A40000\" weight=\"bold\"><![CDATA[</span><span foreground=\"#4D9A06\"> test</span><span foreground=\"#A40000\" weight=\"bold\"> ]]></span>" &&
102
markup != "<span foreground=\"#A40000\" weight=\"bold\"><![CDATA[</span><span foreground=\"#4D9A06\"> test </span><span foreground=\"#A40000\" weight=\"bold\">]]></span>") {
103
Assert.Fail ("CDATA markup invalid:" + markup);
106
TestOutput ("<![CDATA[ test]]>",
107
"<span foreground=\"#A40000\" weight=\"bold\"><![CDATA[</span><span foreground=\"#4D9A06\"> test</span><span foreground=\"#A40000\" weight=\"bold\">]]></span>",
113
/// Bug 603 - Last token in doc comment has wrong color
116
public void TestBug603 ()
118
TestOutput ("///<summary>foo bar</summary>",
119
"<span foreground=\"#4D9A06\">///<summary>foo bar</summary></span>");