Browse Source

Boolean variables now correctly converted to python.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4146 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
10f4b5965c
  1. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs
  2. 42
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/BooleanConversionTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs

@ -891,8 +891,10 @@ namespace ICSharpCode.PythonBinding @@ -891,8 +891,10 @@ namespace ICSharpCode.PythonBinding
public object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
{
if (primitiveExpression.LiteralFormat == LiteralFormat.None) {
if (primitiveExpression.Value == null) {
Append("None");
} else if (primitiveExpression.Value is Boolean) {
Append(primitiveExpression.Value.ToString());
} else {
Append(primitiveExpression.StringValue);
}

42
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/BooleanConversionTestFixture.cs

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using ICSharpCode.NRefactory;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
namespace PythonBinding.Tests.Converter
{
[TestFixture]
public class BooleanVariableConversionTestFixture
{
string csharp = "class Foo\r\n" +
"{\r\n" +
"\tbool a;\r\n" +
"\r\n" +
"\tpublic Foo()\r\n" +
"\t{\r\n" +
"\t\ta = true;\r\n" +
"\t}\r\n" +
"}";
[Test]
public void ConvertedPythonCode()
{
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
string python = converter.Convert(csharp);
string expectedPython = "class Foo(object):\r\n" +
"\tdef __init__(self):\r\n" +
"\t\tself._a = True";
Assert.AreEqual(expectedPython, python);
}
}
}

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -97,6 +97,7 @@ @@ -97,6 +97,7 @@
<Compile Include="Converter\ArrayConversionTestFixture.cs" />
<Compile Include="Converter\AssignmentOperatorConversionTestFixture.cs" />
<Compile Include="Converter\BitShiftConversionTestFixture.cs" />
<Compile Include="Converter\BooleanConversionTestFixture.cs" />
<Compile Include="Converter\BreakAndContinueConversionTestFixture.cs" />
<Compile Include="Converter\CallConstructorWithParametersConversionTestFixture.cs" />
<Compile Include="Converter\ClassDestructorConversionTestFixture.cs" />

Loading…
Cancel
Save