OSDN Git Service

StatusTextHistoryを追加
[opentween/open-tween.git] / OpenTween.Tests / Models / StatusTextHistoryTest.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2024 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 using Xunit;
23
24 namespace OpenTween.Models
25 {
26     public class StatusTextHistoryTest
27     {
28         [Fact]
29         public void Initialize_Test()
30         {
31             var history = new StatusTextHistory();
32             Assert.Single(history.Items);
33             Assert.Equal(new("", null), history.Items[0]);
34             Assert.Equal(0, history.HistoryIndex);
35         }
36
37         [Fact]
38         public void Back_NoItemsTest()
39         {
40             var history = new StatusTextHistory();
41             history.Back("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
42             Assert.Single(history.Items);
43             Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
44             Assert.Equal(0, history.HistoryIndex);
45         }
46
47         [Fact]
48         public void Back_HasItemsTest()
49         {
50             var history = new StatusTextHistory();
51             history.SetLastItem("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
52             history.AddLast();
53             history.Back("@foo bbb", (new TwitterStatusId("222"), "foo"));
54
55             Assert.Equal(2, history.Items.Count);
56             Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
57             Assert.Equal(new("@foo bbb", (new TwitterStatusId("222"), "foo")), history.Items[1]);
58             Assert.Equal(0, history.HistoryIndex);
59         }
60
61         [Fact]
62         public void Forward_NoItemsTest()
63         {
64             var history = new StatusTextHistory();
65             history.Forward("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
66             Assert.Single(history.Items);
67             Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
68             Assert.Equal(0, history.HistoryIndex);
69         }
70
71         [Fact]
72         public void Forward_HasItemsTest()
73         {
74             var history = new StatusTextHistory();
75             history.SetLastItem("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
76             history.AddLast();
77             history.Back("@foo bbb", (new TwitterStatusId("222"), "foo"));
78             history.Forward("@hoge aaa 123", (new TwitterStatusId("111"), "hoge"));
79
80             Assert.Equal(2, history.Items.Count);
81             Assert.Equal(new("@hoge aaa 123", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
82             Assert.Equal(new("@foo bbb", (new TwitterStatusId("222"), "foo")), history.Items[1]);
83             Assert.Equal(1, history.HistoryIndex);
84         }
85
86         [Fact]
87         public void AddLast_Test()
88         {
89             var history = new StatusTextHistory();
90             history.SetLastItem("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
91             history.AddLast();
92             Assert.Equal(2, history.Items.Count);
93             Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
94             Assert.Equal(new("", null), history.Items[1]);
95             Assert.Equal(1, history.HistoryIndex);
96         }
97
98         [Fact]
99         public void Peek_EmptyTest()
100         {
101             var history = new StatusTextHistory();
102             Assert.Null(history.Peek());
103         }
104
105         [Fact]
106         public void Peek_HasItemsTest()
107         {
108             var history = new StatusTextHistory();
109             history.SetLastItem("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
110             history.AddLast();
111
112             Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Peek());
113         }
114     }
115 }