コード例 #1
0
        public void VersionedStringSource_ExplicitlyConvertsToString_WhenSourceIsString()
        {
            var data = "Hello, world!";
            var source = new VersionedStringSource(data);

            TheResultingString((String)source).ShouldBe("Hello, world!");
        }
コード例 #2
0
        public void VersionedStringSource_ExplicitlyConvertsToString_WhenSourceIsString()
        {
            var data   = "Hello, world!";
            var source = new VersionedStringSource(data);

            TheResultingString((String)source).ShouldBe("Hello, world!");
        }
コード例 #3
0
        public void VersionedStringSource_ProducesCorrectString_WhenToStringIsCalled_AndSourceIsStringBuilder()
        {
            var data   = new VersionedStringBuilder("Hello, world!");
            var source = new VersionedStringSource(data);

            TheResultingString(source.ToString()).ShouldBe("Hello, world!");
        }
コード例 #4
0
        public void VersionedStringSource_ExplicitlyConvertsToStringBuilder_WhenSourceIsStringBuilder()
        {
            var data = new VersionedStringBuilder("Hello, world!");
            var source = new VersionedStringSource(data);

            TheResultingObject((VersionedStringBuilder)source)
                .ShouldSatisfyTheCondition(x => x.ToString() == "Hello, world!");
        }
コード例 #5
0
        public void VersionedStringSource_IsInvalid_WhenNoSourceIsSpecified()
        {
            var source = new VersionedStringSource();

            TheResultingValue(source.IsValid).ShouldBe(false);
            TheResultingValue(source.IsSourcedFromString).ShouldBe(false);
            TheResultingValue(source.IsSourcedFromStringBuilder).ShouldBe(false);
        }
コード例 #6
0
        public void VersionedStringSource_ExplicitlyConvertsToStringBuilder_WhenSourceIsStringBuilder()
        {
            var data   = new VersionedStringBuilder("Hello, world!");
            var source = new VersionedStringSource(data);

            TheResultingObject((VersionedStringBuilder)source)
            .ShouldSatisfyTheCondition(x => x.ToString() == "Hello, world!");
        }
コード例 #7
0
        public void VersionedStringSource_CannotConvertToString_WhenSourceIsNotString()
        {
            var data   = new VersionedStringBuilder("Hello, world!");
            var source = new VersionedStringSource(data);

            Assert.That(() => TheResultingString((String)source).ShouldBe("Hello, world!"),
                        Throws.TypeOf <InvalidCastException>());
        }
コード例 #8
0
        public void VersionedStringSource_IsInvalid_WhenNoSourceIsSpecified()
        {
            var source = new VersionedStringSource();

            TheResultingValue(source.IsValid).ShouldBe(false);
            TheResultingValue(source.IsSourcedFromString).ShouldBe(false);
            TheResultingValue(source.IsSourcedFromStringBuilder).ShouldBe(false);
        }
コード例 #9
0
        public void VersionedStringSource_CannotConvertToString_WhenSourceIsNotString()
        {
            var data = new VersionedStringBuilder("Hello, world!");
            var source = new VersionedStringSource(data);

            Assert.That(() => TheResultingString((String)source).ShouldBe("Hello, world!"),
                Throws.TypeOf<InvalidCastException>());
        }
コード例 #10
0
        public void VersionedStringSource_IsValid_WhenStringBuilderSourceIsSpecified()
        {
            var data   = new VersionedStringBuilder("Hello, world!");
            var source = new VersionedStringSource(data);

            TheResultingValue(source.IsValid).ShouldBe(true);
            TheResultingValue(source.IsSourcedFromString).ShouldBe(false);
            TheResultingValue(source.IsSourcedFromStringBuilder).ShouldBe(true);
        }
コード例 #11
0
        public void VersionedStringSource_IsValid_WhenStringSourceIsSpecified()
        {
            var data = "Hello, world!";
            var source = new VersionedStringSource(data);

            TheResultingValue(source.IsValid).ShouldBe(true);
            TheResultingValue(source.IsSourcedFromString).ShouldBe(true);
            TheResultingValue(source.IsSourcedFromStringBuilder).ShouldBe(false);
        }
コード例 #12
0
        public void VersionedStringBuilder_VersionIsIncremented_WhenAppendVersionedStringSourceIsCalled_WithValidStringBuilderSource()
        {
            var builder = new VersionedStringBuilder("Hello, world!");

            var source = new VersionedStringBuilder(" Goodbye, world!");
            var value = new VersionedStringSource(source);
            builder.Append(value);

            TheResultingValue(builder.Version).ShouldBe(1);
            TheResultingString(builder.ToString()).ShouldBe("Hello, world! Goodbye, world!");
        }
コード例 #13
0
        public void VersionedStringBuilder_VersionIsNotIncremented_WhenInsertVersionedStringSourceIsCalled_WithInvalidSource()
        {
            var builder = new VersionedStringBuilder("Hello, world!");

            var value = new VersionedStringSource();

            builder.Insert(5, value);

            TheResultingValue(builder.Version).ShouldBe(0);
            TheResultingString(builder.ToString()).ShouldBe("Hello, world!");
        }
コード例 #14
0
        public void VersionedStringSource_CannotConvertToStringBuilder_WhenSourceIsNotStringBuilder()
        {
            var data   = "Hello, world!";
            var source = new VersionedStringSource(data);

            Assert.That(() =>
            {
                TheResultingObject((VersionedStringBuilder)source)
                .ShouldSatisfyTheCondition(x => x.ToString() == "Hello, world!");
            },
                        Throws.TypeOf <InvalidCastException>());
        }
コード例 #15
0
        public void VersionedStringBuilder_VersionIsIncremented_WhenInsertVersionedStringSourceIsCalled_WithValidStringBuilderSource()
        {
            var builder = new VersionedStringBuilder("Hello, world!");

            var source = new VersionedStringBuilder(" and goodbye");
            var value  = new VersionedStringSource(source);

            builder.Insert(5, value);

            TheResultingValue(builder.Version).ShouldBe(1);
            TheResultingString(builder.ToString()).ShouldBe("Hello and goodbye, world!");
        }
コード例 #16
0
        public void VersionedStringSource_CannotConvertToStringBuilder_WhenSourceIsNotStringBuilder()
        {
            var data = "Hello, world!";
            var source = new VersionedStringSource(data);

            Assert.That(() =>
            {
                TheResultingObject((VersionedStringBuilder)source)
                    .ShouldSatisfyTheCondition(x => x.ToString() == "Hello, world!");
            },
            Throws.TypeOf<InvalidCastException>());
        }
コード例 #17
0
        public void VersionedStringBuilder_VersionIsIncremented_WhenAppendVersionedStringSourceIsCalled_WithValidStringSource()
        {
            var builder = new VersionedStringBuilder("Hello, world!");

            var source = " Goodbye, world!";
            var value  = new VersionedStringSource(source);

            builder.Append(value);

            TheResultingValue(builder.Version).ShouldBe(1);
            TheResultingString(builder.ToString()).ShouldBe("Hello, world! Goodbye, world!");
        }
コード例 #18
0
ファイル: TextBox.cs プロジェクト: masums/ultraviolet
        /// <summary>
        /// Occurs when the value of the Text dependency property changes.
        /// </summary>
        private static void HandleTextChanged(DependencyObject dobj, VersionedStringSource oldValue, VersionedStringSource newValue)
        {
            var raiseTextChanged = false;

            var textBox = (TextBox)dobj;

            if (textBox.TextEditor != null)
            {
                raiseTextChanged = !textBox.TextEditor.HandleTextChanged(newValue);
            }

            if (raiseTextChanged)
            {
                textBox.OnTextChanged();
            }
        }
コード例 #19
0
        /// <summary>
        /// Appends the contents of a <see cref="VersionedStringSource"/> to the end of the string builder.
        /// </summary>
        /// <param name="this">The <see cref="StringBuilder"/> instance.</param>
        /// <param name="value">The <see cref="VersionedStringSource"/> to append to the string builder.</param>
        /// <returns>The current <see cref="StringBuilder"/> instance.</returns>
        public static StringBuilder AppendVersionedStringSource(this StringBuilder @this, VersionedStringSource value)
        {
            Contract.Require(@this, "this");

            if (value.IsValid)
            {
                if (value.IsSourcedFromString)
                {
                    var source = (String)value;
                    @this.Append(source);
                }
                else
                {
                    var source = (VersionedStringBuilder)value;
                    for (int i = 0; i < source.Length; i++)
                    {
                        @this.Append(source[i]);
                    }
                }
            }

            return @this;
        }
コード例 #20
0
        /// <summary>
        /// Inserts the contents of a <see cref="VersionedStringSource"/> into the string builder at the specified position.
        /// </summary>
        /// <param name="this">The <see cref="StringBuilder"/> instance.</param>
        /// <param name="index">The index at which to begin inserting the value.</param>
        /// <param name="value">The <see cref="VersionedStringSource"/> to insert into the string builder.</param>
        /// <returns>The current <see cref="StringBuilder"/> instance.</returns>
        public static StringBuilder InsertVersionedStringSource(this StringBuilder @this, Int32 index, VersionedStringSource value)
        {
            Contract.Require(@this, "this");
            Contract.EnsureRange(index >= 0 && index <= @this.Length, "index");

            if (value.IsValid)
            {
                if (value.IsSourcedFromString)
                {
                    var source = (String)value;
                    @this.Insert(index, source);
                }
                else
                {
                    var source = (VersionedStringBuilder)value;
                    for (int i = 0; i < source.Length; i++)
                    {
                        @this.Insert(index + i, source[i]);
                    }
                }
            }

            return @this;
        }
コード例 #21
0
        public void VersionedStringBuilder_VersionIsNotIncremented_WhenInsertVersionedStringSourceIsCalled_WithInvalidSource()
        {
            var builder = new VersionedStringBuilder("Hello, world!");

            var value = new VersionedStringSource();
            builder.Insert(5, value);

            TheResultingValue(builder.Version).ShouldBe(0);
            TheResultingString(builder.ToString()).ShouldBe("Hello, world!");
        }
コード例 #22
0
ファイル: TextEditor.cs プロジェクト: RUSshy/ultraviolet
 /// <summary>
 /// Appends the specified string to the end of the internal text buffer.
 /// </summary>
 private void AppendToBuffer(VersionedStringSource str)
 {
     if (str.IsValid)
     {
         if (str.IsSourcedFromString)
         {
             InsertIntoBuffer(new StringSegment((String)str), bufferText.Length);
         }
         else
         {
             InsertIntoBuffer(new StringSegment((StringBuilder)(VersionedStringBuilder)str), bufferText.Length);
         }
     }
 }
コード例 #23
0
ファイル: TextEditor.cs プロジェクト: RUSshy/ultraviolet
 /// <summary>
 /// Inserts the specified string into the internal text buffer at the specified position.
 /// </summary>
 private void InsertIntoBuffer(VersionedStringSource str, Int32 position)
 {
     if (str.IsValid)
     {
         if (str.IsSourcedFromString)
         {
             InsertIntoBuffer(new StringSegment((String)str), position);
         }
         else
         {
             InsertIntoBuffer(new StringSegment((StringBuilder)(VersionedStringBuilder)str), position);
         }
     }
 }
コード例 #24
0
        /// <summary>
        /// Occurs when the value of the Text dependency property changes.
        /// </summary>
        private static void HandleTextChanged(DependencyObject dobj, VersionedStringSource oldValue, VersionedStringSource newValue)
        {
            var label = (TextBlock)dobj;

            label.UpdateTextParserResult();
        }
コード例 #25
0
ファイル: TextEditor.cs プロジェクト: RUSshy/ultraviolet
        /// <summary>
        /// Called when the value of the <see cref="TextBox.TextProperty"/> dependency property changes.
        /// </summary>
        /// <param name="value">The new value of the dependency property.</param>
        /// <returns><see langword="true"/> if the editor replaced the text with its own source; otherwise, <see langword="false"/>.</returns>
        internal Boolean HandleTextChanged(VersionedStringSource value)
        {
            if (value.IsSourcedFromStringBuilder && (VersionedStringBuilder)value == bufferText)
                return false;

            var valueHasNotChanged = value.Length == bufferText.Length;
            if (valueHasNotChanged)
            {
                for (int i = 0; i < bufferText.Length; i++)
                {
                    if (bufferText[i] != value[i])
                    {
                        valueHasNotChanged = false;
                        break;
                    }
                }
            }

            if (valueHasNotChanged)
                return false;

            if (value.IsSourcedFromStringBuilder)
            {
                var vsb = (VersionedStringBuilder)value;
                if (vsb.Version == bufferText.Version)
                    return false;
            }

            BeginTrackingSelectionChanges();

            ClearBuffer(value.Length == 0);
            InsertIntoBuffer(value, bufferText.Length);

            if (caretPosition > bufferText.Length)
            {
                caretBlinkTimer = 0;
                caretPosition = bufferText.Length;

                pendingScrollToCaret = true;
            }

            UpdateTextStringSource();
            UpdateTextParserStream();

            EndTrackingSelectionChanges();

            return true;
        }
コード例 #26
0
        public void VersionedStringBuilder_VersionIsIncremented_WhenInsertVersionedStringSourceIsCalled_WithValidStringSource()
        {
            var builder = new VersionedStringBuilder("Hello, world!");

            var source = " and goodbye";
            var value = new VersionedStringSource(source);
            builder.Insert(5, value);

            TheResultingValue(builder.Version).ShouldBe(1);
            TheResultingString(builder.ToString()).ShouldBe("Hello and goodbye, world!");
        }
コード例 #27
0
 /// <summary>
 /// Inserts the contents of the specified string source at the specified index within the string builder.
 /// </summary>
 /// <param name="index">The index at which to insert the value.</param>
 /// <param name="value">The value to insert.</param>
 /// <returns>The current instance of <see cref="VersionedStringBuilder"/>.</returns>
 public VersionedStringBuilder Insert(Int32 index, VersionedStringSource value)
 {
     if (value.IsValid)
     {
         if (value.IsSourcedFromString)
         {
             Insert(index, (String)value);
         }
         else
         {
             Insert(index, (VersionedStringBuilder)value);
         }
     }
     else
     {
         if (index < 0 || index > stringBuilder.Length)
             throw new ArgumentOutOfRangeException("index");
     }
     return this;
 }
コード例 #28
0
ファイル: TextEditor.cs プロジェクト: prshreshtha/ultraviolet
        /// <summary>
        /// Called when the value of the <see cref="TextBox.TextProperty"/> dependency property changes.
        /// </summary>
        /// <param name="value">The new value of the dependency property.</param>
        /// <returns><c>true</c> if the editor replaced the text with its own source; otherwise, <c>false</c>.</returns>
        internal Boolean HandleTextChanged(VersionedStringSource value)
        {
            if (value.IsSourcedFromStringBuilder)
            {
                var vsb = (VersionedStringBuilder)value;
                if (vsb.Version == bufferText.Version)
                    return false;
            }

            BeginTrackingSelectionChanges();

            var valueLength = 0;
            if (value.IsValid)
            {
                if (value.IsSourcedFromString)
                {
                    valueLength = ((String)value).Length;
                }
                else
                {
                    valueLength = ((VersionedStringBuilder)value).Length;
                }
            }

            ClearBuffer(valueLength == 0);
            InsertIntoBuffer(value, bufferText.Length);

            if (caretPosition > bufferText.Length)
            {
                caretBlinkTimer = 0;
                caretPosition = bufferText.Length;

                pendingScrollToCaret = true;
            }

            UpdateTextStringSource();
            UpdateTextParserStream();

            EndTrackingSelectionChanges();

            return true;
        }
コード例 #29
0
ファイル: TextBox.cs プロジェクト: RUSshy/ultraviolet
        /// <summary>
        /// Occurs when the value of the Text dependency property changes.
        /// </summary>
        private static void HandleTextChanged(DependencyObject dobj, VersionedStringSource oldValue, VersionedStringSource newValue)
        {
            var raiseTextChanged = false;

            var textBox = (TextBox)dobj;
            if (textBox.TextEditor != null)
                raiseTextChanged = !textBox.TextEditor.HandleTextChanged(newValue);

            if (raiseTextChanged)
                textBox.OnTextChanged();
        }
コード例 #30
0
        public void VersionedStringSource_ProducesCorrectString_WhenToStringIsCalled_AndSourceIsString()
        {
            var data = "Hello, world!";
            var source = new VersionedStringSource(data);

            TheResultingString(source.ToString()).ShouldBe("Hello, world!");
        }
コード例 #31
0
        public void VersionedStringSource_ProducesCorrectString_WhenToStringIsCalled_AndSourceIsInvalid()
        {
            var source = new VersionedStringSource();

            TheResultingString(source.ToString()).ShouldBe(null);
        }
コード例 #32
0
 /// <summary>
 /// Appends the contents of the specified string source at the end of the string builder.
 /// </summary>
 /// <param name="value">The value to append.</param>
 /// <returns>The current instance of <see cref="VersionedStringBuilder"/>.</returns>
 public VersionedStringBuilder Append(VersionedStringSource value)
 {
     if (value.IsValid)
     {
         if (value.IsSourcedFromString)
         {
             Append((String)value);
         }
         else
         {
             Append((VersionedStringBuilder)value);
         }
     }
     return this;
 }
コード例 #33
0
ファイル: TextBlock.cs プロジェクト: prshreshtha/ultraviolet
 /// <summary>
 /// Occurs when the value of the Text dependency property changes.
 /// </summary>
 private static void HandleTextChanged(DependencyObject dobj, VersionedStringSource oldValue, VersionedStringSource newValue)
 {
     var label = (TextBlock)dobj;
     label.UpdateTextParserResult();
 }
コード例 #34
0
        public void VersionedStringSource_ProducesCorrectString_WhenToStringIsCalled_AndSourceIsInvalid()
        {
            var source = new VersionedStringSource();

            TheResultingString(source.ToString()).ShouldBe(null);
        }