OSDN Git Service

区間が重複するエンティティについて TweetFormatter のテストコードを追加
authorKimura Youichi <kim.upsilon@bucyou.net>
Sun, 25 May 2014 14:25:34 +0000 (23:25 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sun, 25 May 2014 14:45:19 +0000 (23:45 +0900)
5/28 から追加される予定の extended_entities 対応のため

OpenTween.Tests/TweetFormatterTest.cs

index b09dd3f..9f7a5b4 100644 (file)
@@ -331,5 +331,53 @@ namespace OpenTween
             var expected = "てすと<br>てすと<br>てすと";
             Assert.Equal(expected, TweetFormatter.AutoLinkHtml(text, entities));
         }
+
+        [Fact]
+        public void AutoLinkHtml_OverlappedEntitiesTest()
+        {
+            // extended_entities で追加される、区間が重複したエンティティを考慮
+            // 参照: https://dev.twitter.com/docs/api/multiple-media-extended-entities
+
+            var text = "\"I hope you'll keep...building bonds of friendship that will enrich your lives &amp; enrich our world\" \u2014FLOTUS in China, http://t.co/fxmuQN9JL9";
+            var entities = new[]
+            {
+                new TwitterEntityMedia
+                {
+                    DisplayUrl = "pic.twitter.com/fxmuQN9JL9",
+                    ExpandedUrl = "http://twitter.com/FLOTUS/status/449660889793581056/photo/1",
+                    Indices = new[] { 121, 143 },
+                    MediaUrlHttps = "https://pbs.twimg.com/media/Bj2EH6yIQAEYvxu.jpg",
+                    Url = "http://t.co/fxmuQN9JL9",
+                },
+                new TwitterEntityMedia
+                {
+                    DisplayUrl = "pic.twitter.com/fxmuQN9JL9",
+                    ExpandedUrl = "http://twitter.com/FLOTUS/status/449660889793581056/photo/1",
+                    Indices = new[] { 121, 143 },
+                    MediaUrlHttps = "https://pbs.twimg.com/media/Bj2EHxAIIAE8dtg.jpg",
+                    Url = "http://t.co/fxmuQN9JL9",
+                },
+                new TwitterEntityMedia
+                {
+                    DisplayUrl = "pic.twitter.com/fxmuQN9JL9",
+                    ExpandedUrl = "http://twitter.com/FLOTUS/status/449660889793581056/photo/1",
+                    Indices = new[] { 121, 143 },
+                    MediaUrlHttps = "https://pbs.twimg.com/media/Bj2EH3pIYAE4LQn.jpg",
+                    Url = "http://t.co/fxmuQN9JL9",
+                },
+                new TwitterEntityMedia
+                {
+                    DisplayUrl = "pic.twitter.com/fxmuQN9JL9",
+                    ExpandedUrl = "http://twitter.com/FLOTUS/status/449660889793581056/photo/1",
+                    Indices = new[] { 121, 143 },
+                    MediaUrlHttps = "https://pbs.twimg.com/media/Bj2EL3DIEAAzGAX.jpg",
+                    Url = "http://t.co/fxmuQN9JL9",
+                },
+            };
+
+            var expected = "&quot;I hope you&#39;ll keep...building bonds of friendship that will enrich your lives &amp; enrich our world&quot; \u2014FLOTUS in China, " +
+                "<a href=\"http://t.co/fxmuQN9JL9\" title=\"http://twitter.com/FLOTUS/status/449660889793581056/photo/1\">pic.twitter.com/fxmuQN9JL9</a>";
+            Assert.Equal(expected, TweetFormatter.AutoLinkHtml(text, entities));
+        }
     }
 }