From 10f4b5965cf7a70dce87f045d90a6b32605ebc42 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 25 May 2009 15:57:53 +0000 Subject: [PATCH] Boolean variables now correctly converted to python. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4146 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/NRefactoryToPythonConverter.cs | 4 +- .../Converter/BooleanConversionTestFixture.cs | 42 +++++++++++++++++++ .../Test/PythonBinding.Tests.csproj | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/BooleanConversionTestFixture.cs diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs index 0b92a7980f..9485a6ff78 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs @@ -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); } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/BooleanConversionTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/BooleanConversionTestFixture.cs new file mode 100644 index 0000000000..99d80f6267 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/BooleanConversionTestFixture.cs @@ -0,0 +1,42 @@ +// +// +// +// +// $Revision$ +// + +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); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index 83c1bf4d75..aee3ab6c23 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -97,6 +97,7 @@ +