示例#1
0
        public void StatementRequiresOutputPort00()
        {
            Assert.Throws <ArgumentNullException>(() =>
            {
                // Null as argument will cause exception.
                CodeBlockUtils.DoesStatementRequireOutputPort(null, 0);
            });

            // Create a list of another empty list.
            var svs = new List <List <string> >()
            {
                new List <string>()
            };

            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                // -1 as index argument will cause exception.
                CodeBlockUtils.DoesStatementRequireOutputPort(svs, -1);
            });

            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                // Out-of-bound index argument will cause exception.
                CodeBlockUtils.DoesStatementRequireOutputPort(svs, 1);
            });
        }
示例#2
0
        public void StatementRequiresOutputPort02()
        {
            var svs = new List <List <string> >()
            {
                new List <string>()
                {
                    "Apple", "Orange"
                },

                new List <string>()
                {
                    "Watermelon", "Grape", "HoneyDew"
                },

                new List <string>()
                {
                    "Lemon", "Apple"
                }
            };

            // "Apple" is redefined on the last statement, no port for first statement.
            Assert.IsFalse(CodeBlockUtils.DoesStatementRequireOutputPort(svs, 0));

            // None of the variables on statement 1 is redefined, so show output port.
            Assert.IsTrue(CodeBlockUtils.DoesStatementRequireOutputPort(svs, 1));

            // The last line will display an output port as long as it defines variable.
            Assert.IsTrue(CodeBlockUtils.DoesStatementRequireOutputPort(svs, 2));
        }
示例#3
0
 public void GenerateInputPortData00()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         // Null as argument will cause exception.
         CodeBlockUtils.GenerateInputPortData(null);
     });
 }
示例#4
0
 public void GetStatementVariables00()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         // Null as argument will cause exception.
         CodeBlockUtils.GetStatementVariables(null, true);
     });
 }
示例#5
0
        public void GenerateInputPortData01()
        {
            // Empty list of input should return empty result.
            var unboundIdentifiers = new List <string>();
            var data = CodeBlockUtils.GenerateInputPortData(unboundIdentifiers);

            Assert.IsNotNull(data);
            Assert.AreEqual(0, data.Count());
        }
示例#6
0
        public void TestMapLogicalToVisualLineIndices01()
        {
            var code = "point = Point.ByCoordinates(1, 2, 3);";
            var maps = CodeBlockUtils.MapLogicalToVisualLineIndices(code);

            Assert.IsNotNull(maps);
            Assert.AreEqual(1, maps.Count());
            Assert.AreEqual(0, maps.ElementAt(0));
        }
示例#7
0
        public void TestMapLogicalToVisualLineIndices00()
        {
            var firstResult = CodeBlockUtils.MapLogicalToVisualLineIndices(null);

            Assert.IsNotNull(firstResult);
            Assert.AreEqual(0, firstResult.Count());

            var secondResult = CodeBlockUtils.MapLogicalToVisualLineIndices("");

            Assert.IsNotNull(secondResult);
            Assert.AreEqual(0, secondResult.Count());
        }
示例#8
0
        private void InitializeSyntaxHighlighter()
        {
            var stream = GetType().Assembly.GetManifestResourceStream(
                "Dynamo.UI.Resources." + Configurations.HighlightingFile);

            this.InnerTextEditor.SyntaxHighlighting = HighlightingLoader.Load(
                new XmlTextReader(stream), HighlightingManager.Instance);

            // Highlighting Digits
            var rules = this.InnerTextEditor.SyntaxHighlighting.MainRuleSet.Rules;

            rules.Add(CodeBlockUtils.CreateDigitRule());
        }
示例#9
0
        public void TestMapLogicalToVisualLineIndices04()
        {
            var code = "firstLine = Line.ByStartPointEndPoint(" +
                       "Point.ByCoordinatesinates(0, 0, 0), " +
                       "Point.ByCoordinatesinates(10, 20, 30));\n" +
                       "\n" +
                       "xCoordinates0 = 10;\n" +
                       "yCoordinates0 = 20;\n" +
                       "zCoordinates0 = 30;\n" +
                       "\n" +
                       "\n" +
                       "xCoordinates1 = 40;\n" +
                       "yCoordinates1 = 50;\n" +
                       "zCoordinates1 = 60;\n" +
                       "\n" +
                       "secondLine = Line.ByStartPointEndPoint(" +
                       "Point.ByCoordinatesinates(xCoordinates0, yCoordinates0, zCoordinates0), " +
                       "Point.ByCoordinatesinates(xCoordinates1, yCoordinates1, zCoordinates1));\n" +
                       "\n" +
                       "\n" +
                       "sp = firstLine.StartPoint;\n" +
                       "ep = firstLine.EndPoint;\n";

            var maps = CodeBlockUtils.MapLogicalToVisualLineIndices(code);

            Assert.IsNotNull(maps);
            Assert.AreEqual(17, maps.Count()); // Note the empty last line.
            Assert.AreEqual(0, maps.ElementAt(0));
            Assert.AreEqual(2, maps.ElementAt(1));
            Assert.AreEqual(3, maps.ElementAt(2));
            Assert.AreEqual(4, maps.ElementAt(3));
            Assert.AreEqual(5, maps.ElementAt(4));
            Assert.AreEqual(6, maps.ElementAt(5));
            Assert.AreEqual(7, maps.ElementAt(6));
            Assert.AreEqual(8, maps.ElementAt(7));
            Assert.AreEqual(9, maps.ElementAt(8));
            Assert.AreEqual(10, maps.ElementAt(9));
            Assert.AreEqual(11, maps.ElementAt(10));
            Assert.AreEqual(12, maps.ElementAt(11));
            Assert.AreEqual(15, maps.ElementAt(12));
            Assert.AreEqual(16, maps.ElementAt(13));
            Assert.AreEqual(17, maps.ElementAt(14));
            Assert.AreEqual(18, maps.ElementAt(15));
        }
示例#10
0
        public void TestFormatTextScenarios()
        {
            var before = "1;2;";
            var after  = CodeBlockUtils.FormatUserText(before);

            Assert.AreEqual("1;\n2;", after);

            before = "  \t\n  1;2;  \t\n   ";
            after  = CodeBlockUtils.FormatUserText(before);
            Assert.AreEqual("1;\n2;", after);

            before = "  a = 1;    b = 2;  \n  \n  ";
            after  = CodeBlockUtils.FormatUserText(before);
            Assert.AreEqual("a = 1;\n    b = 2;", after);

            before = "  a = 1;    \nb = 2;  \n  \n  ";
            after  = CodeBlockUtils.FormatUserText(before);
            Assert.AreEqual("a = 1;\nb = 2;", after);
        }
示例#11
0
        public void TestMapLogicalToVisualLineIndices03()
        {
            var code = "firstLine = Line.ByStartPointEndPoint(" +
                       "Point.ByCoordinates(0, 0, 0), " +
                       "Point.ByCoordinates(10, 20, 30));\n" +
                       "\n" +
                       "secondLine = Line.ByStartPointEndPoint(" +
                       "Point.ByCoordinates(10, 20, 30), " +
                       "Point.ByCoordinates(40, 50, 60));\n";

            var maps = CodeBlockUtils.MapLogicalToVisualLineIndices(code);

            Assert.IsNotNull(maps);
            Assert.AreEqual(4, maps.Count()); // Note the empty last line.
            Assert.AreEqual(0, maps.ElementAt(0));
            Assert.AreEqual(2, maps.ElementAt(1));
            Assert.AreEqual(3, maps.ElementAt(2));
            Assert.AreEqual(5, maps.ElementAt(3));
        }
示例#12
0
        private NormalizedSnapshotSpanCollection GetDimSpans(ITextSnapshot snapshot)
        {
            if (!FocusDimmer.IsOn)
            {
                SnapshotPoint pointZero = new SnapshotPoint(snapshot, 0);
                SnapshotSpan  spanZero  = new SnapshotSpan(pointZero, pointZero);
                return(new NormalizedSnapshotSpanCollection(new List <SnapshotSpan>()
                {
                    spanZero
                }));
            }

            List <SnapshotSpan> result = new List <SnapshotSpan>();

            SnapshotSpan caretBlockSpan = CodeBlockUtils.GetCaretBlockSpan(m_View, m_CaretPosition, m_TagAggregatorService);

            result.Add(new SnapshotSpan(new SnapshotPoint(snapshot, 0), caretBlockSpan.Start));
            result.Add(new SnapshotSpan(caretBlockSpan.End, new SnapshotPoint(snapshot, snapshot.Length)));

            return(new NormalizedSnapshotSpanCollection(result));
        }
示例#13
0
        public void TestSyntaxHighlightRuleForDigits()
        {
            string text = "{-2468.2342E+04, dfsgdfg34534, 34534.345345, 23423, -98.7, 0..10..2, -555};";

            var rule    = CodeBlockUtils.CreateDigitRule().Regex;
            var matches = rule.Matches(text);

            // Expected results (8):
            // -2468.2342E+04
            // 34534.345345
            // 23423
            // -98.7
            // 0
            // 10
            // 2
            // -555
            Assert.AreEqual(8, matches.Count);
            var actual = matches.Cast <Match>().Select(m => m.Value).ToArray();

            string[] expected = new string[] { "-2468.2342E+04", "34534.345345", "23423", "-98.7", "0", "10", "2", "-555" };
            Assert.IsTrue(expected.SequenceEqual(actual));
        }
示例#14
0
        public void GenerateInputPortData02()
        {
            var unboundIdentifiers = new List <string>();

            unboundIdentifiers.Add("ShortVarName");
            unboundIdentifiers.Add("LongerVariableNameThatWillGetTruncated");

            var data = CodeBlockUtils.GenerateInputPortData(unboundIdentifiers);

            Assert.IsNotNull(data);
            Assert.AreEqual(2, data.Count());

            var data0 = data.ElementAt(0);

            Assert.AreEqual(unboundIdentifiers[0], data0.NickName);
            Assert.AreEqual(unboundIdentifiers[0], data0.ToolTipString);

            var data1 = data.ElementAt(1);

            Assert.AreEqual("LongerVariableNameTha...", data1.NickName);
            Assert.AreEqual(unboundIdentifiers[1], data1.ToolTipString);
        }
示例#15
0
        public void TestSemiColonAddition()
        {
            string userText, compilableText;

            userText       = "a";
            compilableText = CodeBlockUtils.FormatUserText(userText);
            Assert.AreEqual("a;", compilableText);

            userText       = "\na\n\n\n";
            compilableText = CodeBlockUtils.FormatUserText(userText);
            Assert.AreEqual("a;", compilableText);

            userText       = "a = 1; \n\n b = foo( c,\nd\n,\ne)";
            compilableText = CodeBlockUtils.FormatUserText(userText);
            Assert.AreEqual("a = 1;\n\n b = foo( c,\nd\n,\ne);", compilableText);

            userText       = "      a = b-c;\nx = 1+3;\n   ";
            compilableText = CodeBlockUtils.FormatUserText(userText);
            Assert.AreEqual("a = b-c;\nx = 1+3;", compilableText);

            userText       = "\n   \n   \n    \n";
            compilableText = CodeBlockUtils.FormatUserText(userText);
            Assert.AreEqual("", compilableText);
        }
示例#16
0
        public void GetStatementVariables01()
        {
            // Create a statement of "Value = 1234".
            var leftNode    = new IdentifierNode("Value");
            var rightNode   = new IntNode(1234);
            var binExprNode = new BinaryExpressionNode(
                leftNode, rightNode, Operator.assign);

            var statements = new List <Statement>()
            {
                Statement.CreateInstance(binExprNode)
            };

            var vars = CodeBlockUtils.GetStatementVariables(statements, true);

            Assert.IsNotNull(vars);
            Assert.AreEqual(1, vars.Count());

            var variables = vars.ElementAt(0);

            Assert.IsNotNull(variables);
            Assert.AreEqual(1, variables.Count());
            Assert.AreEqual("Value", variables.ElementAt(0));
        }
示例#17
0
        public void StatementRequiresOutputPort01()
        {
            var svs = new List <List <string> >(); // An empty list should return false.

            Assert.IsFalse(CodeBlockUtils.DoesStatementRequireOutputPort(svs, 0));
        }