public void TrySplitSpecifier_InvalidRaw()
        {
            bool result = FormatSpecifierUtil.TrySplitSpecifier(
                "!!!", out string size, out string raw, out string baseSpecifier);

            Assert.That(result, Is.False);
        }
示例#2
0
        /// <summary>
        /// Parses n and returns true if |formatSpecifier| is of the form "expand(n)"
        /// and false otherwise.
        /// </summary>
        public static bool TryParseExpandFormatSpecifier(string formatSpecifier,
                                                         out int expandedIndex)
        {
            expandedIndex   = -1;
            formatSpecifier = FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix(formatSpecifier);
            if (!formatSpecifier.StartsWith(_expandStart) || !formatSpecifier.EndsWith(_expandEnd))
            {
                return(false);
            }

            int result;

            if (!int.TryParse(formatSpecifier.Substring(_expandStart.Length,
                                                        formatSpecifier.Length - _expandStart.Length - _expandEnd.Length), out result))
            {
                return(false);
            }

            if (result < 0)
            {
                return(false);
            }
            expandedIndex = result;
            return(true);
        }
示例#3
0
        // TODO: handle the situation when raw and expand formatter are both present
        public virtual IVariableInformation Create(
            RemoteValue remoteValue, string displayName = null,
            FormatSpecifier formatSpecifier             = null,
            CustomVisualizer customVisualizer           = CustomVisualizer.None)
        {
            IVariableInformation varInfo =
                _varInfoFactory.Create(remoteValue, displayName, formatSpecifier, customVisualizer);

            // Don't use Natvis for raw format specifier (!), e.g. "myvar,!".
            if (FormatSpecifierUtil.HasRawFormatSpecifier(varInfo.FormatSpecifier))
            {
                return(new CachingVariableInformation(varInfo));
            }

            var natvisVarInfo = new NatvisVariableInformation(_natvisExpander, varInfo);

            if (ExpandFormatSpecifierUtil.TryParseExpandFormatSpecifier(
                    natvisVarInfo.FormatSpecifier, out int expandedIndex))
            {
                return(new CachingVariableInformation(
                           _expandVariableFactory.Create(natvisVarInfo, expandedIndex)));
            }

            return(new CachingVariableInformation(natvisVarInfo));
        }
 public void GetChildFormatSpecifier_View_Inherited()
 {
     Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier("view(simple)", null),
                 Is.EqualTo("view(simple)"));
     Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier("!view(simple)", null),
                 Is.EqualTo("view(simple)"));
     Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier("!!view(simple)", null),
                 Is.EqualTo("!!view(simple)"));
 }
 public void GetChildFormatSpecifier_Expand_NotInherited()
 {
     Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier("expand(1)", null),
                 Is.EqualTo(""));
     Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier("!expand(1)", null),
                 Is.EqualTo(""));
     Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier("!!expand(1)", null),
                 Is.EqualTo("!!"));
 }
        public void TrySplitSpecifier_SizeExpressionRawBase()
        {
            bool result = FormatSpecifierUtil.TrySplitSpecifier(
                "[a[i]]!!x", out string size, out string raw, out string baseSpecifier);

            Assert.That(result, Is.True);
            Assert.That(size, Is.EqualTo("[a[i]]"));
            Assert.That(raw, Is.EqualTo("!!"));
            Assert.That(baseSpecifier, Is.EqualTo("x"));
        }
        public void TrySplitSpecifier_SizeExpressionWithDoubleQuotesBase()
        {
            bool result = FormatSpecifierUtil.TrySplitSpecifier(
                "[f(a, \"]c\")]Xb", out string size, out string raw, out string baseSpecifier);

            Assert.That(result, Is.True);
            Assert.That(size, Is.EqualTo("[f(a, \"]c\")]"));
            Assert.That(raw, Is.EqualTo(""));
            Assert.That(baseSpecifier, Is.EqualTo("Xb"));
        }
        public void TrySplitSpecifier_SizeExpression()
        {
            bool result = FormatSpecifierUtil.TrySplitSpecifier(
                "[expr]", out string size, out string raw, out string baseSpecifier);

            Assert.That(result, Is.True);
            Assert.That(size, Is.EqualTo("[expr]"));
            Assert.That(raw, Is.EqualTo(""));
            Assert.That(baseSpecifier, Is.EqualTo(""));
        }
        public void TrySplitSpecifier_SizeHexBase()
        {
            bool result = FormatSpecifierUtil.TrySplitSpecifier(
                "0xabx", out string size, out string raw, out string baseSpecifier);

            Assert.That(result, Is.True);
            Assert.That(size, Is.EqualTo("0xab"));
            Assert.That(raw, Is.EqualTo(""));
            Assert.That(baseSpecifier, Is.EqualTo("x"));
        }
        public void TrySplitSpecifier_RawOnly()
        {
            bool result = FormatSpecifierUtil.TrySplitSpecifier(
                "!", out string size, out string raw, out string baseSpecifier);

            Assert.That(result, Is.True);
            Assert.That(size, Is.EqualTo(""));
            Assert.That(raw, Is.EqualTo("!"));
            Assert.That(baseSpecifier, Is.EqualTo(""));
        }
示例#11
0
        /// <summary>
        /// Returns "foo" if |formatSpecifier| is of the form "view(foo)" and an empty string
        /// otherwise.
        /// </summary>
        public static string ParseViewFormatSpecifier(string formatSpecifier)
        {
            formatSpecifier = FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix(formatSpecifier);
            if (!formatSpecifier.StartsWith(_viewStart) || !formatSpecifier.EndsWith(_viewEnd))
            {
                return(string.Empty);
            }

            return(formatSpecifier.Substring(_viewStart.Length,
                                             formatSpecifier.Length - _viewStart.Length -
                                             _viewEnd.Length));
        }
        public void GetChildFormatSpecifier_NotInherited()
        {
            var formatMock = Substitute.For <IRemoteValueFormat>();

            formatMock.ShouldInheritFormatSpecifier().Returns(false);

            Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier("spec", formatMock),
                        Is.EqualTo(string.Empty));
            Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier("!spec", formatMock),
                        Is.EqualTo(string.Empty));
            Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier("!!spec", formatMock),
                        Is.EqualTo("!!"));
            Assert.That(FormatSpecifierUtil.GetChildFormatSpecifier(" !!spec ", formatMock),
                        Is.EqualTo("!!"));
        }
 public void SuppressMemoryAddress()
 {
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress(null), Is.False);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress(string.Empty), Is.False);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress("!"), Is.False);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress("!!"), Is.False);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress("na"), Is.True);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress("!na"), Is.True);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress(" !na "), Is.True);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress("!!na"), Is.True);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress(" !!na "), Is.True);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress(" 3!na "), Is.True);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress(" [3]s "), Is.True);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress("!x"), Is.False);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress(" !x "), Is.False);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress("! x "), Is.False);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress("!!x"), Is.False);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress(" !!x "), Is.False);
     Assert.That(FormatSpecifierUtil.SuppressMemoryAddress("!! x "), Is.False);
 }
 public void HasRawFormatSpecifier()
 {
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier(null), Is.False);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier(string.Empty), Is.False);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("!"), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier(" !  "), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("!!"), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier(" !!  "), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("!x"), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("  !x "), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("!!x"), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("  !!x "), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier(" 3!!x "), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("!!view(a) "), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier(" !expand(a) "), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier(" [n]!x "), Is.True);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier(" [!n]x "), Is.False);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("x"), Is.False);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("x!"), Is.False);
     Assert.That(FormatSpecifierUtil.HasRawFormatSpecifier("x!!"), Is.False);
 }
 public void RemoveRawFormatSpecifier()
 {
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix(null),
                 Is.EqualTo(string.Empty));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix(string.Empty),
                 Is.EqualTo(string.Empty));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix("!"),
                 Is.EqualTo(string.Empty));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix(" !  "),
                 Is.EqualTo(string.Empty));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix("!!"),
                 Is.EqualTo(string.Empty));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix(" !!  "),
                 Is.EqualTo(string.Empty));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix("!x"), Is.EqualTo("x"));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix("  !expand(3) "),
                 Is.EqualTo("expand(3)"));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix("!!x"), Is.EqualTo("x"));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix("  !!view(simple) "),
                 Is.EqualTo("view(simple)"));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix("x"), Is.EqualTo("x"));
     Assert.That(FormatSpecifierUtil.RemoveRawFormatSpecifierPrefix("x!"), Is.EqualTo("x!"));
 }