コード例 #1
0
        public void ApplyMappingsString_MatchWithinSubstring_DoesntDoubleReplace()
        {
            var mappings = new Dictionary <string, string>()
            {
                { "abc", "a'b'c'" },
                { "bc", "b''c''" }
            };

            var    converter = new OrthographyConverter(mappings);
            string result    = converter.ApplyMappings("abchelloworld");

            Assert.That(result, Is.Not.EqualTo("a'b''c''helloworld"));                  // This would be obtained if you only advance it by 1 instead of by the length of the matched key.
            Assert.That(result, Is.EqualTo("a'b'c'helloworld"));
        }
コード例 #2
0
        public void ApplyMappingsString_MultipleMatches_LongerLengthTakesPrecendence()
        {
            var mappings = new Dictionary <string, string>()
            {
                { "ab", "a''b''" },
                { "abc", "a'b'c'" },
                { "a", "a'''" }
            };

            var    converter = new OrthographyConverter(mappings);
            string result    = converter.ApplyMappings("abchelloworld");

            Assert.That(result, Is.Not.EqualTo("a'''bc'helloworld"));              // This would be obtained if shortest mapping takes precedence.
            Assert.That(result, Is.Not.EqualTo("a''b''chelloworld"));              // This would be obtained if first mapping takes precedence.
            Assert.That(result, Is.EqualTo("a'b'c'helloworld"));
        }