10 changed files with 283 additions and 110 deletions
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
// 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.Globalization; |
||||
using ICSharpCode.Reporting.Globals; |
||||
|
||||
namespace ICSharpCode.Reporting.Expressions |
||||
{ |
||||
/// <summary>
|
||||
/// Description of ExpressionHelper.
|
||||
/// </summary>
|
||||
class ExpressionHelper |
||||
{ |
||||
public ExpressionHelper() |
||||
{ |
||||
} |
||||
|
||||
public static string ExtractExpressionPart (string src) |
||||
{ |
||||
char v = Convert.ToChar("=",CultureInfo.CurrentCulture ); |
||||
return StringHelper.RightOf(src,v).Trim(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,139 @@
@@ -0,0 +1,139 @@
|
||||
// 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; |
||||
|
||||
namespace ICSharpCode.Reporting.Globals |
||||
{ |
||||
/// <summary>
|
||||
/// Description of StringHelper.
|
||||
/// </summary>
|
||||
class StringHelper |
||||
{ |
||||
/// <summary>
|
||||
/// Left of the first occurance of c
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="c"></param>
|
||||
/// <returns></returns>
|
||||
public static string LeftOf(string src, char c) |
||||
{ |
||||
int idx=src.IndexOf(c); |
||||
if (idx==-1) |
||||
{ |
||||
return src; |
||||
} |
||||
|
||||
return src.Substring(0, idx); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Left of the n'th occurance of c
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="c"></param>
|
||||
/// <param name="n"></param>
|
||||
/// <returns></returns>
|
||||
public static string LeftOf(string src, char c, int n) |
||||
{ |
||||
int idx=-1; |
||||
while (n != 0) |
||||
{ |
||||
idx=src.IndexOf(c, idx+1); |
||||
if (idx==-1) |
||||
{ |
||||
return src; |
||||
} |
||||
--n; |
||||
} |
||||
return src.Substring(0, idx); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Right of the first occurance of c
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="c"></param>
|
||||
/// <returns></returns>
|
||||
public static string RightOf(string src, char c) |
||||
{ |
||||
int idx=src.IndexOf(c); |
||||
if (idx==-1) |
||||
{ |
||||
return ""; |
||||
} |
||||
|
||||
return src.Substring(idx+1); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Right of the n'th occurance of c
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="c"></param>
|
||||
/// <returns></returns>
|
||||
public static string RightOf(string src, char c, int n) |
||||
{ |
||||
int idx=-1; |
||||
while (n != 0) |
||||
{ |
||||
idx=src.IndexOf(c, idx+1); |
||||
if (idx==-1) |
||||
{ |
||||
return ""; |
||||
} |
||||
--n; |
||||
} |
||||
|
||||
return src.Substring(idx+1); |
||||
} |
||||
|
||||
public static string LeftOfRightmostOf(string src, char c) |
||||
{ |
||||
int idx=src.LastIndexOf(c); |
||||
if (idx==-1) |
||||
{ |
||||
return src; |
||||
} |
||||
return src.Substring(0, idx); |
||||
} |
||||
|
||||
public static string RightOfRightmostOf(string src, char c) |
||||
{ |
||||
int idx=src.LastIndexOf(c); |
||||
if (idx==-1) |
||||
{ |
||||
return src; |
||||
} |
||||
return src.Substring(idx+1); |
||||
} |
||||
|
||||
public static string Between(string src, char start, char end) |
||||
{ |
||||
string res=String.Empty; |
||||
int idxStart=src.IndexOf(start); |
||||
if (idxStart != -1) |
||||
{ |
||||
++idxStart; |
||||
int idxEnd=src.IndexOf(end, idxStart); |
||||
if (idxEnd != -1) |
||||
{ |
||||
res=src.Substring(idxStart, idxEnd-idxStart); |
||||
} |
||||
} |
||||
return res; |
||||
} |
||||
|
||||
public static int Count(string src, char find) |
||||
{ |
||||
int ret=0; |
||||
foreach(char s in src) |
||||
{ |
||||
if (s==find) |
||||
{ |
||||
++ret; |
||||
} |
||||
} |
||||
return ret; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,99 @@
@@ -0,0 +1,99 @@
|
||||
// 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.PageBuilder.ExportColumns; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.Reporting.Test.Expressions |
||||
{ |
||||
[TestFixture] |
||||
public class IntegrationTests |
||||
{ |
||||
Collection<ExportText> collection; |
||||
ExpressionVisitor expressionVisitor; |
||||
|
||||
[Test] |
||||
public void ExpressionMustStartWithEqualChar() |
||||
{ |
||||
var result = collection[0]; |
||||
expressionVisitor.Visit(collection[0]); |
||||
Assert.That(result.Text,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); |
||||
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")); |
||||
} |
||||
|
||||
#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 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[1].Text = script; |
||||
expressionVisitor.Visit(collection[1]); |
||||
var res = Convert.ToDouble(collection[1].Text); |
||||
Assert.That(collection[1].Text,Is.EqualTo("11")); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
[SetUp] |
||||
public void CreateExportlist() { |
||||
collection = new Collection<ExportText>(); |
||||
collection.Add(new ExportText() |
||||
{ |
||||
Text = "myExporttextColumn" |
||||
}); |
||||
collection.Add(new ExportText() |
||||
{ |
||||
Text ="= 3 + 5" |
||||
|
||||
}); |
||||
|
||||
} |
||||
|
||||
[TestFixtureSetUp] |
||||
public void Setup() { |
||||
expressionVisitor = new ExpressionVisitor(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
Loading…
Reference in new issue