CrabUI
Loading...
Searching...
No Matches
SubstringSafe.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
19 public class SubstringSafeTest : UnitTest
20 {
21 public override void Execute(string method = null)
22 {
23 string s = "qwerty";
24 Describe("SubstringSafe(int start, int length)", () =>
25 {
26 Describe("empty string", () =>
27 {
28 Expect("".SubstringSafe(0, 1)).ToBeEqual("");
29 });
30
31 Describe("1 letter", () =>
32 {
33 Expect(s.SubstringSafe(0, 1)).ToBeEqual("q");
34 Expect(s.SubstringSafe(1, 1)).ToBeEqual("w");
35 Expect(s.SubstringSafe(2, 1)).ToBeEqual("e");
36 Expect(s.SubstringSafe(3, 1)).ToBeEqual("r");
37 Expect(s.SubstringSafe(4, 1)).ToBeEqual("t");
38 Expect(s.SubstringSafe(5, 1)).ToBeEqual("y");
39 Expect(s.SubstringSafe(6, 1)).ToBeEqual("");
40 });
41
42 Describe("out of bounds", () =>
43 {
44 Expect(s.SubstringSafe(-100, 6)).ToBeEqual("");
45 Expect(s.SubstringSafe(100, 10)).ToBeEqual("");
46 Expect(s.SubstringSafe(0, 100)).ToBeEqual("qwerty");
47 Expect(s.SubstringSafe(-50, 100)).ToBeEqual("qwerty");
48 Expect(s.SubstringSafe(0, 6)).ToBeEqual("qwerty");
49 });
50 });
51
52 Describe("SubstringSafe(int start)", () =>
53 {
54 Expect("".SubstringSafe(0)).ToBeEqual("");
55 Expect("".SubstringSafe(100)).ToBeEqual("");
56 Expect("".SubstringSafe(-100)).ToBeEqual("");
57 Expect(s.SubstringSafe(-100)).ToBeEqual("qwerty");
58 Expect(s.SubstringSafe(0)).ToBeEqual("qwerty");
59 Expect(s.SubstringSafe(1)).ToBeEqual("werty");
60 Expect(s.SubstringSafe(2)).ToBeEqual("erty");
61 Expect(s.SubstringSafe(3)).ToBeEqual("rty");
62 Expect(s.SubstringSafe(4)).ToBeEqual("ty");
63 Expect(s.SubstringSafe(5)).ToBeEqual("y");
64 Expect(s.SubstringSafe(6)).ToBeEqual("");
65 Expect(s.SubstringSafe(100)).ToBeEqual("");
66 });
67 }
68
69 }
70}