~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/BinaryOperatorConversionTestFixture.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.NRefactory.Ast;
 
7
using ICSharpCode.RubyBinding;
 
8
using NUnit.Framework;
 
9
 
 
10
namespace RubyBinding.Tests.Converter
 
11
{
 
12
        /// <summary>
 
13
        /// Tests that all the binary operators are converted to
 
14
        /// Ruby correctly.
 
15
        /// </summary>
 
16
        [TestFixture]
 
17
        public class BinaryOperatorConversionTests
 
18
        {
 
19
                string csharp = "class Foo\r\n" +
 
20
                                                "{\r\n" +
 
21
                                                "    public int Run(i)\r\n" +
 
22
                                                "    {\r\n" +
 
23
                                                "        if (i BINARY_OPERATOR 0) {\r\n" +
 
24
                                                "            return 10;\r\n" +
 
25
                                                "        }\r\n" +
 
26
                                                "        return 0;\r\n" +
 
27
                                                "    }\r\n" +
 
28
                                                "}";
 
29
                
 
30
                [Test]
 
31
                public void GreaterThan()
 
32
                {
 
33
                        Assert.AreEqual(">", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.GreaterThan));
 
34
                }
 
35
 
 
36
                [Test]
 
37
                public void NotEqual()
 
38
                {
 
39
                        Assert.AreEqual("!=", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.InEquality));
 
40
                }
 
41
                
 
42
                [Test]
 
43
                public void Divide()
 
44
                {
 
45
                        Assert.AreEqual("/", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.Divide));
 
46
                }
 
47
                
 
48
                [Test]
 
49
                public void LessThan()
 
50
                {
 
51
                        Assert.AreEqual("<", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.LessThan));
 
52
                }
 
53
 
 
54
                [Test]
 
55
                public void Equals()
 
56
                {
 
57
                        string code = GetCode(@"==");
 
58
                        NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
 
59
                        converter.IndentString = "    ";
 
60
                        string RubyCode = converter.Convert(code);
 
61
                        string expectedRubyCode = "class Foo\r\n" +
 
62
                                                "    def Run(i)\r\n" +
 
63
                                                "        if i == 0 then\r\n" +
 
64
                                                "            return 10\r\n" +
 
65
                                                "        end\r\n" +
 
66
                                                "        return 0\r\n" +
 
67
                                                "    end\r\n" +
 
68
                                                "end";
 
69
                        Assert.AreEqual(expectedRubyCode, RubyCode);
 
70
                }
 
71
 
 
72
                [Test]
 
73
                public void LessThanOrEqual()
 
74
                {
 
75
                        Assert.AreEqual("<=", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.LessThanOrEqual));
 
76
                }
 
77
 
 
78
                [Test]
 
79
                public void GreaterThanOrEqual()
 
80
                {
 
81
                        Assert.AreEqual(">=", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.GreaterThanOrEqual));
 
82
                }
 
83
                
 
84
                [Test]
 
85
                public void Add()
 
86
                {
 
87
                        Assert.AreEqual("+", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.Add));
 
88
                }
 
89
                
 
90
                [Test]
 
91
                public void Multiply()
 
92
                {
 
93
                        Assert.AreEqual("*", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.Multiply));
 
94
                }
 
95
                
 
96
                [Test]
 
97
                public void BitwiseAnd()
 
98
                {
 
99
                        Assert.AreEqual("&", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.BitwiseAnd));
 
100
                }
 
101
 
 
102
                [Test]
 
103
                public void BitwiseOr()
 
104
                {
 
105
                        Assert.AreEqual("|", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.BitwiseOr));
 
106
                }
 
107
 
 
108
                [Test]
 
109
                public void BooleanAnd()
 
110
                {
 
111
                        Assert.AreEqual("and", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.LogicalAnd));
 
112
                }
 
113
 
 
114
                [Test]
 
115
                public void BooleanOr()
 
116
                {
 
117
                        Assert.AreEqual("or", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.LogicalOr));
 
118
                }
 
119
                
 
120
                [Test]
 
121
                public void BooleanXor()
 
122
                {
 
123
                        Assert.AreEqual("^", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.ExclusiveOr));
 
124
                }               
 
125
 
 
126
                [Test]
 
127
                public void Modulus()
 
128
                {
 
129
                        Assert.AreEqual("%", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.Modulus));
 
130
                }
 
131
 
 
132
                [Test]
 
133
                public void Subtract()
 
134
                {
 
135
                        Assert.AreEqual("-", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.Subtract));
 
136
                }
 
137
                
 
138
                [Test]
 
139
                public void DivideInteger()
 
140
                {
 
141
                        Assert.AreEqual("/", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.DivideInteger));
 
142
                }
 
143
 
 
144
                [Test]
 
145
                public void ReferenceEquality()
 
146
                {
 
147
                        Assert.AreEqual("is", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.ReferenceEquality));
 
148
                }
 
149
                
 
150
                [Test]
 
151
                public void BitShiftRight()
 
152
                {
 
153
                        Assert.AreEqual(">>", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.ShiftRight));
 
154
                }
 
155
                
 
156
                [Test]
 
157
                public void BitShiftLeft()
 
158
                {
 
159
                        Assert.AreEqual("<<", NRefactoryToRubyConverter.GetBinaryOperator(BinaryOperatorType.ShiftLeft));
 
160
                }
 
161
        
 
162
                /// <summary>
 
163
                /// Gets the C# code with the binary operator replaced with the
 
164
                /// specified string.
 
165
                /// </summary>
 
166
                string GetCode(string op)
 
167
                {
 
168
                        return csharp.Replace("BINARY_OPERATOR", op);
 
169
                }
 
170
        }
 
171
}