From a97c39fd9d60950d417957dc61c331585e43130b Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Fri, 11 Oct 2013 20:05:30 +0200 Subject: [PATCH] Rework Fields!Fieldname --- .../Src/Expressions/Irony/Ast/FieldsNode.cs | 7 +- .../ICSharpCode.Reporting.Test.csproj | 5 +- .../src/Expressions/IntegrationTests.cs | 170 ------------------ .../InterationTests/FieldsFixture.cs | 59 ++++++ .../InterationTests/ParametersFixture.cs | 73 ++++++++ .../InterationTests/StandardTests.cs | 93 ++++++++++ .../Expressions/ParametersHandlingFixture.cs | 1 - 7 files changed, 233 insertions(+), 175 deletions(-) delete mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/FieldsFixture.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/ParametersFixture.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/StandardTests.cs diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/FieldsNode.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/FieldsNode.cs index c88548c647..27369a45e4 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/FieldsNode.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/FieldsNode.cs @@ -24,12 +24,13 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast fieldNode = AddChild("Args", nodes[2]); } + protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; //standard prolog - var c = thread.GetCurrentContainer(); - var cc = (ExportText)c.ExportedItems.Where(x => x.Name == fieldNode.AsString).FirstOrDefault(); - return cc.Text; + var container = thread.GetCurrentContainer(); + var column = (ExportText)container.ExportedItems.Where(x => x.Name == fieldNode.AsString).FirstOrDefault(); + return column.Text; } } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj index 3167e06e0c..200c4246b7 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj @@ -66,7 +66,9 @@ - + + + @@ -88,6 +90,7 @@ + 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 deleted file mode 100644 index 06d2f99d01..0000000000 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs +++ /dev/null @@ -1,170 +0,0 @@ -// 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.Collections.ObjectModel; -using ICSharpCode.Reporting.BaseClasses; -using ICSharpCode.Reporting.Exporter.Visitors; -using ICSharpCode.Reporting.Items; -using ICSharpCode.Reporting.PageBuilder.ExportColumns; -using NUnit.Framework; - -namespace ICSharpCode.Reporting.Test.Expressions -{ - [TestFixture] - public class IntegrationTests - { - Collection collection; - ExpressionVisitor expressionVisitor; - - [Test] - public void ExpressionMustStartWithEqualChar() - { - collection[0].Text = "myText"; - var result = collection[0].Text; - expressionVisitor.Visit(collection[0]); - Assert.That(result,Is.EqualTo(collection[0].Text)); - } - - - [Test] - public void ReportSyntaxError() { - collection[0].Text = "= myText"; - expressionVisitor.Visit(collection[0]); - } - - - - [Test] - public void SimpleStringHandling () { - 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 - - [Test] - [Ignore] - public void CanUserSystemEnvironment() { - /* - //Using methods imported from System.Environment - var script = @"report = '#{MachineName}-#{OSVersion}-#{UserName}'"; - var result = evaluator.Evaluate(script); - var expected = string.Format("{0}-{1}-{2}", Environment.MachineName, Environment.OSVersion, Environment.UserName); - Assert.AreEqual(expected, result, "Unexpected computation result"); - */ - } - - #endregion - - - #region Convert inside Container - [Test] - public void SimpleStringHandlingInContainer () { - var script = "='Sharpdevelop' + ' is great'"; - - collection[0].Text = script; - var exportContainer = new ExportContainer(); - exportContainer.ExportedItems.Add(collection[0]); - expressionVisitor.Visit(exportContainer); - - var resultColumn = (ExportText)exportContainer.ExportedItems[0]; - Assert.That(resultColumn.Text,Is.EqualTo("Sharpdevelop is great")); - } - - #endregion - - #region System.Math - - [Test] - 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[0].Text = script; - expressionVisitor.Visit(collection[0]); - var res = Convert.ToDouble(collection[0].Text); - Assert.That(collection[0].Text,Is.EqualTo("11")); - } - #endregion - - - #region Parameters - - [Test] - public void CanConcatParameter () { - - var parameters = new ParameterCollection(); - parameters.Add(new BasicParameter() { - ParameterName = "param1", - ParameterValue = "SharpDevelop" - } - ); - - parameters.Add(new BasicParameter() { - ParameterName = "param2", - ParameterValue = " is " - } - ); - parameters.Add(new BasicParameter() { - ParameterName = "param3", - ParameterValue = "great" - } - ); - - var reportSettings = CreateReportSettings(parameters); - var visitor = new ExpressionVisitor(reportSettings); - - var script = "=Parameters!param1 + Parameters!param2 + Parameters!param3"; - collection[0].Text = script; - visitor.Visit(collection[0]); - Assert.That (collection[0].Text,Is.EqualTo("SharpDevelop is great")); - } - - - #endregion - - #region Fields - - [Test] - public void fields() { - var script = "=Fields!myfield"; - collection[0].Text = script; - collection.Add(new ExportText() - { - Text = "hi from Field", - Name = "myfield" - }); - - var visitor = new ExpressionVisitor(new ReportSettings()); - var exportContainer = new ExportContainer(); - exportContainer.ExportedItems.Add(collection[0]); - exportContainer.ExportedItems.Add(collection[1]); - visitor.Visit(exportContainer); - Assert.That (collection[0].Text,Is.EqualTo("hi from Field")); - } - #endregion - ReportSettings CreateReportSettings(ParameterCollection parameters) - { - var reportSettings = new ReportSettings(); - reportSettings.ParameterCollection.AddRange(parameters); - return reportSettings; - } - - - [SetUp] - public void CreateExportlist() { - collection = new Collection(); - collection.Add(new ExportText() - { - Text = "myExporttextColumn" - }); - } - - [TestFixtureSetUp] - public void Setup() { - expressionVisitor = new ExpressionVisitor(new ReportSettings()); - } - - } -} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/FieldsFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/FieldsFixture.cs new file mode 100644 index 0000000000..0fe065a59c --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/FieldsFixture.cs @@ -0,0 +1,59 @@ +// 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.Collections.ObjectModel; +using ICSharpCode.Reporting.Exporter.Visitors; +using ICSharpCode.Reporting.Items; +using ICSharpCode.Reporting.PageBuilder.ExportColumns; +using NUnit.Framework; + +namespace ICSharpCode.Reporting.Test.Expressions.InterationTests +{ + [TestFixture] + public class FieldsFixture + { + Collection collection; + ExpressionVisitor expressionVisitor; + + + [Test] + public void FieldsInContainer() { + var script = "=Fields!myfield1 + Fields!myfield2"; + collection[0].Text = script; + collection.Add(new ExportText() + { + Text = "Sharpdevelop", + Name = "myfield1" + }); + collection.Add(new ExportText() + { + Text = " is great", + Name = "myfield2" + }); + var visitor = new ExpressionVisitor(new ReportSettings()); + var exportContainer = new ExportContainer(); + exportContainer.ExportedItems.Add(collection[0]); + exportContainer.ExportedItems.Add(collection[1]); + exportContainer.ExportedItems.Add(collection[2]); + visitor.Visit(exportContainer); + Assert.That (collection[0].Text,Is.EqualTo("Sharpdevelop is great")); + } + + + [SetUp] + public void CreateExportlist() { + collection = new Collection(); + collection.Add(new ExportText() + { + Text = "myExporttextColumn" + }); + } + + [TestFixtureSetUp] + public void Setup() { + expressionVisitor = new ExpressionVisitor(new ReportSettings()); + } + + + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/ParametersFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/ParametersFixture.cs new file mode 100644 index 0000000000..24872ca575 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/ParametersFixture.cs @@ -0,0 +1,73 @@ +// 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.Collections.ObjectModel; +using ICSharpCode.Reporting.BaseClasses; +using ICSharpCode.Reporting.Exporter.Visitors; +using ICSharpCode.Reporting.Items; +using ICSharpCode.Reporting.PageBuilder.ExportColumns; +using NUnit.Framework; + +namespace ICSharpCode.Reporting.Test.Expressions.InterationTests +{ + [TestFixture] + public class ParametersFixture + { + Collection collection; + ExpressionVisitor expressionVisitor; + + + [Test] + public void CanConcatParameter () { + + var parameters = new ParameterCollection(); + parameters.Add(new BasicParameter() { + ParameterName = "param1", + ParameterValue = "SharpDevelop" + } + ); + + parameters.Add(new BasicParameter() { + ParameterName = "param2", + ParameterValue = " is " + } + ); + parameters.Add(new BasicParameter() { + ParameterName = "param3", + ParameterValue = "great" + } + ); + + var reportSettings = CreateReportSettings(parameters); + var visitor = new ExpressionVisitor(reportSettings); + + var script = "=Parameters!param1 + Parameters!param2 + Parameters!param3"; + collection[0].Text = script; + visitor.Visit(collection[0]); + Assert.That (collection[0].Text,Is.EqualTo("SharpDevelop is great")); + } + + + ReportSettings CreateReportSettings(ParameterCollection parameters) + { + var reportSettings = new ReportSettings(); + reportSettings.ParameterCollection.AddRange(parameters); + return reportSettings; + } + + + [SetUp] + public void CreateExportlist() { + collection = new Collection(); + collection.Add(new ExportText() + { + Text = "myExporttextColumn" + }); + } + + [TestFixtureSetUp] + public void Setup() { + expressionVisitor = new ExpressionVisitor(new ReportSettings()); + } + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/StandardTests.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/StandardTests.cs new file mode 100644 index 0000000000..6980d80cac --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/StandardTests.cs @@ -0,0 +1,93 @@ +// 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.Collections.ObjectModel; +using ICSharpCode.Reporting.BaseClasses; +using ICSharpCode.Reporting.Exporter.Visitors; +using ICSharpCode.Reporting.Items; +using ICSharpCode.Reporting.PageBuilder.ExportColumns; +using NUnit.Framework; + +namespace ICSharpCode.Reporting.Test.Expressions.InterationTests { + + [TestFixture] + public class StandardTests + { + Collection collection; + ExpressionVisitor expressionVisitor; + + [Test] + public void ExpressionMustStartWithEqualChar() + { + collection[0].Text = "myText"; + var result = collection[0].Text; + expressionVisitor.Visit(collection[0]); + Assert.That(result,Is.EqualTo(collection[0].Text)); + } + + + [Test] + public void ReportSyntaxError() { + collection[0].Text = "= myText"; + expressionVisitor.Visit(collection[0]); + } + + + + [Test] + public void SimpleStringHandling () { + var script = "='Sharpdevelop' + ' is great'"; + collection[0].Text = script; + expressionVisitor.Visit(collection[0]); + Assert.That(collection[0].Text,Is.EqualTo("Sharpdevelop is great")); + } + + + #region Convert inside Container + [Test] + public void SimpleStringHandlingInContainer () { + var script = "='Sharpdevelop' + ' is great'"; + + collection[0].Text = script; + var exportContainer = new ExportContainer(); + exportContainer.ExportedItems.Add(collection[0]); + expressionVisitor.Visit(exportContainer); + + var resultColumn = (ExportText)exportContainer.ExportedItems[0]; + Assert.That(resultColumn.Text,Is.EqualTo("Sharpdevelop is great")); + } + + #endregion + + + #region System.Math + + [Test] + 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[0].Text = script; + expressionVisitor.Visit(collection[0]); + var res = Convert.ToDouble(collection[0].Text); + Assert.That(collection[0].Text,Is.EqualTo("11")); + } + #endregion + + + [SetUp] + public void CreateExportlist() { + collection = new Collection(); + collection.Add(new ExportText() + { + Text = "myExporttextColumn" + }); + } + + + [TestFixtureSetUp] + public void Setup() { + expressionVisitor = new ExpressionVisitor(new ReportSettings()); + } + + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/ParametersHandlingFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/ParametersHandlingFixture.cs index 5b4248a9a5..4f48c42d3a 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/ParametersHandlingFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/ParametersHandlingFixture.cs @@ -92,7 +92,6 @@ namespace ICSharpCode.Reporting.Test.Expressions { var reportSettings = new ReportSettings(); reportSettings.ParameterCollection.AddRange(parameters); -// evaluator.App.Globals.Add("ReportSettings", reportSettings); evaluator.AddReportSettings(reportSettings); }