1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00
cs2j/CSharpTranslator/antlr3/cs2jTest/TranslationTemplate.cs
Kevin Glynn 791c01efa5 Big, Interim Commit. Main thing here is Translation Template rewrite
This is in a half-broken state, but Translation Template is now more how I want it.

Major things for TranslationTemplate:

- re-org of classes to be better aligned with reality
- Value equality implemented (and days of my life wasted)
- Many collections are lists so that we can add to them as we parse code

Also:

- The start of a unit test suite (yay!)

-
2010-10-11 18:16:01 +02:00

77 lines
1.9 KiB
C#

using System;
using NUnit.Framework;
using System.IO;
using System.Xml.Serialization;
using RusticiSoftware.Translator.Utils;
using System.Xml;
using System.Text;
using System.Collections.Generic;
namespace RusticiSoftware.Translator.CLR
{
[TestFixture()]
public class TranslationTemplateTest
{
private TypeRepTemplate ToStreamAndBack(TypeRepTemplate inT) {
XmlSerializer xmls = new XmlSerializer(inT.GetType(), Constants.TranslationTemplateNamespace);
using (MemoryStream ms = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
settings.Indent = true;
settings.IndentChars = "\t";
settings.NewLineChars = Environment.NewLine;
settings.ConformanceLevel = ConformanceLevel.Document;
using (XmlWriter writer = XmlTextWriter.Create(ms, settings))
{
xmls.Serialize(writer, inT);
}
#if VERBOSETESTS
string xml = Encoding.UTF8.GetString(ms.ToArray());
Console.WriteLine (xml);
#endif
//ms.Flush();
ms.Position = 0;
return TypeRepTemplate.newInstance(ms);
}
}
[Test()]
public void EnumCase ()
{
EnumRepTemplate to = new EnumRepTemplate();
to.Members.Add(new EnumMemberRepTemplate("START"));
to.Members.Add(new EnumMemberRepTemplate("EOF","3"));
EnumRepTemplate back = (EnumRepTemplate)ToStreamAndBack(to);
Assert.AreEqual(to, back);
}
[Test()]
public void DelegateCase ()
{
DelegateRepTemplate to = new DelegateRepTemplate();
to.Return = "System.String";
to.Params.Add(new ParamRepTemplate("System.Int32", "count"));
to.Params.Add(new ParamRepTemplate("System.Object", "fill"));
to.Params.Add(new ParamRepTemplate("System.Boolean", "verbose"));
to.Java = "fred";
DelegateRepTemplate back = (DelegateRepTemplate)ToStreamAndBack(to);
Assert.AreEqual(to, back);
}
}
}