////////////////////////////////////////////////////////////////////////////// // Project: Ob51 // License: Apache License, Version 2.0; for details see LICENSE file // Copyright: see NOTICE file // // Last file commit: $Revision: 92 $ Made by: $Author: command0 $ ////////////////////////////////////////////////////////////////////////////// using System; using NUnit.Framework; using ProgramNode = Ob51.Compiler.InternalTree.ProgramNode; /// /// A class that provides simple forms for assertions commonly used in this /// test DLL. /// internal static class ProgramNodeAssert { private static string MakeName(ProgramNode node) { return node.GetType().ToString() + " " + node.Name; } internal static void ChildrenCountEquals(int expected, ProgramNode node) { Assert.AreEqual(expected, node.ChildrenCount, MakeName(node) + " node has wrong number of children"); } internal static void NameEquals(string expected, ProgramNode node) { Assert.AreEqual(expected, node.Name, MakeName(node) + " node has wrong Name property value"); } internal static void TypeEquals(int expected, ProgramNode node) { Assert.AreEqual(expected, node.Type, MakeName(node) + " node has wrong Type property value"); } internal static void PropertiesEqual(int ChildrenCount, int Type, string Name, ProgramNode node) { NameEquals(Name, node); TypeEquals(Type, node); ChildrenCountEquals(ChildrenCount, node); } internal static void SameChildByNameAndIndex(int index, string name, ProgramNode father) { Assert.AreSame(father[index], father[name], MakeName(father) + " node children with index " + index + " and name " + name + " are not same"); } /// /// Checks whether the child number of node /// can be casted to type. /// If it can, the result of casting is returned. Otherwise an exception is thrown. /// internal static T CastChildToType(ProgramNode father, int childNumber) where T : ProgramNode { Assert.IsInstanceOfType(typeof(T), father[childNumber], childNumber.ToString() + " son of " + father.GetType().ToString()); return (T)father[childNumber]; } }