예제 #1
0
        public void Output_Of_String()
        {
            var so = new StringOutput(16);

            so.Write("text", null !);
            Assert.AreEqual("text", so.ToString());
        }
예제 #2
0
        public void StringOutputTest()
        {
            var so = new StringOutput();

            so.Write("text", 0, 2, null);
            Assert.AreEqual("te", so.ToString());
        }
예제 #3
0
        public void Output_Of_ValueStringBuilder()
        {
            var so = new StringOutput();

            using var sb = SmartFormat.Utilities.ZStringBuilderExtensions.CreateZStringBuilder();
            sb.Append("text");
            so.Write(sb, null !);
            Assert.AreEqual("text", so.ToString());
        }
예제 #4
0
        /// <summary>
        /// Replaces one or more format items in a specified string with the string representation of a specific object.
        /// </summary>
        /// <param name="provider">The <see cref="IFormatProvider" /> to use.</param>
        /// <param name="format">A composite format string.</param>
        /// <param name="args">The object to format.</param>
        /// <returns>Returns the formatted input with items replaced with their string representation.</returns>
        public string Format(IFormatProvider?provider, string format, params object[] args)
        {
            var output        = new StringOutput(format.Length + args.Length * 8);
            var formatParsed  = Parser.ParseFormat(format, GetNotEmptyFormatterExtensionNames());
            var current       = args.Length > 0 ? args[0] : args; // The first item is the default.
            var formatDetails = new FormatDetails(this, formatParsed, args, null, provider, output);

            Format(formatDetails, formatParsed, current);

            return(output.ToString());
        }
예제 #5
0
파일: MiscTests.cs 프로젝트: icedland/iced
        void StringOutput_uses_input_sb()
        {
            var sb = new System.Text.StringBuilder();

            sb.Append("Text");
            var output = new StringOutput(sb);

            output.Write("hello", FormatterTextKind.Text);
            Assert.Equal("Texthello", sb.ToString());
            Assert.Equal("Texthello", output.ToString());
        }
예제 #6
0
        public void Format_WithCache_Into_StringOutput()
        {
            var data         = new { Name = "Joe", City = "Melbourne" };
            var formatter    = GetSimpleFormatter();
            var formatString = "{Name}, {City}";
            var format       = formatter.Parser.ParseFormat(formatString);
            var output       = new StringOutput();

            formatter.FormatInto(output, null, format, data);
            Assert.That(output.ToString(), Is.EqualTo($"{data.Name}, {data.City}"));
        }
예제 #7
0
        /// <summary>
        /// Replaces one or more format items in a specified string with the string representation of a specific object,
        /// using the <see cref="FormatCache"/>.
        /// </summary>
        /// <param name="cache">The <see cref="FormatCache" /> to use.</param>
        /// <param name="format">A composite format string.</param>
        /// <param name="args">The objects to format.</param>
        /// <returns>Returns the formatted input with items replaced with their string representation.</returns>
        public string FormatWithCache(ref FormatCache?cache, string format, params object[] args)
        {
            var output = new StringOutput(format.Length + args.Length * 8);

            cache ??= new FormatCache(Parser.ParseFormat(format, GetNotEmptyFormatterExtensionNames()));
            var current       = args.Length > 0 ? args[0] : args; // The first item is the default.
            var formatDetails = new FormatDetails(this, cache.Format, args, cache, null, output);

            Format(formatDetails, cache.Format, current);

            return(output.ToString());
        }
        internal static string Format(Instruction instruction, Formatter formatter, bool printInstructionAddresses, uint pointerSize)
        {
            var output = new StringOutput();

            if (printInstructionAddresses)
            {
                FormatInstructionPointer(instruction, formatter, pointerSize, output);
            }

            formatter.Format(instruction, output);

            return(output.ToString());
        }
예제 #9
0
        public void ToString_StringInput_ReturnsString()
        {
            //arrange
            string  input  = "item1";
            IOutput output = new StringOutput(input);

            //act
            string result = output.ToString();

            //assert
            Assert.NotNull(output);
            Assert.NotNull(result);
            Assert.Equal("item1", result);
        }