Skip to content

Commit cd30fac

Browse files
authored
Merge pull request #8 from Preagonal/updates2
Minor improvements
2 parents 802adf4 + 98705be commit cd30fac

18 files changed

+3271
-3056
lines changed

GS2Engine.UnitTests/StackEntryExtensionsTests.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GS2Engine.Enums;
22
using GS2Engine.Extensions;
3+
using GS2Engine.GS2.Script;
34
using GS2Engine.Models;
45

56
namespace GS2Engine.UnitTests
@@ -81,6 +82,21 @@ public void When_input_is_string_Then_return_StackEntry_with_type_string_and_val
8182
Assert.Equal(val, test.GetValue()?.ToString());
8283
}
8384

85+
[Fact]
86+
public void When_input_is_TString_Then_return_StackEntry_with_type_string_and_value_type_TString()
87+
{
88+
//Arrange
89+
TString val = "test";
90+
91+
//Act
92+
IStackEntry test = val.ToStackEntry();
93+
94+
//Assert
95+
Assert.Equal(StackEntryType.String, test.Type);
96+
Assert.Equal(typeof(TString), test.GetValue()?.GetType());
97+
Assert.Equal(val, test.GetValue()?.ToString());
98+
}
99+
84100
[Fact]
85101
public void When_input_is_string_array_Then_return_StackEntry_with_type_array_and_value_type_List_string()
86102
{
@@ -96,6 +112,93 @@ public void When_input_is_string_array_Then_return_StackEntry_with_type_array_an
96112
Assert.Equal(val, test.GetValue());
97113
}
98114

115+
[Fact]
116+
public void When_input_is_int_array_Then_return_StackEntry_with_type_array_and_value_type_List_int()
117+
{
118+
//Arrange
119+
int[] val = {1,2};
120+
121+
//Act
122+
IStackEntry test = val.ToStackEntry();
123+
124+
//Assert
125+
Assert.Equal(StackEntryType.Array, test.Type);
126+
Assert.Equal(typeof(List<int>), test.GetValue()?.GetType());
127+
Assert.Equal(val, test.GetValue());
128+
}
129+
130+
[Fact]
131+
public void When_input_is_command_Then_return_StackEntry_with_type_array_and_value_type_List_string()
132+
{
133+
//Arrange
134+
Script.Command val = (_, _) => 0.ToStackEntry();
135+
136+
//Act
137+
IStackEntry test = val.ToStackEntry();
138+
139+
//Assert
140+
Assert.Equal(StackEntryType.Function, test.Type);
141+
Assert.Equal(typeof(Script.Command), test.GetValue()?.GetType());
142+
Assert.Equal(val, test.GetValue());
143+
}
144+
145+
[Fact]
146+
public void When_input_is_guicontrol_Then_return_StackEntry_with_type_array_and_value_type_List_string()
147+
{
148+
//Arrange
149+
IGuiControl val = new GuiControl("", null);
150+
151+
//Act
152+
IStackEntry test = val.ToStackEntry();
153+
154+
//Assert
155+
Assert.Equal(StackEntryType.Array, test.Type);
156+
Assert.Equal(typeof(GuiControl), test.GetValue()?.GetType());
157+
Assert.Equal(val, test.GetValue());
158+
}
159+
160+
[Fact]
161+
public void When_input_is_variablecollection_Then_return_StackEntry_with_type_array_and_value_type_List_string()
162+
{
163+
//Arrange
164+
VariableCollection val = new();
165+
166+
//Act
167+
IStackEntry test = val.ToStackEntry();
168+
169+
//Assert
170+
Assert.Equal(StackEntryType.Array, test.Type);
171+
Assert.Equal(typeof(VariableCollection), test.GetValue()?.GetType());
172+
Assert.Equal(val, test.GetValue());
173+
}
174+
175+
[Fact]
176+
public void When_input_is_typeof_list_Then_return_StackEntry_with_type_array_and_value_type_List_string()
177+
{
178+
//Arrange
179+
List<object> val = new();
180+
181+
//Act
182+
IStackEntry test = val.ToStackEntry();
183+
184+
//Assert
185+
Assert.Equal(StackEntryType.Array, test.Type);
186+
Assert.Equal(typeof(List<object>), test.GetValue()?.GetType());
187+
Assert.Equal(val, test.GetValue());
188+
}
189+
190+
[Fact]
191+
public void When_input_is_outofrange_Then_return_StackEntry_with_type_array_and_value_type_List_string()
192+
{
193+
//Arrange
194+
Thread val = new(_ =>{} );
195+
196+
//Act
197+
//Assert
198+
ArgumentOutOfRangeException exception = Assert.Throws<ArgumentOutOfRangeException>(() => val.ToStackEntry());
199+
Assert.Equal("Specified argument was out of the range of valid values.", exception.Message);
200+
}
201+
99202
[Fact]
100203
public void When_input_is_bool_Then_return_StackEntry_with_type_bool_and_value_type_bool()
101204
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using GS2Engine.Enums;
2+
using GS2Engine.Extensions;
3+
using GS2Engine.GS2.Script;
4+
using GS2Engine.Models;
5+
6+
namespace GS2Engine.UnitTests
7+
{
8+
public class StackExtensionsTests
9+
{
10+
[Fact]
11+
public void When_input_is_int_Then_return_StackEntry_with_type_number_and_value_type_double()
12+
{
13+
//Arrange
14+
Stack<StackEntry> stack = new();
15+
stack.Push("asd".ToStackEntry());
16+
17+
//Act
18+
Stack<StackEntry> newStack = stack.Clone();
19+
20+
//Assert
21+
Assert.Equal(stack.Peek(), newStack.Peek());
22+
}
23+
}
24+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using GS2Engine.Enums;
2+
using GS2Engine.Extensions;
3+
using GS2Engine.GS2.Script;
4+
using GS2Engine.Models;
5+
6+
namespace GS2Engine.UnitTests
7+
{
8+
public class TStringTests
9+
{
10+
[Fact]
11+
public void When_input_is_byte_array_Then_return_TString_with_copy_of_byte_array_as_buffer()
12+
{
13+
//Arrange
14+
byte[] bytes = { 0, 1, 2, 3 };
15+
16+
//Act
17+
TString fromBytes = bytes;
18+
19+
//Assert
20+
Assert.Equal(fromBytes.buffer, bytes);
21+
}
22+
23+
[Fact]
24+
public void When_input_is_none_Then_return_TString_with_empty_byte_array_as_buffer()
25+
{
26+
//Arrange
27+
//Act
28+
TString stringy = new();
29+
30+
//Assert
31+
Assert.Equal(stringy.buffer, Array.Empty<byte>());
32+
}
33+
34+
[Fact]
35+
public void When_checking_length_Then_value_is_correct()
36+
{
37+
//Arrange
38+
TString stringy = "asd";
39+
40+
//Act
41+
int length = stringy.length();
42+
43+
44+
//Assert
45+
Assert.Equal(length, stringy.Length);
46+
}
47+
48+
[Fact]
49+
public void When_adding_tstring_Then_value_is_correct()
50+
{
51+
//Arrange
52+
TString string1 = "ASD";
53+
TString string2 = "123";
54+
55+
//Act
56+
string1 += string2;
57+
string1.writeChar(64);
58+
59+
//Assert
60+
Assert.Equal("asd123@", string1.ToLower().ToString());
61+
}
62+
}
63+
}

GS2Engine/Enums/StackEntryType.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
namespace GS2Engine.Enums
2-
{
3-
public enum StackEntryType
4-
{
5-
Number,
6-
String,
7-
Variable,
8-
Boolean,
9-
Array,
10-
ArrayStart,
11-
Player,
12-
Function,
13-
}
1+
namespace GS2Engine.Enums
2+
{
3+
public enum StackEntryType
4+
{
5+
Number,
6+
String,
7+
Variable,
8+
Boolean,
9+
Array,
10+
ArrayStart,
11+
Player,
12+
Function,
13+
}
1414
}

0 commit comments

Comments
 (0)