Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull Command and ParseCommand out of MMPatchLoader
Would be nice if enums allowed static methods
- Loading branch information
1 parent
80cefc3
commit a9a990d
Showing
6 changed files
with
184 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace ModuleManager | ||
{ | ||
public enum Command | ||
{ | ||
Insert, | ||
|
||
Delete, | ||
|
||
Edit, | ||
|
||
Replace, | ||
|
||
Copy, | ||
|
||
Rename, | ||
|
||
Paste, | ||
|
||
Special, | ||
|
||
Create | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace ModuleManager | ||
{ | ||
public static class CommandParser | ||
{ | ||
public static Command Parse(string name, out string valueName) | ||
{ | ||
if (name.Length == 0) | ||
{ | ||
valueName = string.Empty; | ||
return Command.Insert; | ||
} | ||
Command ret; | ||
switch (name[0]) | ||
{ | ||
case '@': | ||
ret = Command.Edit; | ||
break; | ||
|
||
case '%': | ||
ret = Command.Replace; | ||
break; | ||
|
||
case '-': | ||
case '!': | ||
ret = Command.Delete; | ||
break; | ||
|
||
case '+': | ||
case '$': | ||
ret = Command.Copy; | ||
break; | ||
|
||
case '|': | ||
ret = Command.Rename; | ||
break; | ||
|
||
case '#': | ||
ret = Command.Paste; | ||
break; | ||
|
||
case '*': | ||
ret = Command.Special; | ||
break; | ||
|
||
case '&': | ||
ret = Command.Create; | ||
break; | ||
|
||
default: | ||
valueName = name; | ||
return Command.Insert; | ||
} | ||
valueName = name.Substring(1); | ||
return ret; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Xunit; | ||
using ModuleManager; | ||
|
||
namespace ModuleManagerTests | ||
{ | ||
public class CommandParserTest | ||
{ | ||
[Fact] | ||
public void TestParse__Insert() | ||
{ | ||
Assert.Equal(Command.Insert, CommandParser.Parse("PART", out string newName)); | ||
Assert.Equal("PART", newName); | ||
} | ||
|
||
[Fact] | ||
public void TestParse__Delete() | ||
{ | ||
Assert.Equal(Command.Delete, CommandParser.Parse("!PART", out string newName1)); | ||
Assert.Equal("PART", newName1); | ||
Assert.Equal(Command.Delete, CommandParser.Parse("-PART", out string newName2)); | ||
Assert.Equal("PART", newName2); | ||
} | ||
|
||
[Fact] | ||
public void TestParse__Edit() | ||
{ | ||
Assert.Equal(Command.Edit, CommandParser.Parse("@PART", out string newName)); | ||
Assert.Equal("PART", newName); | ||
} | ||
|
||
[Fact] | ||
public void TestParse__Replace() | ||
{ | ||
Assert.Equal(Command.Replace, CommandParser.Parse("%PART", out string newName)); | ||
Assert.Equal("PART", newName); | ||
} | ||
|
||
[Fact] | ||
public void TestParse__Copy() | ||
{ | ||
Assert.Equal(Command.Copy, CommandParser.Parse("+PART", out string newName1)); | ||
Assert.Equal("PART", newName1); | ||
Assert.Equal(Command.Copy, CommandParser.Parse("$PART", out string newName2)); | ||
Assert.Equal("PART", newName2); | ||
} | ||
|
||
[Fact] | ||
public void TestParse__Rename() | ||
{ | ||
Assert.Equal(Command.Rename, CommandParser.Parse("|PART", out string newName)); | ||
Assert.Equal("PART", newName); ; | ||
} | ||
|
||
[Fact] | ||
public void TestParse__Paste() | ||
{ | ||
Assert.Equal(Command.Paste, CommandParser.Parse("#PART", out string newName)); | ||
Assert.Equal("PART", newName); | ||
} | ||
|
||
[Fact] | ||
public void TestParse__Special() | ||
{ | ||
Assert.Equal(Command.Special, CommandParser.Parse("*PART", out string newName)); | ||
Assert.Equal("PART", newName); | ||
} | ||
|
||
[Fact] | ||
public void TestParse__Special__Chained() | ||
{ | ||
Assert.Equal(Command.Special, CommandParser.Parse("*@PART", out string newName)); | ||
Assert.Equal("@PART", newName); | ||
} | ||
|
||
[Fact] | ||
public void TestParse__Create() | ||
{ | ||
Assert.Equal(Command.Create, CommandParser.Parse("&PART", out string newName)); | ||
Assert.Equal("PART", newName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters