CrabUI
Loading...
Searching...
No Matches
ParserTest.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Diagnostics;
6using System.Runtime.CompilerServices;
7using System.IO;
8
9using Barotrauma;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Input;
12using Microsoft.Xna.Framework.Graphics;
13using HarmonyLib;
14using CrabUI;
15
16namespace CrabUITest
17{
18 public class ParserTest : UnitTest
19 {
20 public void ParseTest()
21 {
22 Expect(CUIParser.Parse("123", typeof(int))).ToBeEqual(123);
23 Expect(CUIParser.Parse("123", typeof(string))).ToBeEqual("123");
24 Expect(CUIParser.Parse("123", typeof(float))).ToBeEqual(123.0f);
25 Expect(CUIParser.Parse("123", typeof(double))).ToBeEqual(123.0);
26 Expect(CUIParser.Parse("bebe", typeof(double))).ToBeEqual(0.0);
27 Expect(CUIParser.Parse("BoOl", typeof(bool))).ToBeEqual(false);
28 Expect(CUIParser.Parse("TrUe", typeof(bool))).ToBeEqual(true);
29
30 Expect(CUIParser.Parse("Reverse", typeof(CUIDirection))).ToBeEqual(CUIDirection.Reverse);
31 Expect(CUIParser.Parse("Beberse", typeof(CUIDirection))).ToBeEqual(CUIDirection.Straight);
32
33 Expect(CUIParser.Parse("[2,2]", typeof(Vector2))).ToBeEqual(new Vector2(2, 2));
34 Expect(CUIParser.Parse("red", typeof(Color))).ToBeEqual(new Color(255, 0, 0));
35 }
36
37 public void SerializeTest()
38 {
39 Expect(CUIParser.Serialize(new Vector2(2, 2))).ToBeEqual("[2,2]");
40 Expect(CUIParser.Serialize(2)).ToBeEqual("2");
41 Expect(CUIParser.Serialize(2 + 2 == 4)).ToBeEqual("True");
42 Expect(CUIParser.Serialize(Color.Red)).ToBeEqual("255,0,0,255");
43 }
44
45 }
46}
Class for easy parsing and serialization of anything.
Definition CUIParser.cs:19