public void DefineInnerScope_InCombinedParentOfTwoInners_SetsRootScopeOnInner()
 {
     Scope root = new     Scope("0123456789");
     Scope parent = root.DefineInnerScope(5, 4);
     //5678
     Scope combinedParent = root.DefineInnerScope(5, 5);//5678+9
     Scope innerChild = root.DefineInnerScope(6, 2);//67
     Assert.AreEqual(combinedParent.InnerLeftScope, innerChild.ParentScope);
     Assert.AreEqual(combinedParent, combinedParent.InnerLeftScope.ParentScope);
     Assert.AreEqual(combinedParent, combinedParent.InnerRightScope.ParentScope);
 }
        public void DefineInnerScope_WithleftMiddleandRightScopesasInner()
        {
            Scope root = new Scope("012345");
            root.DefineInnerScope(3, 1);//012|3|45
            ScopeSplitter splitter = new ScopeSplitter();
            splitter.AutoSplit(root, 2, 3, true);//01|(2|3|4)|5

            Scope encapsulator = root.DefineInnerScope(2, 3);
            Assert.AreEqual("2", encapsulator.InnerLeftScope.Text);
            Assert.AreEqual("3", encapsulator.InnerMiddleScope.Text);
            Assert.AreEqual("4", encapsulator.InnerRightScope.Text);
        }
예제 #3
0
        public Scope Split(Scope root, SplitPoint splitPoint, bool isImplicit)
        {
            Scope inner          = root.FindInnerScope(splitPoint.StartIndex, 1);
            int   requiredLength = splitPoint.Length;

            if (requiredLength == inner.Length)
            {
                requiredLength -= 1;
            }
            Scope newScope = inner.DefineInnerScope(splitPoint.StartIndex, requiredLength);

            newScope.IsImplicit = isImplicit;
            return(newScope);
        }
예제 #4
0
 private Scope TryDefineScopeInInnerScope(int length, int startPosInParent)
 {
     if (innerMiddleScope != null && innerMiddleScope.EncapsulatesTextPart(startPosInParent, length))
     {
         return(innerMiddleScope.DefineInnerScope(startPosInParent, length));
     }
     if (innerLeftScope.EncapsulatesTextPart(startPosInParent, length))
     {
         return(innerLeftScope.DefineInnerScope(startPosInParent, length));
     }
     if (innerRightScope.EncapsulatesTextPart(startPosInParent, length))
     {
         return(innerRightScope.DefineInnerScope(startPosInParent, length));
     }
     return(null);
 }
예제 #5
0
        public void AutoScope(Scope root)
        {
            if (autoAdvisor == null)
            {
                return;
            }
            foreach (Suggestion possibility in autoAdvisor.possibleMatches)
            {
                Match match = Regex.Match(root.Text, possibility.RegexText);
                if (match.Success)
                {
                    Scope innerScope = root.FindInnerScope(match.Index, match.Length);

                    if (innerScope == null || innerScope.Length != match.Length)
                    {
                        List <SplitPoint> points = new ScopeSplitter().GetSplitPoints(root, match.Index, match.Length);
                        bool willNewScopeBeInsdeAScopeWithSuggestions = false;
                        if (points.Count > 0)
                        {
                            foreach (SplitPoint point in points)
                            {
                                Scope target = root.FindInnerScope(point.StartIndex, point.Length);
                                if (target != null && target.Suggestions.Count > 0)
                                {
                                    willNewScopeBeInsdeAScopeWithSuggestions = true;
                                    break;
                                }
                            }
                        }
                        if (!willNewScopeBeInsdeAScopeWithSuggestions)
                        {
                            innerScope = root.DefineInnerScope(match.Index, match.Length);
                        }
                    }
                    if (innerScope != null)
                    {
                        innerScope.Suggestions.Add(possibility);
                        innerScope.IsExplicit = true;
                    }
                }
            }
        }
 public void SetInnerScope_OnLastCharInInnerScope_InnerInnerMiddleScopeIsNull()
 {
     scope = new Scope("a text b");
     scope.DefineInnerScope(1, 6);//' text '
     scope.DefineInnerScope(6, 1);//' ' in the end of inner middle scope
     Assert.IsNull(scope.InnerMiddleScope.InnerMiddleScope);
 }
 public void SetInnerScope_OnInnerScope_WorksFromParent()
 {
     scope = new Scope("abcde");
     scope.DefineInnerScope(1, 3);//bcd
     scope.DefineInnerScope(2, 1);//'c'
     Assert.AreEqual("c", scope.InnerMiddleScope.InnerMiddleScope.Text);
 }
 public void SetInnerScope_WithScopeInTheEnd_DoesntSetInnerMiddleScope()
 {
     scope = new Scope("abc");
     Scope newone = scope.DefineInnerScope(2, 1);
     Assert.IsNull(scope.InnerMiddleScope);
 }
 public void SetInnerScope_EncapsulatingInnerScopes_CreatesOuterScopeWithInnerScopes2()
 {
     Scope root = new Scope("abcd");
     root.DefineInnerScope(1, 1);//b
     root.DefineInnerScope(2, 1);//'c' as inner of 'cd'
     Scope encapsulating = root.DefineInnerScope(1, 3);//'bcd'
     Assert.AreEqual("bcd", encapsulating.Text);
 }
예제 #10
0
 public void SetInnerScope_SetsParentCorrectlyRightScope()
 {
     Scope rootScope = new Scope("abc");
     rootScope.DefineInnerScope(1, 1);
     Assert.AreSame(rootScope, rootScope.InnerRightScope.ParentScope);
 }
예제 #11
0
 public void SetInnerScope_SetsInnerLeftScopePropertyToLeftScope2()
 {
     scope = new Scope("defg");
     scope.DefineInnerScope(2, 1);
     Scope leftScopeWithCorrectProperties = new Scope("de", 0);
     leftScopeWithCorrectProperties.IsExplicit = false;
     Assert.IsTrue(leftScopeWithCorrectProperties.Equals(scope.InnerLeftScope));
 }
예제 #12
0
 public void SetInnerScope_SameScopeAsParent_ThrowsExcpetion()
 {
     scope = new Scope("abc");
     Scope inner = scope.DefineInnerScope(0, 3);
 }
예제 #13
0
 public void SetInnerScope_IsFlat_CreatesTwoExtraScopesIfScopeIsInTheMiddle2()
 {
     scope = new Scope("abcd");
     Scope inner = scope.DefineInnerScope(1, 2);
     Scope[] innerScopes = scope.GetInnerScopes();
     Assert.AreEqual(3, innerScopes.Length);
 }
예제 #14
0
 public void SetInnerScope_OnFirstCharInInnerScope_InnerInnerLeftScopeTextIsOK()
 {
     scope = new Scope("a text b");
     scope.DefineInnerScope(1, 5);//' text'
     scope.DefineInnerScope(1, 1);//' ' inside inner middle scope
     Assert.AreEqual(" ", scope.InnerMiddleScope.InnerLeftScope.Text);
 }
예제 #15
0
 public void SetInnerScope_IsFlat_CreatesOneExtraScopesIfScopeIsInTheEnd()
 {
     scope = new Scope("abc");
     Scope inner = scope.DefineInnerScope(2, 1);
     Scope[] innerScopes = scope.GetInnerScopes();
     Assert.AreEqual(2, innerScopes.Length);
 }
예제 #16
0
 public void SetInnerScope_IfInnerScopeExists_DoesNotThrowsException()
 {
     scope = new Scope("abc");
     scope.DefineInnerScope(0, 1);
     scope.DefineInnerScope(2, 1);
 }
예제 #17
0
        public void SetInnerScope_EncapsulatingInnerScopes_CreatesRightImplicitScopeSplitted()
        {
            Scope root = new Scope("abcd");
            root.DefineInnerScope(1, 1);//b
            Assert.AreEqual("cd", root.InnerRightScope.Text);

            Scope encapsulating = root.DefineInnerScope(1, 2);//'b'+'c' splitting 'd' to an implicit scope

            Assert.AreEqual("d", root.InnerRightScope.Text);
            Assert.AreEqual("bc", root.InnerMiddleScope.Text);
            Assert.AreEqual(true, root.InnerRightScope.IsImplicit);
            Assert.AreEqual("b", encapsulating.InnerLeftScope.Text);
            Assert.AreEqual("c", encapsulating.InnerRightScope.Text);
        }
예제 #18
0
 public void SetInnerScope_OnLastCharInInnerScope_InnerInnerRightScopeTextIsOK()
 {
     scope = new Scope("a text b");
     scope.DefineInnerScope(1, 6);//' text '
     scope.DefineInnerScope(6, 1);//' ' in the end of inner middle scope
     Assert.AreEqual(" ", scope.InnerMiddleScope.InnerRightScope.Text);
 }
예제 #19
0
        public void DefineInnerScope_WithleftMiddleandRightScopesasInner_RemovesOriginalScopesFromDirectRootAndIntoNewScope()
        {
            Scope root = new Scope("012");
            root.DefineInnerScope(1, 1);//1
            root.InnerRightScope.Suggestions.Add(new Suggestion("a","b"));
            root.InnerMiddleScope.Suggestions.Add(new Suggestion("a","b"));

            Scope encapsulator = root.DefineInnerScope(0, 2);//01

            Assert.AreEqual("0", encapsulator.InnerLeftScope.Text);
            Assert.AreEqual(null, encapsulator.InnerMiddleScope);
            Assert.AreEqual("1", encapsulator.InnerRightScope.Text);

            Assert.AreEqual("2", root.InnerRightScope.Text);
            Assert.AreEqual("01", root.InnerLeftScope.Text);
            Assert.AreEqual(null, root.InnerMiddleScope);

            Assert.AreEqual(1, root.InnerRightScope.Suggestions.Count);
            Assert.AreEqual(1, encapsulator.InnerRightScope.Suggestions.Count);
            Assert.AreEqual(encapsulator, encapsulator.InnerRightScope.ParentScope);
            Assert.AreEqual(encapsulator, encapsulator.InnerLeftScope.ParentScope);
        }
예제 #20
0
 public void SetInnerScope_ParentIsNoLongerFlat()
 {
     Scope root = new Scope("abcd");
     root.DefineInnerScope(1, 1);//b
     Assert.IsFalse(root.IsFlat);
 }
예제 #21
0
 public void SetInnerScope_SetsInnerRightScopePropertyToRightScope2()
 {
     scope = new Scope("defge");
     scope.DefineInnerScope(2, 1);
     Scope rightScopeWithCorrectProperties = new Scope("ge", 3);
     rightScopeWithCorrectProperties.IsExplicit = false;
     Assert.IsTrue(rightScopeWithCorrectProperties.Equals(scope.InnerRightScope));
 }
예제 #22
0
 public void SetInnerScope_SetsInnerLeftScopePropertyToLeftScope()
 {
     scope = new Scope("abc", 0, true);
     scope.DefineInnerScope(1, 1);
     Scope leftScopeWithCorrectProperties = new Scope("a", 0, false);
     Assert.IsTrue(leftScopeWithCorrectProperties.Equals(scope.InnerLeftScope));
 }
예제 #23
0
 public void SetInnerScope_EncapsulatingInnerScopes_CreatesOuterScopeWithInnerScopes()
 {
     Scope root = new Scope("abcd");
     root.DefineInnerScope(1, 1);//b
     root.DefineInnerScope(2, 1);//'c' as inner of 'cd'
     Scope encapsulating = root.DefineInnerScope(1, 2);//'b'+'c' splitting 'd' to an implicit scope
     Assert.AreEqual("bc", encapsulating.Text);
 }
예제 #24
0
 public void SetInnerScope_SetsInnerMiddleScopePropertyToNewScope()
 {
     scope = new Scope("abc");
     Scope middle = scope.DefineInnerScope(1, 1);
     Assert.AreSame(middle, scope.InnerMiddleScope);
 }
예제 #25
0
 public void SetInnerScope_OnFirstCharInInnerScope_InnerInnerMiddleScopeIsNull()
 {
     scope = new Scope("a text b");
     scope.DefineInnerScope(1, 5);//' text'
     scope.DefineInnerScope(1, 1);//' ' inside inner middle scope
     Assert.IsNull(scope.InnerMiddleScope.InnerMiddleScope);
 }
예제 #26
0
 public void SetInnerScope_SetsInnerRightScopePropertyToRightScope()
 {
     scope = new Scope("abc");
     scope.DefineInnerScope(1, 1);
     Scope rightScopeWithCorrectProperties = new Scope("c", 2, false);
     Assert.IsTrue(rightScopeWithCorrectProperties.Equals(scope.InnerRightScope));
 }
예제 #27
0
 public void SetInnerScope_OnFirstChar_InnerMiddleScopeIsNull()
 {
     scope = new Scope(" text");
     scope.DefineInnerScope(0, 1);//' '
     Assert.IsNull(scope.InnerMiddleScope);
 }
예제 #28
0
 public void SetInnerScope_SetsParentCorrectly()
 {
     Scope rootScope = new Scope("abc");
     Scope inner = rootScope.DefineInnerScope(1, 1);
     Assert.AreSame(rootScope, inner.ParentScope);
 }
예제 #29
0
 public void SetInnerScope_OnInnerScope_HasCorrectRightScopeText()
 {
     scope = new Scope("abcde");
     scope.DefineInnerScope(1, 3);//bcd
     scope.DefineInnerScope(2, 1);//'c'
     Assert.AreEqual("d", scope.InnerMiddleScope.InnerRightScope.Text);
 }
예제 #30
0
 public void SetInnerScope_WithScopeInThebeginning_SetsInnerLEftScopeAsNewScope()
 {
     scope = new Scope("abc");
     Scope newone = scope.DefineInnerScope(0, 1);
     Assert.AreSame(newone, scope.InnerLeftScope);
 }
예제 #31
0
 public void SetInnerScope_OnInnerScope_SetsMiddleScopeLengthCorrectly()
 {
     scope = new Scope("this is some text");
     Scope textScope = scope.DefineInnerScope(8, 5);//'some '
     Scope exScope = scope.DefineInnerScope(9, 2);//'om'
     Assert.AreEqual(2, textScope.InnerMiddleScope.Length); //'s'
 }
예제 #32
0
 public void SetInnerScope_WithScopeInTheEnd_SetsInnerRightScopeAsNewScope()
 {
     scope = new Scope("abc");
     Scope newone = scope.DefineInnerScope(2, 1);
     Assert.AreSame(newone, scope.InnerRightScope);
 }
예제 #33
0
 public void SetInnerScope_OnInnerScope_SetsRightScopeLengthCorrectly()
 {
     scope = new Scope("this is some text");
     Scope textScope = scope.DefineInnerScope(8, 4);//'some'
     Scope exScope = scope.DefineInnerScope(9, 2);//'om'
     Assert.AreEqual(1, textScope.InnerRightScope.Length); //'e'
 }