Example #1
0
        public void T003_Defect_1467629_Debugging_InlineCondition_With_Multiple_Return_Types()
        {
            Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();
            string      src = @"import(""ProtoGeometry.dll"");
import(""DSCoreNodes.dll"");
class FixitySymbol // this class is implicitly extended from var 
{
    Origin : Point; // define the class properties.. 
    Size : double;
    IsFixed : bool;
    Symbol : var[]..[]; //defined 'by composition', by one or more Solids 
    constructor FromOriginSize(origin : Point, size : double, isFixed : bool) //example constructor 
    {
        Origin = origin; // by convention properties of the class (with uppercase names) 
        Size = size; // are populated from the corresponding arguments (with lowercase names) 
        IsFixed = isFixed;
        localWCS = CoordinateSystem.WCS;
        Symbol = isFixed ? // using an in-line conditional
            Cuboid.ByLengths(CoordinateSystem.ByOriginVectors(Origin, // if true 
            Vector.ByCoordinates(1,0,0), Vector.ByCoordinates(0,1,0)), Size, Size, Size) : { Sphere.ByCenterPointRadius(Origin, Size * 0.25),
            Cone.ByCenterLineRadius(Line.ByStartPointDirectionLength(Origin, Vector.ByCoordinates(0,0,1), -Size), Size * 0.01, Size * 0.5) };
    }
    def Move : FixitySymbol(x : double, y : double, z : double) // an instance method 
    {
        return = FixitySymbol.FromOriginSize(this.Origin.Translate(x, y, z), this.Size, this.IsFixed); // note: the use of 'this' key word to refer to the instance 
    }
    
}
origin1 = Point.ByCoordinates(5, 5, 0); // define some appropriate input arguments 
origin2 = Point.ByCoordinates(0..10..5, 10, 0); // including a collection of points 
firstFixitySymbol = FixitySymbol.FromOriginSize(origin1, 2, true); // initially constructed 
firstFixitySymbol = firstFixitySymbol.Move(0, -4, 0); // modified by the instance method";
            WatchTestFx fx  = new WatchTestFx(); fx.CompareRunAndWatchResults(null, src, map);
        }
Example #2
0
        public void T002_Defect_1467629_Debugging_InlineCondition_With_Multiple_Return_Types()
        {
            Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();
            string      src = @"class B
{
    b = 0;
    constructor B(xx)
    {
        b = xx;
    }
}
class A  
{
    x : var[]..[];
    constructor A(a : int) //example constructor 
    {
        x = a == 1 ? B.B(1) : { B.B(0), B.B(2) }; // using an in-line conditional
            
    }   
}
c = 2;
aa = A.A(c);
c = 1;";
            WatchTestFx fx  = new WatchTestFx(); fx.CompareRunAndWatchResults(null, src, map);
        }
Example #3
0
        /// <summary>
        /// Generates a list of variables to watch. Runs the code and verifies the results against the generated watch list
        /// Verifies the results against a list
        /// </summary>
        /// <param name="code"></param>
        /// <param name="verification"></param>
        private void RunDebugWatch(string code)
        {
            Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();

            WatchTestFx.GeneratePrintStatements(code, ref map);
            WatchTestFx fx = new WatchTestFx();

            fx.CompareRunAndWatchResults(null, code, map);
        }
Example #4
0
        public void T003_Defect_1467629_Debugging_InlineCondition_With_Multiple_Return_Types()
        {
            Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();

            String filePath = @"..\..\..\Scripts\TD\DebugTests\T003_Defect_1467629_Debugging_InlineCondition_With_Multiple_Return_Types.ds";

            StreamReader file = new StreamReader(filePath);

            WatchTestFx.GeneratePrintStatements(file, ref map);

            file = new StreamReader(filePath);

            String src = file.ReadToEnd();

            file.Close();

            WatchTestFx fx = new WatchTestFx(); fx.CompareRunAndWatchResults(Path.GetFullPath(filePath), src, map);
        }
Example #5
0
        public void T003_Defect_1467629_Debugging_InlineCondition_With_Multiple_Return_Types()
        {
            Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();
            string      src = @"import(""ProtoGeometry.dll"");
import(""Math.dll"");
class FixitySymbol // this class is implicitly extended from var 
{
    Origin : Point; // define the class properties.. 
    Size : double;
    IsFixed : bool;
    Symbol : var[]..[]; //defined 'by composition', by one or more Solids 
    constructor FromOriginSize(origin : Point, size : double, isFixed : bool) //example constructor 
    {
        Origin = origin; // by convention properties of the class (with uppercase names) 
        Size = size; // are populated from the corresponding arguments (with lowercase names) 
        IsFixed = isFixed;
        localWCS = CoordinateSystem.WCS;
        Symbol = isFixed ? // using an in-line conditional
            Cuboid.ByLengths(CoordinateSystem.ByOriginVectors(Origin, // if true 
            localWCS.XAxis, localWCS.YAxis), Size, Size, Size) : { Sphere.ByCenterPointRadius(Origin, Size * 0.25),
            Cone.ByCenterLineRadius(Line.ByStartPointDirectionLength(Origin, localWCS.ZAxis, -Size), Size * 0.01, Size * 0.5) };
    }
    def Move : FixitySymbol(x : double, y : double, z : double) // an instance method 
    {
        return = FixitySymbol.FromOriginSize(this.Origin.Translate(x, y, z), this.Size, this.IsFixed); // note: the use of 'this' key word to refer to the instance 
    }
    // in general instances of DesignScript class are immutable, and cannot be changed 
    // to give the illusion of change, this instance method actually calls a constructor 
    // and creates a new instance, but using some of the properties of the previous instance 
    def SetColor(color : Color)
    {
        this.Symbol = this.Symbol.SetColor(color); // call SetColor on constituent geometric properties 
        return = null;
    }
}
origin1 = Point.ByCoordinates(5, 5, 0); // define some appropriate input arguments 
origin2 = Point.ByCoordinates(0..10..5, 10, 0); // including a collection of points 
firstFixitySymbol = FixitySymbol.FromOriginSize(origin1, 2, true); // initially constructed 
firstFixitySymbol.SetColor(Color.Cyan); // set color 
firstFixitySymbol = firstFixitySymbol.Move(0, -4, 0); // modified by the instance method";
            WatchTestFx fx  = new WatchTestFx(); fx.CompareRunAndWatchResults(null, src, map);
        }
        public ExecutionMirror RunScriptFile(string directory, string filename)
        {
            string currentFile = filename;
            string errorString = "";

            if (testImport)
            {
                currentFile = Path.GetFileName(filename);
                string fileToRun  = Path.GetFileNameWithoutExtension(currentFile) + "_Import.ds";
                string importCode = string.Format("import(\"{0}\");", currentFile);
                directory = Path.Combine(directory, filename);
                directory = Path.GetDirectoryName(directory) + @"\";
                createDSFile(fileToRun, directory, importCode);
                errorString = "tested as import file";
            }


            else if (testDebug)
            {
                Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();
                string     fname = Path.Combine(directory, filename);
                TextReader file  = new StreamReader(fname);
                WatchTestFx.GeneratePrintStatements(file, ref map);
                file = new StreamReader(fname);
                String src = file.ReadToEnd();
                file.Close();

                WatchTestFx fx = new WatchTestFx();
                testCore = fx.TestCore;

                fx.CompareRunAndWatchResults(Path.GetFullPath(filename), src, map);
                testMirror = fx.Mirror;

                return(testMirror);
            }

            string dsFullPathName = directory + currentFile;

            return(RunScript(dsFullPathName, errorString));
        }
Example #7
0
        /// <summary>
        /// Method to run an inline Ds script.
        /// </summary>
        /// <param name="sourceCode">The String contains the ds codes</param>
        /// <returns></returns>
        public virtual ExecutionMirror RunScriptSource(string sourceCode, string errorstring = "", string includePath = "")
        {
            sourceCode = sourceCode.Insert(0, "import(\"Builtin.dll\");");

            if (testImport)
            {
                Guid g;
                g = Guid.NewGuid();

                StackTrace trace  = new StackTrace();
                int        caller = 2;

                string tempPath  = System.IO.Path.GetTempPath();
                string import    = @"testImport\";
                string importDir = Path.Combine(tempPath, import);

                if (!Directory.Exists(importDir))
                {
                    System.IO.Directory.CreateDirectory(importDir);
                }


                string importFileName = (g.ToString() + ".ds");
                createDSFile(importFileName, importDir, sourceCode);

                return(testMirror = RunScriptFile(importDir, importFileName));
            }
            else if (testDebug)
            {
                Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();
                if (!String.IsNullOrEmpty(includePath))
                {
                    if (System.IO.Directory.Exists(includePath))
                    {
                        testCore.Options.IncludeDirectories.Add(includePath);
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Path: {0} does not exist.", includePath));
                    }
                }
                StringReader file = new StringReader(sourceCode);
                WatchTestFx.GeneratePrintStatements(file, ref map);

                WatchTestFx fx = new WatchTestFx();
                testCore = fx.TestCore;
                fx.CompareRunAndWatchResults("", sourceCode, map);
                testMirror = fx.Mirror;

                return(testMirror);
            }
            else
            {
                SetupTestCore();
                if (!String.IsNullOrEmpty(includePath))
                {
                    if (System.IO.Directory.Exists(includePath))
                    {
                        testCore.Options.IncludeDirectories.Add(includePath);
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Path: {0} does not exist.", includePath));
                    }
                }
                testRuntimeCore = runner.Execute(sourceCode, testCore);
                testMirror      = testRuntimeCore.Mirror;

                if (dumpDS)
                {
                    String fileName   = TestContext.CurrentContext.Test.Name + ".ds";
                    String folderName = TestContext.CurrentContext.Test.FullName;

                    string[] substrings = folderName.Split('.');

                    string path = "..\\..\\..\\test\\core\\dsevaluation\\DSFiles\\";
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }

                    createDSFile(fileName, path, sourceCode);
                }

                SetErrorMessage(errorstring);
                return(testMirror);
            }
        }
        /// <summary>
        /// Method to run an inline Ds script.
        /// </summary>
        /// <param name="sourceCode">The String contains the ds codes</param>
        /// <returns></returns>
        public ExecutionMirror RunScriptSource(string sourceCode, string errorstring = "", string includePath = "")
        {
            if (testImport)
            {
                Guid g;
                g = Guid.NewGuid();

                StackTrace trace      = new StackTrace();
                int        caller     = 2;
                StackFrame frame      = trace.GetFrame(caller);
                string     callerName = frame.GetMethod().Name;

                string tempPath  = System.IO.Path.GetTempPath();
                string import    = @"testImport\";
                string importDir = Path.Combine(tempPath, import);

                if (!Directory.Exists(importDir))
                {
                    System.IO.Directory.CreateDirectory(importDir);
                }


                string importFileName = (g.ToString() + ".ds");
                createDSFile(importFileName, importDir, sourceCode);

                return(testMirror = RunScriptFile(importDir, importFileName));
            }
            else if (testDebug)
            {
                Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();
                if (!String.IsNullOrEmpty(includePath))
                {
                    if (System.IO.Directory.Exists(includePath))
                    {
                        testCore.Options.IncludeDirectories.Add(includePath);
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Path: {0} does not exist.", includePath));
                    }
                }

                StringReader file = new StringReader(sourceCode);
                WatchTestFx.GeneratePrintStatements(file, ref map);

                WatchTestFx fx = new WatchTestFx();
                testCore = fx.TestCore;
                fx.CompareRunAndWatchResults("", sourceCode, map);
                testMirror = fx.Mirror;

                return(testMirror);
            }
            else
            {
                var testCore = SetupTestCore();
                if (!String.IsNullOrEmpty(includePath))
                {
                    if (System.IO.Directory.Exists(includePath))
                    {
                        testCore.Options.IncludeDirectories.Add(includePath);
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Path: {0} does not exist.", includePath));
                    }
                }
                testMirror = runner.Execute(sourceCode, testCore, out compileState);
                SetErrorMessage(errorstring);
                return(testMirror);
            }
        }