~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/TryCatchFinallyConversionTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using ICSharpCode.NRefactory;
 
6
using ICSharpCode.RubyBinding;
 
7
using NUnit.Framework;
 
8
 
 
9
namespace RubyBinding.Tests.Converter
 
10
{
 
11
        /// <summary>
 
12
        /// Converts a C# try-catch-finally to Ruby.
 
13
        /// </summary>
 
14
        [TestFixture]
 
15
        public class TryCatchFinallyConversionTestFixture
 
16
        {
 
17
                string csharp = "class Loader\r\n" +
 
18
                                                "{\r\n" +
 
19
                                                "    public void load(string xml)\r\n" +
 
20
                                                "    {\r\n" +
 
21
                                                "        try {\r\n" +
 
22
                                                "            XmlDocument doc = new XmlDocument();\r\n" +
 
23
                                                "            doc.LoadXml(xml);\r\n" +
 
24
                                                "        } catch (XmlException ex) {\r\n" +
 
25
                                                "            Console.WriteLine(ex.ToString());\r\n" +
 
26
                                                "        } finally {\r\n" +
 
27
                                                "            Console.WriteLine(xml);\r\n" +
 
28
                                                "        }\r\n" +
 
29
                                                "    }\r\n" +
 
30
                                                "}";
 
31
                
 
32
                [Test]
 
33
                public void ConvertedCode()
 
34
                {
 
35
                        string expectedRuby =
 
36
                                "class Loader\r\n" +
 
37
                                "    def load(xml)\r\n" +
 
38
                                "        begin\r\n" +
 
39
                                "            doc = XmlDocument.new()\r\n" +
 
40
                                "            doc.LoadXml(xml)\r\n" +
 
41
                                "        rescue XmlException => ex\r\n" +
 
42
                                "            Console.WriteLine(ex.ToString())\r\n" +
 
43
                                "        ensure\r\n" +
 
44
                                "            Console.WriteLine(xml)\r\n" +
 
45
                                "        end\r\n" +
 
46
                                "    end\r\n" +
 
47
                                "end";
 
48
                        
 
49
                        NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
 
50
                        converter.IndentString = "    ";
 
51
                        string Ruby = converter.Convert(csharp);
 
52
                
 
53
                        Assert.AreEqual(expectedRuby, Ruby);
 
54
                }
 
55
        }
 
56
}