Пример #1
0
            public void It_will_set_the_child_scope_parent()
            {
                Scope scope = new Scope("fnord", 0, 0);
                Scope childScope = new Scope("The Child Scope", 0, 0);

                scope.AddChild(childScope);

                Assert.Equal(scope, childScope.Parent);
            }
Пример #2
0
        public void AddChild(Scope childScope)
        {
            if (childScope.Parent != null)
                throw new InvalidOperationException("The child scope already has a parent.");

            childScope.Parent = this;

            Children.Add(childScope);
        }
Пример #3
0
            public void It_will_add_the_child_scope_to_the_children_collection()
            {
                Scope scope = new Scope("fnord", 0, 0);
                Scope childScope = new Scope("The Child Scope", 0, 0);

                scope.AddChild(childScope);

                Assert.Contains(childScope, scope.Children);
            }
Пример #4
0
            public void It_will_throw_if_child_scope_already_has_parent()
            {
                Scope scope = new Scope("fnord", 0, 0);
                Scope existingParentScope = new Scope("The Parent Scope", 0, 0);
                Scope childScope = new Scope("The Child Scope", 0, 0);
                childScope.Parent = existingParentScope;

                Exception ex = Record.Exception(() => scope.AddChild(childScope));

                Assert.IsType<InvalidOperationException>(ex);
                Assert.Contains("The child scope already has a parent.", ex.Message);
            }
Пример #5
0
            public void It_will_set_the_name_and_index_and_length_and_children()
            {
                const string name = "The Scope Name";
                const int index = 435;
                const int length = 34;

                Scope scope = new Scope(name, index, length);

                Assert.Equal("The Scope Name", scope.Name);
                Assert.Equal(435, scope.Index);
                Assert.Equal(34, scope.Length);
                Assert.Null(scope.Parent);
                Assert.Empty(scope.Children);
            }
        private static void GetStyleInsertionsForCapturedStyle(Scope scope, ICollection<TextInsertion> styleInsertions)
        {
            styleInsertions.Add(new TextInsertion {
                Index = scope.Index,
                Scope = scope
            });

            foreach (Scope childScope in scope.Children)
                GetStyleInsertionsForCapturedStyle(childScope, styleInsertions);

            styleInsertions.Add(new TextInsertion {
                Index = scope.Index + scope.Length,
                Text = (Char)27 + "[0m" + (Char)27 + "[37;40m"
            });
        }
        private static void BuildSpanForCapturedStyle(Scope scope,
            IStyleSheet styleSheet,
            TextWriter writer)
        {
            string cssClassName = "";

            if (styleSheet.Styles.Contains(scope.Name))
            {
                Style style = styleSheet.Styles[scope.Name];

                cssClassName = style.CssClassName;
            }

            WriteElementStart("span", cssClassName, writer);
        }
        private static void BuildSpanForCapturedStyle(Scope scope,
                                                        IStyleSheet styleSheet,
                                                        TextWriter writer)
        {
            Color foreground = Color.Empty;
            Color background = Color.Empty;

            if (styleSheet.Styles.Contains(scope.Name))
            {
                Style style = styleSheet.Styles[scope.Name];

                foreground = style.Foreground;
                background = style.Background;
            }

            WriteElementStart("span", foreground, background, writer);
        }
        private static void AddScopeToNestedScopes(Scope scope,
                                                   ref Scope currentScope,
                                                   ICollection<Scope> capturedStyleTree)
        {
            if (scope.Index >= currentScope.Index && (scope.Index + scope.Length <= currentScope.Index + currentScope.Length))
            {
                currentScope.AddChild(scope);
                currentScope = scope;
            }
            else
            {
                currentScope = currentScope.Parent;

                if (currentScope != null)
                    AddScopeToNestedScopes(scope, ref currentScope, capturedStyleTree);
                else
                    capturedStyleTree.Add(scope);
            }
        }
        private static void BuildSpanForCapturedStyle(Scope scope,
            IStyleSheet styleSheet,
            TextWriter writer)
        {
            Color foreground = Color.Empty;
            Color background = Color.Empty;
            bool italic = false;
            bool bold = false;

            if (styleSheet.Styles.Contains(scope.Name))
            {
                Style style = styleSheet.Styles[scope.Name];

                foreground = style.Foreground;
                background = style.Background;
                italic = style.Italic;
                bold = style.Bold;
            }

            WriteElementStart(writer, "span", foreground, background, italic, bold);
        }
Пример #11
0
        private static void GetStyleInsertionsForCapturedStyle(Scope scope, ICollection<TextInsertion> styleInsertions)
        {
            styleInsertions.Add(new TextInsertion {
                                                      Index = scope.Index,
                                                      Scope = scope
                                                  });

            foreach (var childScope in scope.Children)
                GetStyleInsertionsForCapturedStyle(childScope, styleInsertions);

            styleInsertions.Add(new TextInsertion {
                                                      Index = scope.Index + scope.Length,
                                                      Text = "</span>"
                                                  });
        }