Skip to content

Commit

Permalink
fix all the tests and improve the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWandererProductions committed Jun 2, 2024
1 parent e77cbae commit 6853076
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 90 deletions.
12 changes: 6 additions & 6 deletions CommonLibraryTests/Interpret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public sealed class Interpret
[TestInitialize]
public void SetUp()
{
_irtPrompt = new IrtPrompt();
_irtPrompt = new IrtPrompt(new Prompt());
_commands = new Dictionary<int, InCommand>
{
{ 1, new InCommand { Command = "COMMAND1", ParameterCount = 0, Description = "Description1" } },
Expand Down Expand Up @@ -358,7 +358,7 @@ private static void SendCommands(object sender, OutCommand e)
public void HandleInputValidCommandNoParameters_Success()
{
var commandHandled = false;
_irtPrompt.sendCommand += (sender, e) =>
_irtPrompt.SendCommand += (sender, e) =>
{
Assert.AreEqual(1, e.Command);
commandHandled = true;
Expand All @@ -376,7 +376,7 @@ public void HandleInputValidCommandNoParameters_Success()
public void HandleInputInvalidCommandLogsError()
{
var logHandled = false;
_irtPrompt.sendLog += (_, e) =>
_irtPrompt.SendLog += (_, e) =>
{
Assert.IsTrue(e.Contains(IrtConst.KeyWordNotFoundError));
logHandled = true;
Expand All @@ -394,7 +394,7 @@ public void HandleInputInvalidCommandLogsError()
public void HandleInputHelpCommandLogsHelp()
{
var logHandled = false;
_irtPrompt.sendLog += (sender, e) =>
_irtPrompt.SendLog += (sender, e) =>
{
Assert.AreEqual(IrtConst.HelpGeneric, e);
logHandled = true;
Expand All @@ -412,7 +412,7 @@ public void HandleInputHelpCommandLogsHelp()
public void HandleInputCommandWithParametersSuccess()
{
var commandHandled = false;
_irtPrompt.sendCommand += (sender, e) =>
_irtPrompt.SendCommand += (sender, e) =>
{
Assert.AreEqual(2, e.Command);
Assert.AreEqual(1, e.Parameter.Count);
Expand All @@ -432,7 +432,7 @@ public void HandleInputCommandWithParametersSuccess()
public void HandleInputCommandWithInvalidParametersLogsError()
{
var logHandled = false;
_irtPrompt.sendLog += (sender, e) =>
_irtPrompt.SendLog += (sender, e) =>
{
Assert.IsTrue(e.Contains(IrtConst.ParenthesisError));
logHandled = true;
Expand Down
5 changes: 1 addition & 4 deletions CommonLibraryTests/InterpretExtension.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using Interpreter;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CommonLibraryTests
{
Expand Down
4 changes: 2 additions & 2 deletions CoreLibrary.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
# Visual Studio Version 16
VisualStudioVersion = 16.0.34729.46
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViewModel", "ViewModel\ViewModel.csproj", "{9B2741D2-443A-4136-B9A4-1191686DA4AD}"
EndProject
Expand Down
2 changes: 2 additions & 0 deletions CoreLibrary.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fda52545_002De1eb_002D4d94_002D9d07_002Dd3c4be883354/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="SpeedConvertCif" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;MSTest::D2D1B7B6-0C94-45F8-BD4E-1FB9A318AC21::net5.0-windows7.0::CommonLibraryTests.Projections.LeftRightBug&lt;/TestId&gt;&#xD;
&lt;TestId&gt;MSTest::D2D1B7B6-0C94-45F8-BD4E-1FB9A318AC21::net5.0-windows7.0::CommonLibraryTests.Interpret.ConsoleInterpreter&lt;/TestId&gt;&#xD;
&lt;TestId&gt;MSTest::D2D1B7B6-0C94-45F8-BD4E-1FB9A318AC21::net5.0-windows7.0::CommonLibraryTests.Interpret.Container&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String>

Expand Down
10 changes: 10 additions & 0 deletions Interpreter/ErrorLogging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Documents;
using ExtendedSystemObjects;

namespace Interpreter
{
Expand All @@ -16,6 +19,11 @@ namespace Interpreter
/// </summary>
internal static class ErrorLogging
{
/// <summary>
/// The log
/// </summary>
internal static List<string> Log = new List<string>();

/// <summary>
/// Error Logging
/// </summary>
Expand Down Expand Up @@ -49,6 +57,8 @@ internal static string SetLastError(string error, int logLvl)
default: return string.Empty;
}

Log.Add(message);

Trace.WriteLine(string.Concat(message, Environment.NewLine));

return message;
Expand Down
12 changes: 9 additions & 3 deletions Interpreter/IPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ internal interface IPrompt
void AddCommands(Dictionary<int, InCommand> com, string userSpace, Dictionary<int, InCommand> extension = null);

/// <summary>
/// Start the window.
/// Start the window. If we want to use the included window.
/// </summary>
void StartWindow();

/// <summary>
/// The callbacks.
/// The callbacks for Window, method messages to the window.
/// </summary>
/// <param name="message">The messages.</param>
void Callbacks(string message);
void CallbacksWindow(string message);

/// <summary>
/// Callbacks the specified message.
/// </summary>
/// <param name="message">The message.</param>
void Callback(string message);

/// <summary>
/// Start the console.
Expand Down
1 change: 0 additions & 1 deletion Interpreter/InCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// ReSharper disable MemberCanBeInternal

using System;
using System.Collections.Generic;

namespace Interpreter
{
Expand Down
29 changes: 23 additions & 6 deletions Interpreter/Irt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,30 @@ var word in
/// <returns>If internal Command was used</returns>
internal static string CheckInternalCommands(string input)
{
foreach (
var enums in
IrtConst.InternalCommands.Where(
enums => input.StartsWith(enums.ToUpper(CultureInfo.InvariantCulture),
StringComparison.Ordinal)))
if (input.Contains(IrtConst.AdvancedOpen))
{
var index = input.IndexOf(IrtConst.AdvancedOpen);

if (index >= 0)
{
input = input[..index];
input = input.Trim();
}
}
else if (input.Contains(IrtConst.BaseOpen))
{
var index = input.IndexOf(IrtConst.BaseOpen);

if (index >= 0)
{
input = input[..index];
input = input.Trim();
}
}

foreach (var command in IrtConst.InternalCommands.Where(command => string.Equals(input, command.ToUpper(CultureInfo.InvariantCulture), StringComparison.Ordinal)))
{
return enums;
return command;
}

return string.Empty;
Expand Down
36 changes: 36 additions & 0 deletions Interpreter/IrtConst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ internal static class IrtConst
/// </summary>
internal const string InternalUse = "USE";

/// <summary>
/// The internal command Log (const). Value: "LOG".
/// </summary>
internal const string InternalErrorLog = "LOG";

/// <summary>
/// The internal command Log info (const). Value: "LOGINFO".
/// </summary>
internal const string InternalLogInfo = "LOGINFO";

/// <summary>
/// The internal command Log full (const). Value: "LOGFULL".
/// </summary>
internal const string InternalLogFull= "LOGFULL";

/// <summary>
/// The error no commands provided (const). Value: "No Commands were provided".
/// </summary>
Expand Down Expand Up @@ -101,6 +116,21 @@ internal static class IrtConst
/// </summary>
internal const string MessageWarning = "Warning: ";

/// <summary>
/// The message error count (const). Value: "Error Count: ".
/// </summary>
internal const string MessageErrorCount = "Error Count: ";

/// <summary>
/// The message log Count (const). Value: "Log Count: ".
/// </summary>
internal const string MessageLogCount = "Log Count: ";

/// <summary>
/// The message log statistics (const). Value: "General Information about the Log.".
/// </summary>
internal const string MessageLogStatistics = "General Information abount the Log.";

/// <summary>
/// The end (const). Value: ";".
/// </summary>
Expand Down Expand Up @@ -175,6 +205,9 @@ internal static class IrtConst
InternalCommandList,
InternalUsing,
InternalUse,
InternalErrorLog,
InternalLogInfo,
InternalLogFull,
InternalCommandContainer,
InternalCommandBatchExecute
};
Expand All @@ -197,6 +230,9 @@ internal static class IrtConst
InternalCommandList, " : List all external Commands", Environment.NewLine,
InternalUsing, " : Current Commands available and the one currently in use", Environment.NewLine,
InternalUse, " : Type use(namespace) to switch to command namespace", Environment.NewLine,
InternalLogInfo, " : statistics about the current log", Environment.NewLine,
InternalErrorLog, " : Enumerate all Error Log entries", Environment.NewLine,
InternalLogFull, " : Enumerate full Log", Environment.NewLine,
InternalCommandContainer,
" : Holds a set of commands and executes them sequential, use Container{Command1; Command2; .... } and ; is the Separator that states that a new command follows."
);
Expand Down
Loading

0 comments on commit 6853076

Please sign in to comment.