Browse Source

Supporting converting multiple variable assignments on a single line to Python.

4.0
Matt Ward 14 years ago
parent
commit
fba3a7a46d
  1. 19
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs
  2. 38
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/LocalVariableDefinitionsOnSameLineTests.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  4. 2
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/LocalVariableDefinitionsOnSameLineTests.cs

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

@ -807,15 +807,16 @@ namespace ICSharpCode.PythonBinding @@ -807,15 +807,16 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
{
VariableDeclaration variableDeclaration = localVariableDeclaration.Variables[0];
if (!variableDeclaration.Initializer.IsNull) {
// Create variable declaration.
AppendIndented(variableDeclaration.Name + " = ");
// Generate the variable initializer.
variableDeclaration.Initializer.AcceptVisitor(this, data);
AppendLine();
foreach (VariableDeclaration variableDeclaration in localVariableDeclaration.Variables) {
if (!variableDeclaration.Initializer.IsNull) {
// Create variable declaration.
AppendIndented(variableDeclaration.Name + " = ");
// Generate the variable initializer.
variableDeclaration.Initializer.AcceptVisitor(this, data);
AppendLine();
}
}
return null;
}

38
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/LocalVariableDefinitionsOnSameLineTests.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.NRefactory;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
namespace PythonBinding.Tests.Converter
{
[TestFixture]
public class LocalVariableDefinitionsOnSameLineTests
{
string csharp =
"class Foo\r\n" +
"{\r\n" +
" public Foo()\r\n" +
" {\r\n" +
" int i = 0, i = 2;\r\n" +
" }\r\n" +
"}";
[Test]
public void ConvertedPythonCode()
{
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
converter.IndentString = " ";
string python = converter.Convert(csharp);
string expectedPython =
"class Foo(object):\r\n" +
" def __init__(self):\r\n" +
" i = 0\r\n" +
" i = 2";
Assert.AreEqual(expectedPython, python);
}
}
}

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

@ -141,6 +141,7 @@ @@ -141,6 +141,7 @@
<Compile Include="Converter\IntegerClassFieldWithConstructorTestFixture.cs" />
<Compile Include="Converter\LocalVariableAssignedInConstructorTestFixture.cs" />
<Compile Include="Converter\LocalVariableDeclarationInIfStatementTestFixture.cs" />
<Compile Include="Converter\LocalVariableDefinitionsOnSameLineTests.cs" />
<Compile Include="Converter\LocalVariableNotInitializedTestFixture.cs" />
<Compile Include="Converter\MethodCallInConstructorTestFixture.cs" />
<Compile Include="Converter\MethodParameterConversionTestFixture.cs" />

2
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/LocalVariableDefinitionsOnSameLineTests.cs

@ -16,7 +16,7 @@ namespace RubyBinding.Tests.Converter @@ -16,7 +16,7 @@ namespace RubyBinding.Tests.Converter
"{\r\n" +
" public Foo()\r\n" +
" {\r\n" +
" int i = 0, i = 2\r\n" +
" int i = 0, i = 2;\r\n" +
" }\r\n" +
"}";

Loading…
Cancel
Save