Browse Source

Fix unitTest's

reports
Peter Forstmeier 13 years ago
parent
commit
45d0db1da4
  1. 36
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/ReportingLanguageRuntime.cs
  2. 38
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs
  3. 1
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IronyGeneral.cs

36
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/ReportingLanguageRuntime.cs

@ -1,6 +1,7 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // 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) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Linq;
using Irony.Interpreter; using Irony.Interpreter;
using Irony.Parsing; using Irony.Parsing;
@ -19,11 +20,42 @@ namespace ICSharpCode.Reporting.Expressions.Irony
{ {
base.Init(); base.Init();
//add built-in methods, special form IIF, import Math and Environment methods //add built-in methods, special form IIF, import Math and Environment methods
// BuiltIns.AddMethod(BuiltInPrintMethod, "print"); // BuiltIns.AddMethod(BuiltInPrintMethod, "print");
// BuiltIns.AddMethod(BuiltInFormatMethod, "format"); // BuiltIns.AddMethod(BuiltInFormatMethod, "format");
BuiltIns.AddSpecialForm(SpecialFormsLibrary.Iif, "iif", 3, 3); BuiltIns.AddSpecialForm(SpecialFormsLibrary.Iif, "iif", 3, 3);
BuiltIns.ImportStaticMembers(typeof(System.Math)); BuiltIns.ImportStaticMembers(typeof(System.Math));
BuiltIns.ImportStaticMembers(typeof(Environment)); BuiltIns.ImportStaticMembers(typeof(Environment));
} }
/*
private object BuiltInPrintMethod(ScriptThread thread, object[] args) {
string text = string.Empty;
switch(args.Length) {
case 1:
text = string.Empty + args[0]; //compact and safe conversion ToString()
break;
case 0:
break;
default:
text = string.Join(" ", args);
break;
}
thread.App.WriteLine(text);
return null;
}
private object BuiltInFormatMethod(ScriptThread thread, object[] args) {
if (args == null || args.Length == 0) return null;
var template = args[0] as string;
if (template == null)
this.ThrowScriptError("Format template must be a string.");
if (args.Length == 1) return template;
//create formatting args array
var formatArgs = args.Skip(1).ToArray();
var text = string.Format(template, formatArgs);
return text;
}
*/
} }
} }

38
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs

@ -17,31 +17,29 @@ namespace ICSharpCode.Reporting.Test.Expressions
[Test] [Test]
public void ExpressionMustStartWithEqualChar() public void ExpressionMustStartWithEqualChar()
{ {
var result = collection[0]; collection[0].Text = "myText";
var result = collection[0].Text;
expressionVisitor.Visit(collection[0]); expressionVisitor.Visit(collection[0]);
Assert.That(result.Text,Is.EqualTo(collection[0].Text)); Assert.That(result,Is.EqualTo(collection[0].Text));
} }
[Test] [Test]
public void SimpleMath() { public void SimpleMath() {
expressionVisitor.Visit(collection[1]); collection[0].Text = "=3 + 6";
expressionVisitor.Visit(collection[0]);
Assert.That(collection[1].Text,Is.EqualTo("8")); Assert.That(collection[0].Text,Is.EqualTo("9"));
var res = Convert.ToInt32(collection[1].Text); var res = Convert.ToInt32(collection[0].Text);
Assert.That(res is int); Assert.That(res is int);
} }
[Test] [Test]
public void SimpleStringHandling () { public void SimpleStringHandling () {
var script = "='Sharpdevelop' + ' is great'"; var script = "='Sharpdevelop' + ' is great'";
collection.Add(new ExportText() collection[0].Text = script;
{ expressionVisitor.Visit(collection[0]);
Text = script Assert.That(collection[0].Text,Is.EqualTo("Sharpdevelop is great"));
});
expressionVisitor.Visit(collection[2]);
Assert.That(collection[2].Text,Is.EqualTo("Sharpdevelop is great"));
} }
#region System.Environment #region System.Environment
@ -67,10 +65,10 @@ namespace ICSharpCode.Reporting.Test.Expressions
public void CanRunSystemMath () { public void CanRunSystemMath () {
//Using methods imported from System.Math class //Using methods imported from System.Math class
var script = @"=abs(-1.0) + Log10(100.0) + sqrt(9) + floor(4.5) + sin(PI/2)"; var script = @"=abs(-1.0) + Log10(100.0) + sqrt(9) + floor(4.5) + sin(PI/2)";
collection[1].Text = script; collection[0].Text = script;
expressionVisitor.Visit(collection[1]); expressionVisitor.Visit(collection[0]);
var res = Convert.ToDouble(collection[1].Text); var res = Convert.ToDouble(collection[0].Text);
Assert.That(collection[1].Text,Is.EqualTo("11")); Assert.That(collection[0].Text,Is.EqualTo("11"));
} }
#endregion #endregion
@ -82,12 +80,6 @@ namespace ICSharpCode.Reporting.Test.Expressions
{ {
Text = "myExporttextColumn" Text = "myExporttextColumn"
}); });
collection.Add(new ExportText()
{
Text ="= 3 + 5"
});
} }
[TestFixtureSetUp] [TestFixtureSetUp]

1
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IronyGeneral.cs

@ -49,6 +49,7 @@ namespace ICSharpCode.Reporting.Test.Expressions
#endregion #endregion
#region System.Math #region System.Math
[Test] [Test]

Loading…
Cancel
Save