private static void CheckGetAntExpressions(IList <string> actual, params string[] expected) { Assert.IsNotNull(actual); Assert.IsTrue(ArrayUtils.AreEqual( expected, new List <string>(actual).ToArray())); }
/// <summary> /// Returns a value for the logical inequality operator node. /// </summary> /// <param name="context">Context to evaluate expressions against.</param> /// <param name="evalContext">Current expression evaluation context.</param> /// <returns>Node's value.</returns> protected override object Get(object context, EvaluationContext evalContext) { object leftVal = GetLeftValue(context, evalContext); object rightVal = GetRightValue(context, evalContext); if (leftVal == null) { return(rightVal != null); } else if (rightVal == null) { return(true); } else if (leftVal.GetType() == rightVal.GetType()) { if (leftVal is Array) { return(!ArrayUtils.AreEqual(leftVal as Array, rightVal as Array)); } else { return(!leftVal.Equals(rightVal)); } } else { return(CompareUtils.Compare(leftVal, rightVal) != 0); } }
/// <summary> /// Returns a value for the logical equality operator node. /// </summary> /// <param name="context">Context to evaluate expressions against.</param> /// <param name="evalContext">Current expression evaluation context.</param> /// <returns>Node's value.</returns> protected override object Get(object context, EvaluationContext evalContext) { var lhs = GetLeftValue(context, evalContext); var rhs = GetRightValue(context, evalContext); if (lhs == null) { return(rhs == null); } if (rhs == null) { return(false); } if (lhs.GetType() == rhs.GetType()) { if (lhs is Array) { return(ArrayUtils.AreEqual(lhs as Array, rhs as Array)); } return(lhs.Equals(rhs)); } if (lhs.GetType().IsEnum&& rhs is string) { return(lhs.Equals(Enum.Parse(lhs.GetType(), (string)rhs))); } if (rhs.GetType().IsEnum&& lhs is string) { return(rhs.Equals(Enum.Parse(rhs.GetType(), (string)lhs))); } return(CompareUtils.Compare(lhs, rhs) == 0); }
public void GetAntExpressionsWithEmptyString() { IList <string> actual = StringUtils.GetAntExpressions(String.Empty); Assert.IsNotNull(actual); string[] expected = new string[] {}; Assert.IsTrue(ArrayUtils.AreEqual(expected, new List <string>(actual).ToArray())); }
public void GetAntExpressionsWithAStringThatDoesntHaveAnyExpressions() { IList <string> actual = StringUtils.GetAntExpressions("I could really go a cup of tea right now... in fact I think I'll go get one."); Assert.IsNotNull(actual); string[] expected = new string[] {}; Assert.IsTrue(ArrayUtils.AreEqual(expected, new List <string>(actual).ToArray())); }
public void AreEqual() { object [] one = new string [] { "Foo", "Bar", "Baz" }; object [] two = new string [] { "Foo", "Bar", "Baz" }; Assert.IsTrue(ArrayUtils.AreEqual(one, two)); object [] three = new string [] { "Foo", "Ben", "Baz" }; Assert.IsFalse(ArrayUtils.AreEqual(one, three)); }
public void AreEqualWithBadArguments() { Assert.IsTrue(ArrayUtils.AreEqual(null, null)); object [] one = new string [] { "Foo", "Bar", "Baz" }; object [] two = null; Assert.IsFalse(ArrayUtils.AreEqual(one, two)); object [] three = new string [] { "Foo", "Bar" }; Assert.IsFalse(ArrayUtils.AreEqual(one, three)); }
public void ConvertFromPreservesExtraneousWhitespace() { object[] expected = new object[] { "1 ", " Foo ", " 3" }; StringArrayConverter vrt = new StringArrayConverter(); object actual = vrt.ConvertFrom("1 , Foo , 3"); Assert.IsNotNull(actual); Assert.AreEqual(typeof(string[]), actual.GetType()); Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual), "Individual array elements not correctly converted (check the whitespace?)."); }
void VerifyHorzLine(List <object> drawActions, ref int position, int xLeft, int xRight, int y, int dyHeight, int[] rgdx, int dxStart) { var action = drawActions[position++] as MockGraphics.DrawHorzLineAction; Assert.That(action, Is.Not.Null); Assert.That(action.Left, Is.EqualTo(xLeft)); Assert.That(action.Right, Is.EqualTo(xRight)); Assert.That(action.Y, Is.EqualTo(y)); Assert.That(action.Height, Is.EqualTo(dyHeight)); Assert.IsTrue(ArrayUtils.AreEqual(action.Rgdx, rgdx)); Assert.That(action.DxStart, Is.EqualTo(dxStart)); }
public void ConvertFrom() { object[] expected = new object[] { "1", "Foo", "3" }; StringArrayConverter vrt = new StringArrayConverter(); object actual = vrt.ConvertFrom("1,Foo,3"); Assert.IsNotNull(actual); Assert.AreEqual(typeof(string[]), actual.GetType()); Assert.AreEqual(3, ((string[])actual).Length, "Wrong number of elements in the resulting array."); Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual), "Individual array elements not correctly converted."); }
public void NullingTheListSeparatorMakesItRevertToTheDefault() { object[] expected = new object[] { "1", "Foo", "3" }; StringArrayConverter vrt = new StringArrayConverter(); vrt.ListSeparator = null; object actual = vrt.ConvertFrom("1,Foo,3"); Assert.IsNotNull(actual); Assert.AreEqual(typeof(string[]), actual.GetType()); Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual), "Individual array elements not correctly converted."); }
public void CustomListSeparator() { object[] expected = new object[] { "1", "Foo", "3" }; StringArrayConverter vrt = new StringArrayConverter(); const string customSeparator = "#"; vrt.ListSeparator = customSeparator; object actual = vrt.ConvertFrom(string.Format("1{0}Foo{0}3", customSeparator)); Assert.IsNotNull(actual); Assert.AreEqual(typeof(string[]), actual.GetType()); Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual), "Individual array elements not correctly converted."); }
public void SortCtorsReallyIsGreedy() { BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; Type foolType = typeof(Fool); ConstructorInfo[] ctors = foolType.GetConstructors(flags); AutowireUtils.SortConstructors(ctors); ConstructorInfo[] expected = new ConstructorInfo[] { foolType.GetConstructor(new Type[] { typeof(string), typeof(int), typeof(Double), typeof(Fool) }), foolType.GetConstructor(new Type[] { typeof(string), typeof(int) }), foolType.GetConstructor(new Type[] { typeof(string) }), foolType.GetConstructor(Type.EmptyTypes), }; Assert.IsTrue(ArrayUtils.AreEqual(expected, ctors), "AutowireUtils.SortConstructors() did not put the greedy public ctors first."); }
public PAKFile(string filename) { FormattedReader pak = new FormattedReader(filename); while (true) { var sig = pak.Read <Signature>(); if (ArrayUtils.AreEqual(sig.signature, stringFileHeader2)) { var header = pak.Read <File>(); if (version == 0) { version = detectVersion(header.data, header.uncompressedSize, header.crc, header.compressionMethod); if (version == 0) { throw new Exception("Unknown AION version!"); } } files[header.Filename.ToLower()] = header; Console.WriteLine("File: {0} Compression: {1}", header.Filename, header.compressionMethod); } else if (ArrayUtils.AreEqual(sig.signature, stringCentralDir2)) { var header = pak.Read <Dir>(); Console.WriteLine("Dir: {0}", header.Filename); } else if (ArrayUtils.AreEqual(sig.signature, stringEndArchive2)) { var header = pak.Read <End>(); Console.WriteLine("End disknumber {0}", header.diskNumber); break; } else { throw new Exception("bad sig"); } } }
public void SplitTests() { string testString = " a,b,, c ,d\n:e "; string delim = ",\n"; string[] res; string[] res1 = new string[] { " a", "b", "", " c ", "d", ":e " }; string[] res2 = new string[] { " a", "b", " c ", "d", ":e " }; string[] res3 = new string[] { "a", "b", "", "c", "d", ":e" }; string[] res4 = new string[] { "a", "b", "c", "d", ":e" }; Assert.AreEqual(0, StringUtils.Split(null, null, false, false).Length); Assert.AreEqual(testString, StringUtils.Split(testString, null, false, false)[0]); Assert.IsTrue(ArrayUtils.AreEqual(res1, res = StringUtils.Split(testString, delim, false, false)), "Received '" + String.Join(",", res) + "'"); Assert.IsTrue(ArrayUtils.AreEqual(res2, res = StringUtils.Split(testString, delim, false, true)), "Received '" + String.Join(",", res) + "'"); Assert.IsTrue(ArrayUtils.AreEqual(res3, res = StringUtils.Split(testString, delim, true, false)), "Received '" + String.Join(",", res) + "'"); Assert.IsTrue(ArrayUtils.AreEqual(res4, res = StringUtils.Split(testString, delim, true, true)), "Received '" + String.Join(",", res) + "'"); Assert.IsTrue(ArrayUtils.AreEqual(new string[] { "one" }, res = StringUtils.Split("one", delim, true, true)), "Received '" + String.Join(",", res) + "'"); }
public void EnsureCultureListSeparatorIsIgnored() { CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture; try { CultureInfo frenchCulture = new CultureInfo("fr-FR"); Thread.CurrentThread.CurrentCulture = frenchCulture; object[] expected = new object[] { "1", "Foo", "3" }; StringArrayConverter vrt = new StringArrayConverter(); // France uses the ';' (semi-colon) to separate list items... object actual = vrt.ConvertFrom("1,Foo,3"); Assert.IsNotNull(actual); Assert.AreEqual(typeof(string[]), actual.GetType()); Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual), "Individual array elements not correctly converted."); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
/// <summary> /// Returns a value for the logical equality operator node. /// </summary> /// <param name="context">Context to evaluate expressions against.</param> /// <param name="evalContext">Current expression evaluation context.</param> /// <returns>Node's value.</returns> protected override object Get(object context, EvaluationContext evalContext) { object left = GetLeftValue(context, evalContext); object right = GetRightValue(context, evalContext); if (left == null) { return(right == null); } else if (right == null) { return(false); } else if (left.GetType() == right.GetType()) { if (left is Array) { return(ArrayUtils.AreEqual(left as Array, right as Array)); } else { return(left.Equals(right)); } } else if (left.GetType().IsEnum&& right is string) { return(left.Equals(Enum.Parse(left.GetType(), (string)right))); } else if (right.GetType().IsEnum&& left is string) { return(right.Equals(Enum.Parse(right.GetType(), (string)left))); } else { return(CompareUtils.Compare(left, right) == 0); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// A helper method for book merger tests- /// Verifies the contents of the given difference /// of type Missing/Added Section/SectionHead. /// </summary> /// <remarks>subDiffs are not verified here; test code should check those directly /// if relevant</remarks> /// <param name="diff">the given Difference</param> /// <param name="start">The verse ref start.</param> /// <param name="end">The verse ref end.</param> /// <param name="type">Type of the diff.</param> /// <param name="sectionsAdded">Sections that were added (this can be single one or an /// array of them; the code will be smart enough to figure out which and act accordingly)</param> /// <param name="paraDest">The destination paragraph</param> /// <param name="ichDest">The character index in the destination paragraph, /// where the added items could be inserted in the other book.</param> /// ------------------------------------------------------------------------------------ public static void VerifySectionDiff(Difference diff, BCVRef start, BCVRef end, DifferenceType type, object sectionsAdded, IScrTxtPara paraDest, int ichDest) { Assert.AreEqual(start, diff.RefStart); Assert.AreEqual(end, diff.RefEnd); Assert.AreEqual(type, diff.DiffType); switch (type) { case DifferenceType.SectionAddedToCurrent: case DifferenceType.SectionHeadAddedToCurrent: if (sectionsAdded is IScrSection) { Assert.AreEqual(1, diff.SectionsCurr.Count()); Assert.AreEqual(sectionsAdded, diff.SectionsCurr.First()); } else if (sectionsAdded is IScrSection[]) { Assert.IsTrue(ArrayUtils.AreEqual((IScrSection[])sectionsAdded, diff.SectionsCurr)); } else { Assert.Fail("Invalid parameter type"); } Assert.IsNull(diff.SectionsRev); Assert.AreEqual(null, diff.ParaCurr); Assert.AreEqual(0, diff.IchMinCurr); Assert.AreEqual(0, diff.IchLimCurr); Assert.AreEqual(paraDest, diff.ParaRev); Assert.AreEqual(ichDest, diff.IchMinRev); Assert.AreEqual(ichDest, diff.IchLimRev); Assert.IsNull(diff.StyleNameCurr); Assert.IsNull(diff.StyleNameRev); break; case DifferenceType.SectionMissingInCurrent: case DifferenceType.SectionHeadMissingInCurrent: if (sectionsAdded is IScrSection) { Assert.AreEqual(1, diff.SectionsRev.Count()); Assert.AreEqual(sectionsAdded, diff.SectionsRev.First()); } else if (sectionsAdded is IScrSection[]) { Assert.IsTrue(ArrayUtils.AreEqual((IScrSection[])sectionsAdded, diff.SectionsRev)); } else { Assert.Fail("Invalid parameter type"); } Assert.IsNull(diff.SectionsCurr); Assert.AreEqual(paraDest, diff.ParaCurr); Assert.AreEqual(ichDest, diff.IchMinCurr); Assert.AreEqual(ichDest, diff.IchLimCurr); Assert.AreEqual(null, diff.ParaRev); Assert.AreEqual(0, diff.IchMinRev); Assert.AreEqual(0, diff.IchLimRev); Assert.IsNull(diff.StyleNameCurr); Assert.IsNull(diff.StyleNameRev); break; default: Assert.Fail("test called wrong verify method or something"); break; } }