Exemple #1
0
        public void ParseKeyedBlocks(string args, string[] keys, string[] values)
        {
            var subject = new BaseFormatterImpl();
            var req     = new FormatterRequest(new Literal(1, 1, 1, 1, new StringBuilder()), string.Empty, null, args);

            // Warm-up
            subject.ParseKeyedBlocks(req, 0);

            Benchmark.Start("Parsing keyed blocks..", this.outputHelper);
            for (int i = 0; i < 10000; i++)
            {
                subject.ParseKeyedBlocks(req, 0);
            }

            Benchmark.End(this.outputHelper);

            var actual = subject.ParseKeyedBlocks(req, 0);

            Assert.Equal(keys.Length, actual.Count());
            this.outputHelper.WriteLine("Input: " + args);
            this.outputHelper.WriteLine("-----");
            for (int index = 0; index < actual.ToArray().Length; index++)
            {
                var keyedBlock    = actual.ToArray()[index];
                var expectedKey   = keys[index];
                var expectedValue = values[index];
                Assert.Equal(expectedKey, keyedBlock.Key);
                Assert.Equal(expectedValue, keyedBlock.BlockText);

                this.outputHelper.WriteLine("Key: " + keyedBlock.Key);
                this.outputHelper.WriteLine("Block: " + keyedBlock.BlockText);
            }
        }
Exemple #2
0
        public void ParseKeyedBlocks_unclosed_escape_sequence(string args)
        {
            var subject = new BaseFormatterImpl();
            var req     = new FormatterRequest(new Literal(1, 1, 1, 1, new StringBuilder()), string.Empty, null, args);

            Assert.Throws <MalformedLiteralException>(() => subject.ParseKeyedBlocks(req, 0));
        }
        public void ParseKeyedBlocks(string args, string[] keys, string[] values)
        {
            var subject = new BaseFormatterImpl();
            var req = new FormatterRequest(new Literal(1, 1, 1, 1, new StringBuilder()), null, null, args);

            // Warm-up
            subject.ParseKeyedBlocks(req, 0);

            Benchmark.Start("Parsing keyed blocks..", this.outputHelper);
            for (int i = 0; i < 10000; i++)
            {
                subject.ParseKeyedBlocks(req, 0);
            }

            Benchmark.End(this.outputHelper);

            var actual = subject.ParseKeyedBlocks(req, 0);
            Assert.Equal(keys.Length, actual.Count());
            this.outputHelper.WriteLine("Input: " + args);
            this.outputHelper.WriteLine("-----");
            for (int index = 0; index < actual.ToArray().Length; index++)
            {
                var keyedBlock = actual.ToArray()[index];
                var expectedKey = keys[index];
                var expectedValue = values[index];
                Assert.Equal(expectedKey, keyedBlock.Key);
                Assert.Equal(expectedValue, keyedBlock.BlockText);

                this.outputHelper.WriteLine("Key: " + keyedBlock.Key);
                this.outputHelper.WriteLine("Block: " + keyedBlock.BlockText);
            }
        }