~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/UnitTests/Mono.TextEditor.Tests/SyntaxHighlightingTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// SyntaxHighlightingTests.cs
3
 
//  
4
 
// Author:
5
 
//       Mike Krüger <mkrueger@novell.com>
6
 
// 
7
 
// Copyright (c) 2009 Mike Krüger
8
 
// 
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:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
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
25
 
// THE SOFTWARE.
26
 
 
27
 
using System;
28
 
using NUnit.Framework;
29
 
using Mono.TextEditor.Highlighting;
30
 
 
31
 
namespace Mono.TextEditor.Tests
32
 
{
33
 
        [TestFixture()]
34
 
        public class SyntaxHighlightingTests
35
 
        {
36
 
                [Test]
37
 
                public void ValidateSyntaxModes ()
38
 
                {
39
 
                        Assert.IsTrue (SyntaxModeService.ValidateAllSyntaxModes ());
40
 
                }
41
 
                
42
 
                static void TestOutput (string input, string expectedMarkup)
43
 
                {
44
 
                        TestOutput (input, expectedMarkup, "text/x-csharp");
45
 
                }
46
 
                
47
 
                public static string GetMarkup (string input, string syntaxMode)
48
 
                {
49
 
                        var data = new TextEditorData ();
50
 
                        data.Document.SyntaxMode = SyntaxModeService.GetSyntaxMode (data.Document, syntaxMode);
51
 
                        data.Text = input;
52
 
                        data.ColorStyle = SyntaxModeService.GetColorStyle (null, "TangoLight");
53
 
                        return data.GetMarkup (0, data.Length, false);
54
 
                }
55
 
 
56
 
                static void TestOutput (string input, string expectedMarkup, string syntaxMode)
57
 
                {
58
 
                        string markup = GetMarkup (input, syntaxMode);
59
 
                        Assert.AreEqual (expectedMarkup, markup, "expected:" + expectedMarkup + Environment.NewLine + "But got:" + markup);
60
 
                }
61
 
                 
62
 
                [Test]
63
 
                public void TestSpans ()
64
 
                {
65
 
                        TestOutput ("/* TestMe */",
66
 
                                "<span foreground=\"#4D9A06\">/* TestMe */</span>");
67
 
                }
68
 
                
69
 
                [Test]
70
 
                public void TestStringEscapes ()
71
 
                {
72
 
                        TestOutput ("\"Escape:\\\" \"outtext",
73
 
                                "<span foreground=\"#75507B\">\"Escape:\\\" \"</span><span foreground=\"#000000\">outtext</span>");
74
 
                }
75
 
                
76
 
                [Test]
77
 
                public void TestVerbatimStringEscapes ()
78
 
                {
79
 
                        TestOutput ("@\"Escape:\"\" \"outtext",
80
 
                                "<span foreground=\"#75507B\">@\"Escape:\"\" \"</span><span foreground=\"#000000\">outtext</span>");
81
 
                }
82
 
                
83
 
                [Test]
84
 
                public void TestHexDigit ()
85
 
                {
86
 
                        TestOutput ("0x12345679AFFEuL",
87
 
                                "<span foreground=\"#75507B\">0x12345679AFFEuL</span>");
88
 
                }
89
 
                
90
 
                [Test]
91
 
                public void TestDoubleDigit ()
92
 
                {
93
 
                        TestOutput ("123.45678e-09d",
94
 
                                "<span foreground=\"#75507B\">123.45678e-09d</span>");
95
 
                }
96
 
                
97
 
                [Test]
98
 
                public void TestCDATASection ()
99
 
                {
100
 
                        string markup = GetMarkup ("<![CDATA[ test ]]>", "application/xml");
101
 
                        if (markup != "<span foreground=\"#A40000\" weight=\"bold\">&lt;![CDATA[</span><span foreground=\"#4D9A06\"> test</span><span foreground=\"#A40000\" weight=\"bold\"> ]]&gt;</span>" && 
102
 
                            markup != "<span foreground=\"#A40000\" weight=\"bold\">&lt;![CDATA[</span><span foreground=\"#4D9A06\"> test </span><span foreground=\"#A40000\" weight=\"bold\">]]&gt;</span>") {
103
 
                                Assert.Fail ("CDATA markup invalid:" + markup);
104
 
                        }
105
 
                        
106
 
                        TestOutput ("<![CDATA[ test]]>",
107
 
                                    "<span foreground=\"#A40000\" weight=\"bold\">&lt;![CDATA[</span><span foreground=\"#4D9A06\"> test</span><span foreground=\"#A40000\" weight=\"bold\">]]&gt;</span>",
108
 
                                    "application/xml");
109
 
                }
110
 
                
111
 
                
112
 
                ///<summary>
113
 
                /// Bug 603 - Last token in doc comment has wrong color 
114
 
                ///</summary>
115
 
                [Test]
116
 
                public void TestBug603 ()
117
 
                {
118
 
                        TestOutput ("///<summary>foo bar</summary>",
119
 
                                "<span foreground=\"#4D9A06\">///&lt;summary&gt;foo bar&lt;/summary&gt;</span>");
120
 
                }
121
 
        }
122
 
}