OSDN Git Service

MyCommon.urlEncodeMultibyteCharメソッドを削除
[opentween/open-tween.git] / OpenTween.Tests / MyCommonTest.cs
index 3282c49..ced990d 100644 (file)
@@ -30,6 +30,7 @@ using System.Text;
 using System.Windows.Forms;
 using Moq;
 using OpenTween;
+using OpenTween.Models;
 using Xunit;
 using Xunit.Extensions;
 
@@ -38,18 +39,6 @@ namespace OpenTween
     public class MyCommonTest
     {
         [Theory]
-        [InlineData("http://ja.wikipedia.org/wiki/Wikipedia", "http://ja.wikipedia.org/wiki/Wikipedia")]
-        [InlineData("http://ja.wikipedia.org/wiki/メインページ",
-            "http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8")]
-        [InlineData("http://fr.wikipedia.org/wiki/Café", "http://fr.wikipedia.org/wiki/Caf%E9")]
-        [InlineData("http://ja.wikipedia.org/wiki/勇気100%", "http://ja.wikipedia.org/wiki/%E5%8B%87%E6%B0%97100%25")]
-        [InlineData("http://ja.wikipedia.org/wiki/Bio_100%", "http://ja.wikipedia.org/wiki/Bio_100%25")]
-        public void urlEncodeMultibyteCharTest(string uri, string expected)
-        {
-            Assert.Equal(expected, MyCommon.urlEncodeMultibyteChar(uri));
-        }
-
-        [Theory]
         [InlineData("http://日本語.idn.icann.org/", "http://xn--wgv71a119e.idn.icann.org/")]
         [InlineData("http://例え.テスト/", "http://xn--r8jz45g.xn--zckzah/")]
         public void IDNEncodeTest(string uri, string expected)
@@ -60,6 +49,7 @@ namespace OpenTween
         [Theory]
         [InlineData("http://xn--wgv71a119e.idn.icann.org/", "http://日本語.idn.icann.org/")]
         [InlineData("http://xn--r8jz45g.xn--zckzah/", "http://例え.テスト/")]
+        [InlineData("http://xn--a/", "http://xn--a/")] // 不正なpunycode
         public void IDNDecodeTest(string uri, string expected)
         {
             Assert.Equal(expected, MyCommon.IDNDecode(uri));
@@ -70,7 +60,10 @@ namespace OpenTween
         [InlineData("http://ja.wikipedia.org/wiki/%3F", "http://ja.wikipedia.org/wiki/%3F")] // "?" に変換しない
         [InlineData("http://ja.wikipedia.org/wiki/%E3%83%9E%E3%82%B8LOVE1000%25",
             "http://ja.wikipedia.org/wiki/マジLOVE1000%25")] // "%" も変換しない
+        [InlineData("http://xn--a/%E3%81%82", "http://xn--a/あ")] // 不正なpunycode
         [InlineData("http://example..com/", "http://example..com/")] // 不正なURL
+        [InlineData("http://example.com/%E3%81%82%FF", "http://example.com/あ%FF")] // 不正なUTF-8シーケンス
+        [InlineData("http://example.com/%E3%81%82%ED%A0%80", "http://example.com/あ%ED%A0%80")] // 不正なUTF-8シーケンス (high surrogate)
         public void ConvertToReadableUrl(string url, string expected)
         {
             Assert.Equal(expected, MyCommon.ConvertToReadableUrl(url));
@@ -121,27 +114,16 @@ namespace OpenTween
             Assert.Equal(expected, MyCommon.IsAnimatedGif(filename));
         }
 
-        public static IEnumerable<object[]> DateTimeParse_TestCase
+        public static TheoryData<string, DateTimeUtc> DateTimeParse_TestCase = new TheoryData<string, DateTimeUtc>
         {
-            get
-            {
-                yield return new object[] {
-                    "Sun Nov 25 06:10:00 +00:00 2012",
-                    new DateTime(2012, 11, 25, 6, 10, 0, DateTimeKind.Utc),
-                };
-                yield return new object[] {
-                    "Sun, 25 Nov 2012 06:10:00 +00:00",
-                    new DateTime(2012, 11, 25, 6, 10, 0, DateTimeKind.Utc),
-                };
-            }
-        }
+            { "Sun Nov 25 06:10:00 +00:00 2012", new DateTimeUtc(2012, 11, 25, 6, 10, 0) },
+            { "Sun, 25 Nov 2012 06:10:00 +00:00", new DateTimeUtc(2012, 11, 25, 6, 10, 0) },
+        };
 
         [Theory]
-        [MemberData("DateTimeParse_TestCase")]
-        public void DateTimeParseTest(string date, DateTime excepted)
-        {
-            Assert.Equal(excepted, MyCommon.DateTimeParse(date).ToUniversalTime());
-        }
+        [MemberData(nameof(DateTimeParse_TestCase))]
+        public void DateTimeParseTest(string date, DateTimeUtc excepted)
+            => Assert.Equal(excepted, MyCommon.DateTimeParse(date));
 
         [DataContract]
         public struct JsonData
@@ -161,7 +143,7 @@ namespace OpenTween
         }
 
         [Theory]
-        [MemberData("CreateDataFromJson_TestCase")]
+        [MemberData(nameof(CreateDataFromJson_TestCase))]
         public void CreateDataFromJsonTest<T>(string json, T expected)
         {
             Assert.Equal(expected, MyCommon.CreateDataFromJson<T>(json));
@@ -213,11 +195,11 @@ namespace OpenTween
         [Theory]
         [InlineData("1.0.0.0", "1.0.0")]
         [InlineData("1.0.0.1", "1.0.1-dev")]
-        [InlineData("1.0.0.12", "1.0.1-dev (Build 12)")]
+        [InlineData("1.0.0.12", "1.0.1-dev+build.12")]
         [InlineData("1.0.1.0", "1.0.1")]
-        [InlineData("1.0.9.1", "1.1.0-dev")]
+        [InlineData("1.0.9.1", "1.0.10-dev")]
         [InlineData("1.1.0.0", "1.1.0")]
-        [InlineData("1.9.9.1", "2.0.0-dev")]
+        [InlineData("1.9.9.1", "1.9.10-dev")]
         public void GetReadableVersionTest(string fileVersion, string expected)
         {
             Assert.Equal(expected, MyCommon.GetReadableVersion(fileVersion));
@@ -239,7 +221,7 @@ namespace OpenTween
         }
 
         [Theory]
-        [MemberData("GetStatusUrlTest1_TestCase")]
+        [MemberData(nameof(GetStatusUrlTest1_TestCase))]
         public void GetStatusUrlTest1(PostClass post, string expected)
         {
             Assert.Equal(expected, MyCommon.GetStatusUrl(post));
@@ -321,5 +303,37 @@ namespace OpenTween
 
             Assert.Empty(actual);
         }
+
+        [Fact]
+        public void CircularCountUp_Test()
+        {
+            var actual = MyCommon.CircularCountUp(length: 6, startIndex: 3);
+
+            Assert.Equal(new[] { 3, 4, 5, 0, 1, 2 }, actual);
+        }
+
+        [Fact]
+        public void CircularCountUp_StartFromZeroTest()
+        {
+            var actual = MyCommon.CircularCountUp(length: 6, startIndex: 0);
+
+            Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, actual);
+        }
+
+        [Fact]
+        public void CircularCountDown_Test()
+        {
+            var actual = MyCommon.CircularCountDown(length: 6, startIndex: 3);
+
+            Assert.Equal(new[] { 3, 2, 1, 0, 5, 4 }, actual);
+        }
+
+        [Fact]
+        public void CircularCountDown_StartFromLastIndexTest()
+        {
+            var actual = MyCommon.CircularCountDown(length: 6, startIndex: 5);
+
+            Assert.Equal(new[] { 5, 4, 3, 2, 1, 0 }, actual);
+        }
     }
 }