Skip to content

Commit

Permalink
Merge pull request #14 from relogiclabs/develop
Browse files Browse the repository at this point in the history
Add Scripting Functionalities
  • Loading branch information
zhossain-info committed Mar 25, 2024
2 parents 958b3b9 + 164b490 commit e5d0b6a
Show file tree
Hide file tree
Showing 604 changed files with 39,479 additions and 22,885 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
JsonSchema/doc/** linguist-documentation
JSchema/doc/** linguist-documentation
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: './JsonSchema/doc'
path: './JSchema/doc'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/.idea/*
/JsonSchema/bin/*
/JsonSchema/obj/*
/JsonSchema/.vscode/*
/JsonSchema.Tests/bin/*
/JsonSchema.Tests/obj/*
/JsonSchema.Tests/.vscode/*
/JSchema/bin/*
/JSchema/obj/*
/JSchema/.vscode/*
/JSchema.Tests/bin/*
/JSchema.Tests/obj/*
/JSchema.Tests/.vscode/*
/Temp*
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>RelogicLabs.JsonSchema.Tests</AssemblyName>
<Description>This project contains test cases for JsonSchema project.</Description>
<AssemblyName>RelogicLabs.JSchema.Tests</AssemblyName>
<Description>This project contains test cases for JSchema project.</Description>
<Authors>Relogic Labs</Authors>
<Company>Relogic Labs</Company>
<Version>1.12.1</Version>
<AssemblyVersion>1.12.1</AssemblyVersion>
<Version>2.0.0</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<Copyright>Copyright © Relogic Labs. All rights reserved.</Copyright>
<NeutralLanguage>en</NeutralLanguage>
<TargetFrameworks>net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
Expand All @@ -18,14 +18,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="coverlet.collector" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\JsonSchema\JsonSchema.csproj" />
<ProjectReference Include="..\JSchema\JSchema.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using RelogicLabs.JsonSchema.Functions;
using RelogicLabs.JsonSchema.Tree;
using RelogicLabs.JsonSchema.Types;
using RelogicLabs.JSchema.Functions;
using RelogicLabs.JSchema.Tree;
using RelogicLabs.JSchema.Nodes;

// Functions for negative (error) test cases
namespace RelogicLabs.JsonSchema.Tests.External;
namespace RelogicLabs.JSchema.Tests.External;

public class ExternalFunctions1
{
Expand All @@ -15,7 +15,7 @@ public bool Odd(JNumber target)
}
}

public class ExternalFunctions2 : FunctionBase
public class ExternalFunctions2 : FunctionProvider
{
public ExternalFunctions2(RuntimeContext runtime) : base(runtime) { }

Expand All @@ -26,25 +26,25 @@ public void Odd(JNumber target)
}
}

public class ExternalFunctions3 : FunctionBase
public class ExternalFunctions3 : FunctionProvider
{
public ExternalFunctions3(RuntimeContext runtime) : base(runtime) { }

public bool Odd() => throw new InvalidOperationException();
}

public class ExternalFunctions4 : FunctionBase
public class ExternalFunctions4 : FunctionProvider
{
public ExternalFunctions4(RuntimeContext runtime) : base(runtime) { }

public bool CanTest(JNumber target)
{
// If you just want to throw any exception without details
return FailWith(new Exception("something went wrong"));
return Fail(new Exception("something went wrong"));
}
}

public class ExternalFunctions5 : FunctionBase
public class ExternalFunctions5 : FunctionProvider
{
public ExternalFunctions5() : base(null!) { }
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using RelogicLabs.JsonSchema.Exceptions;
using RelogicLabs.JsonSchema.Functions;
using RelogicLabs.JsonSchema.Message;
using RelogicLabs.JsonSchema.Tree;
using RelogicLabs.JsonSchema.Types;
using RelogicLabs.JsonSchema.Utilities;
using RelogicLabs.JSchema.Exceptions;
using RelogicLabs.JSchema.Functions;
using RelogicLabs.JSchema.Message;
using RelogicLabs.JSchema.Tree;
using RelogicLabs.JSchema.Nodes;
using RelogicLabs.JSchema.Utilities;

// Functions for positive (valid) test cases
namespace RelogicLabs.JsonSchema.Tests.External;
namespace RelogicLabs.JSchema.Tests.External;

public class ExternalFunctions : FunctionBase
public class ExternalFunctions : FunctionProvider
{
public const string EVENFUNC01 = "EVENFUNC01";
public const string ERRACCESS01 = "ERRACCESS01";
Expand All @@ -22,9 +22,9 @@ public ExternalFunctions(RuntimeContext runtime) : base(runtime) { }
public bool Even(JNumber target)
{
bool result = target % 2 == 0;
if(!result) return FailWith(new JsonSchemaException(
if(!result) return Fail(new JsonSchemaException(
new ErrorDetail(EVENFUNC01, "Number is not even"),
new ExpectedDetail(Function, "even number"),
new ExpectedDetail(Caller, "even number"),
new ActualDetail(target, $"number {target} is odd")));
return true;
}
Expand All @@ -41,9 +41,9 @@ public bool CanTest(JNumber target, JString str1, JBoolean bool1, params JNumber
public bool CheckAccess(JInteger target, JReceiver userRole)
{
string role = userRole.GetValueNode<JString>();
if(role == "user" && target > 5) return FailWith(new JsonSchemaException(
if(role == "user" && target > 5) return Fail(new JsonSchemaException(
new ErrorDetail(ERRACCESS01, "Data access incompatible with 'user' role"),
new ExpectedDetail(Function, "an access at most 5 for 'user' role"),
new ExpectedDetail(Caller, "an access at most 5 for 'user' role"),
new ActualDetail(target, $"found access {target} which is greater than 5")));
return true;
}
Expand All @@ -53,9 +53,9 @@ public bool Condition(JInteger target, JReceiver receiver)
var threshold = receiver.GetValueNode<JInteger>();
Console.WriteLine("Received threshold: " + threshold);
bool result = threshold < target;
if(!result) return FailWith(new JsonSchemaException(
if(!result) return Fail(new JsonSchemaException(
new ErrorDetail(CONDFUNC01, "Number does not satisfy the condition"),
new ExpectedDetail(Function, $"a number > {threshold} of '{receiver.Name}'"),
new ExpectedDetail(Caller, $"a number > {threshold} of '{receiver.Name}'"),
new ActualDetail(target, $"found number {target} <= {threshold}")));
return result;
}
Expand All @@ -67,17 +67,17 @@ public bool ConditionAll(JInteger target, JReceiver receiver)
Console.WriteLine("Target: " + target);
Console.WriteLine("Received integers: " + values);
bool result = list.All(i => i < target);
if(!result) return FailWith(new JsonSchemaException(
if(!result) return Fail(new JsonSchemaException(
new ErrorDetail(CONDFUNC02, "Number does not satisfy the condition"),
new ExpectedDetail(Function, $"a number > any of {values} of '{receiver.Name}'"),
new ExpectedDetail(Caller, $"a number > any of {values} of '{receiver.Name}'"),
new ActualDetail(target, $"found number {target} <= some of {values}")));
return true;
}

public FutureValidator SumEqual(JInteger target, JReceiver receiver)
public FutureFunction SumEqual(JInteger target, JReceiver receiver)
{
// Capture the current value of the function for future lambda
var caller = Function;
// Capture the current value of the caller
var current = Caller;
return () =>
{
var values = receiver.GetValueNodes<JInteger>();
Expand All @@ -86,18 +86,18 @@ public FutureValidator SumEqual(JInteger target, JReceiver receiver)
Console.WriteLine("Received values: " + expression);
int result = values.Sum(i => (int) i);
if(result != target)
return FailWith(new JsonSchemaException(
return Fail(new JsonSchemaException(
new ErrorDetail(SUMEQUAL01, $"Number != sum of {expression} = {result}"),
new ExpectedDetail(caller, $"a number = sum of numbers {result}"),
new ExpectedDetail(current, $"a number = sum of numbers {result}"),
new ActualDetail(target, $"found number {target} != {result}")));
return true;
};
}

public FutureValidator Minmax(JInteger target, JReceiver min, JReceiver max)
public FutureFunction Minmax(JInteger target, JReceiver min, JReceiver max)
{
// Capture the current value of the function for future lambda
var caller = Function;
// Capture the current value of the caller
var current = Caller;
return () =>
{
var intMin = min.GetValueNode<JInteger>();
Expand All @@ -106,9 +106,9 @@ public FutureValidator Minmax(JInteger target, JReceiver min, JReceiver max)
Console.WriteLine($"Received min: {intMin}, max: {intMax}");
bool result = target >= intMin && target <= intMax;
if(!result)
return FailWith(new JsonSchemaException(
return Fail(new JsonSchemaException(
new ErrorDetail(MINMAX01, "Number is outside of range"),
new ExpectedDetail(caller, $"a number in range [{intMin}, {intMax}]"),
new ExpectedDetail(current, $"a number in range [{intMin}, {intMax}]"),
new ActualDetail(target, $"found number {target} not in range")));
return true;
};
Expand Down
Loading

0 comments on commit e5d0b6a

Please sign in to comment.