From 45d0db1da463e42eb4b77664336553a89c882a98 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sun, 29 Sep 2013 20:12:36 +0200 Subject: [PATCH] Fix unitTest's --- .../Irony/ReportingLanguageRuntime.cs | 36 +++++++++++++++++- .../src/Expressions/IntegrationTests.cs | 38 ++++++++----------- .../src/Expressions/IronyGeneral.cs | 1 + 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/ReportingLanguageRuntime.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/ReportingLanguageRuntime.cs index 7f61faffc4..93a0a9e4b2 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/ReportingLanguageRuntime.cs +++ b/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) // 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 { 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; + + } + */ } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs index 2dfddda071..2c86feadda 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs @@ -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 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 { Text = "myExporttextColumn" }); - collection.Add(new ExportText() - { - Text ="= 3 + 5" - - }); - } [TestFixtureSetUp] diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IronyGeneral.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IronyGeneral.cs index 8d45d125b3..67c6a09319 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IronyGeneral.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IronyGeneral.cs @@ -49,6 +49,7 @@ namespace ICSharpCode.Reporting.Test.Expressions #endregion + #region System.Math [Test]