Skip to content

Added UniOperand Cast and Type Operand Support #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions EasyCommands.Tests/EasyCommands.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@
<Compile Include="ScriptTests\FunctionalTests\Commands\ControlCommandTests.cs" />
<Compile Include="ScriptTests\FunctionalTests\Commands\IterationCommandTests.cs" />
<Compile Include="ScriptTests\FunctionalTests\Commands\ListenCommandTests.cs" />
<Compile Include="ScriptTests\FunctionalTests\Operations\Comparisons\SimpleInvalidComparisonsTests.cs" />
<Compile Include="ScriptTests\FunctionalTests\Operations\RoundOperatorTests.cs" />
<Compile Include="ScriptTests\FunctionalTests\Operations\SimpleTypeOperatorTests.cs" />
<Compile Include="ScriptTests\FunctionalTests\Operations\SimplePowerOperatorTests.cs" />
<Compile Include="ScriptTests\FunctionalTests\Operations\SimpleJoinTests.cs" />
<Compile Include="ScriptTests\FunctionalTests\Operations\SimpleRandomTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EasyCommands.Tests.ScriptTests {
[TestClass]
public class SimpleInvalidComparisonsTests {
[TestMethod]
public void InvalidBooleanComparisons() {
VerifyInvalid("true", "boolean", @"""string""", "string");
VerifyInvalid("true", "boolean", "123", "number");
VerifyInvalid("true", "boolean", "1:2:3", "vector");
VerifyInvalid("true", "boolean", "#FF0000", "color");
VerifyInvalid("true", "boolean", "[1,2,3]", "list");
}

[TestMethod]
public void InvalidNumberComparisons() {
VerifyInvalid("123", "number", "true", "boolean");
VerifyInvalid("123", "number", @"""string""", "string");
VerifyInvalid("123", "number", "#FF0000", "color");
VerifyInvalid("123", "number", "[1,2,3]", "list");
}

[TestMethod]
public void InvalidStringComparisons() {
VerifyInvalid("string", "string", "true", "boolean");
VerifyInvalid("string", "string", "123", "number");
VerifyInvalid("string", "string", "1:2:3", "vector");
VerifyInvalid("string", "string", "#FF0000", "color");
VerifyInvalid("string", "string", "[1,2,3]", "list");
}

[TestMethod]
public void InvalidVectorComparisons() {
VerifyInvalid("1:2:3", "vector", "true", "boolean");
VerifyInvalid("1:2:3", "vector", "string", "string");
VerifyInvalid("1:2:3", "vector", "#FF0000", "color");
VerifyInvalid("1:2:3", "vector", "[1,2,3]", "list");
}

[TestMethod]
public void InvalidColorComparisons() {
VerifyInvalid("#FF0000", "color", "true", "boolean");
VerifyInvalid("#FF0000", "color", "string", "string");
VerifyInvalid("#FF0000", "color", "123", "number");
VerifyInvalid("#FF0000", "color", "1:2:3", "vector");
VerifyInvalid("#FF0000", "color", "[1,2,3]", "list");
}

[TestMethod]
public void InvalidListComparisons() {
VerifyInvalid("([1,2,3])", "list", "true", "boolean");
VerifyInvalid("([1,2,3])", "list", "string", "string");
VerifyInvalid("([1,2,3])", "list", "123", "number");
VerifyInvalid("([1,2,3])", "list", "1:2:3", "vector");
VerifyInvalid("([1,2,3])", "list", "#FF0000", "color");
}

private void VerifyInvalid(string value1, string type1, string value2, string type2) {
using (var test = new ScriptTest("print " + value1 + " = " + value2)) {
test.RunOnce();

Assert.AreEqual("Exception Occurred:", test.Logger[0]);
Assert.AreEqual("Cannot perform operation: compare on types: " + type1 + ", " + type2, test.Logger[1]);
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,40 @@ public void RoundVectorBiOperandWithDigits() {
}
}
#endregion

#region InvalidRounding
[TestMethod]
public void CannotRoundString() {
using (var test = new ScriptTest(@"print ""myString"" rounded")) {

test.RunOnce();

Assert.AreEqual("Exception Occurred:", test.Logger[0]);
Assert.AreEqual("Cannot perform operation: round on type: string", test.Logger[1]);
}
}

[TestMethod]
public void CannotRoundStringToDigits() {
using (var test = new ScriptTest(@"print ""myString"" rounded to 2 digits")) {

test.RunOnce();

Assert.AreEqual("Exception Occurred:", test.Logger[0]);
Assert.AreEqual("Cannot perform operation: round on types: string, number", test.Logger[1]);
}
}

[TestMethod]
public void CannotRoundNumberToStringDigits() {
using (var test = new ScriptTest(@"print 123 rounded to ""myString"" digits")) {

test.RunOnce();

Assert.AreEqual("Exception Occurred:", test.Logger[0]);
Assert.AreEqual("Cannot perform operation: round on types: number, string", test.Logger[1]);
}
}
#endregion
}
}
Loading