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 @@ @@ -1,6 +1,7 @@
// 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 System.Linq;
using Irony.Interpreter;
using Irony.Parsing;
@ -19,11 +20,42 @@ namespace ICSharpCode.Reporting.Expressions.Irony @@ -19,11 +20,42 @@ namespace ICSharpCode.Reporting.Expressions.Irony
{
base.Init();
//add built-in methods, special form IIF, import Math and Environment methods
// BuiltIns.AddMethod(BuiltInPrintMethod, "print");
// BuiltIns.AddMethod(BuiltInFormatMethod, "format");
// BuiltIns.AddMethod(BuiltInPrintMethod, "print");
// BuiltIns.AddMethod(BuiltInFormatMethod, "format");
BuiltIns.AddSpecialForm(SpecialFormsLibrary.Iif, "iif", 3, 3);
BuiltIns.ImportStaticMembers(typeof(System.Math));
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 @@ -17,31 +17,29 @@ namespace ICSharpCode.Reporting.Test.Expressions
[Test]
public void ExpressionMustStartWithEqualChar()
{
var result = collection[0];
collection[0].Text = "myText";
var result = collection[0].Text;
expressionVisitor.Visit(collection[0]);
Assert.That(result.Text,Is.EqualTo(collection[0].Text));
Assert.That(result,Is.EqualTo(collection[0].Text));
}
[Test]
public void SimpleMath() {
expressionVisitor.Visit(collection[1]);
Assert.That(collection[1].Text,Is.EqualTo("8"));
var res = Convert.ToInt32(collection[1].Text);
collection[0].Text = "=3 + 6";
expressionVisitor.Visit(collection[0]);
Assert.That(collection[0].Text,Is.EqualTo("9"));
var res = Convert.ToInt32(collection[0].Text);
Assert.That(res is int);
}
[Test]
public void SimpleStringHandling () {
var script = "='Sharpdevelop' + ' is great'";
collection.Add(new ExportText()
{
Text = script
});
expressionVisitor.Visit(collection[2]);
Assert.That(collection[2].Text,Is.EqualTo("Sharpdevelop is great"));
var script = "='Sharpdevelop' + ' is great'";
collection[0].Text = script;
expressionVisitor.Visit(collection[0]);
Assert.That(collection[0].Text,Is.EqualTo("Sharpdevelop is great"));
}
#region System.Environment
@ -67,10 +65,10 @@ namespace ICSharpCode.Reporting.Test.Expressions @@ -67,10 +65,10 @@ namespace ICSharpCode.Reporting.Test.Expressions
public void CanRunSystemMath () {
//Using methods imported from System.Math class
var script = @"=abs(-1.0) + Log10(100.0) + sqrt(9) + floor(4.5) + sin(PI/2)";
collection[1].Text = script;
expressionVisitor.Visit(collection[1]);
var res = Convert.ToDouble(collection[1].Text);
Assert.That(collection[1].Text,Is.EqualTo("11"));
collection[0].Text = script;
expressionVisitor.Visit(collection[0]);
var res = Convert.ToDouble(collection[0].Text);
Assert.That(collection[0].Text,Is.EqualTo("11"));
}
#endregion
@ -82,12 +80,6 @@ namespace ICSharpCode.Reporting.Test.Expressions @@ -82,12 +80,6 @@ namespace ICSharpCode.Reporting.Test.Expressions
{
Text = "myExporttextColumn"
});
collection.Add(new ExportText()
{
Text ="= 3 + 5"
});
}
[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 @@ -49,6 +49,7 @@ namespace ICSharpCode.Reporting.Test.Expressions
#endregion
#region System.Math
[Test]

Loading…
Cancel
Save