Skip to content

Commit 8d6ce1f

Browse files
Version 1.0.3
1 parent 402d250 commit 8d6ce1f

File tree

120 files changed

+3968
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+3968
-12
lines changed

.github/workflows/publish.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Publish packages
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
publish_nuget:
7+
name: Publish package to the NuGet Gallery
8+
runs-on: ubuntu-latest
9+
defaults:
10+
run:
11+
working-directory: './C Sharp/Object Validator'
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Setup .NET
15+
uses: actions/setup-dotnet@v4
16+
with:
17+
dotnet-version: '8.x'
18+
- name: Publish package
19+
run: |
20+
dotnet pack --configuration Release
21+
dotnet nuget push bin/Release/Quicksilver0218.ObjectValidator.*.nupkg --api-key "$NUGET_KEY" --source https://api.nuget.org/v3/index.json
22+
env:
23+
NUGET_KEY: ${{ secrets.NUGET_KEY }}
24+
publish_maven:
25+
name: Publish package to the Maven Central Repository
26+
runs-on: ubuntu-latest
27+
defaults:
28+
run:
29+
working-directory: './Java/Object Validator'
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Set up Java
33+
uses: actions/setup-java@v4
34+
with:
35+
java-version: '21'
36+
distribution: 'temurin'
37+
- name: Setup Gradle
38+
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
39+
- name: Publish package
40+
run: |
41+
./gradlew clean
42+
./gradlew publish
43+
./gradlew jreleaserDeploy
44+
env:
45+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
46+
GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
47+
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
48+
MAVEN_TOKEN_USERNAME: ${{ secrets.MAVEN_TOKEN_USERNAME }}
49+
MAVEN_TOKEN_PASSWORD: ${{ secrets.MAVEN_TOKEN_PASSWORD }}
50+
publish_npm:
51+
name: Publish package to the npm Public Registry
52+
runs-on: ubuntu-latest
53+
defaults:
54+
run:
55+
working-directory: './TypeScript/Object Validator'
56+
permissions:
57+
contents: read
58+
id-token: write
59+
steps:
60+
- uses: actions/checkout@v4
61+
- name: Setup Node.js
62+
uses: actions/setup-node@v4
63+
with:
64+
node-version: '22.x'
65+
registry-url: 'https://registry.npmjs.org'
66+
- name: Publish package
67+
run: |
68+
npm i
69+
npm publish --provenance --access public
70+
env:
71+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
test_csharp:
8+
name: Test C#
9+
runs-on: ubuntu-latest
10+
defaults:
11+
run:
12+
working-directory: './C Sharp'
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Setup .NET
16+
uses: actions/setup-dotnet@v4
17+
with:
18+
dotnet-version: '8.x'
19+
- name: Test
20+
run: |
21+
dotnet pack "Object Validator"
22+
dotnet nuget locals all --clear
23+
dotnet restore "Object Validator Test"
24+
dotnet test "Object Validator Test"
25+
test_java:
26+
name: Test Java
27+
runs-on: ubuntu-latest
28+
defaults:
29+
run:
30+
working-directory: './Java/Object Validator'
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Setup Java
34+
uses: actions/setup-java@v4
35+
with:
36+
java-version: '21'
37+
distribution: 'temurin'
38+
- name: Setup Gradle
39+
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
40+
- name: Test
41+
run: ./gradlew test
42+
test_typescript:
43+
name: Test TypeScript
44+
runs-on: ubuntu-latest
45+
defaults:
46+
run:
47+
working-directory: './TypeScript/Object Validator'
48+
steps:
49+
- uses: actions/checkout@v4
50+
- name: Setup Node.js
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: '22.x'
54+
- name: Test
55+
run: |
56+
npm i
57+
npm test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/release

C Sharp/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin
2+
obj
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<RootNamespace>ObjectValidatorTest</RootNamespace>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<RestoreSources>$(RestoreSources);../Object Validator/bin/Release;https://api.nuget.org/v3/index.json</RestoreSources>
9+
<IsPackable>false</IsPackable>
10+
<IsTestProject>true</IsTestProject>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
16+
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
17+
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
18+
<PackageReference Include="Quicksilver0218.ObjectValidator" Version="1.0.3" />
19+
<None Include="rules.json">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
26+
</ItemGroup>
27+
28+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Object Validator Test", "Object Validator Test.csproj", "{E6E09BF9-D8A1-4097-A94F-3E36EF8A9FDD}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E6E09BF9-D8A1-4097-A94F-3E36EF8A9FDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E6E09BF9-D8A1-4097-A94F-3E36EF8A9FDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E6E09BF9-D8A1-4097-A94F-3E36EF8A9FDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E6E09BF9-D8A1-4097-A94F-3E36EF8A9FDD}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0E663F42-0F19-4F0D-8336-4B790E6D78A9}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Globalization;
2+
3+
class TestObject
4+
{
5+
public string? testString;
6+
public int testInt;
7+
public bool testBool;
8+
public TestObject2?[]? testArray;
9+
}
10+
11+
class TestObject2
12+
{
13+
public DateTime testDateTime;
14+
15+
public override string ToString()
16+
{
17+
return testDateTime.ToString("s", CultureInfo.InvariantCulture);
18+
}
19+
}
+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using System.Diagnostics;
2+
using Quicksilver.ObjectValidator;
3+
4+
namespace ObjectValidatorTest;
5+
[TestClass]
6+
public class UnitTest1
7+
{
8+
private readonly Validator validator;
9+
private readonly ValidationResult result, ffResult;
10+
private readonly HashSet<int?> failures;
11+
12+
public UnitTest1()
13+
{
14+
validator = new(File.ReadAllText("rules.json"));
15+
TestObject testObject = new() {
16+
testString = "test測試",
17+
testInt = 1,
18+
testBool = true,
19+
testArray = [
20+
null,
21+
new() {
22+
testDateTime = new DateTime(2023, 1, 1)
23+
},
24+
new() {
25+
testDateTime = new DateTime(2024, 1, 1)
26+
}
27+
]
28+
};
29+
Stopwatch stopwatch = Stopwatch.StartNew();
30+
result = validator.Validate(testObject);
31+
stopwatch.Stop();
32+
Console.WriteLine(stopwatch.ElapsedMilliseconds + " ms");
33+
failures = result.failures.Select(f => f.id).ToHashSet();
34+
validator.fastFail = true;
35+
ffResult = validator.Validate(testObject);
36+
}
37+
38+
[TestMethod]
39+
public void TestNull()
40+
{
41+
Assert.IsTrue(failures.Contains(1));
42+
}
43+
44+
[TestMethod]
45+
public void TestIn()
46+
{
47+
Assert.IsFalse(failures.Contains(2));
48+
}
49+
50+
[TestMethod]
51+
public void TestBlank()
52+
{
53+
Assert.IsFalse(failures.Contains(3));
54+
}
55+
56+
[TestMethod]
57+
public void TestRegex()
58+
{
59+
Assert.IsFalse(failures.Contains(4));
60+
}
61+
62+
[TestMethod]
63+
public void TestBytes()
64+
{
65+
Assert.IsTrue(failures.Contains(5));
66+
}
67+
68+
[TestMethod]
69+
public void TestStringLength()
70+
{
71+
Assert.IsFalse(failures.Contains(6));
72+
}
73+
74+
[TestMethod]
75+
public void TestArrayLength()
76+
{
77+
Assert.IsFalse(failures.Contains(7));
78+
}
79+
80+
[TestMethod]
81+
public void TestStringContains()
82+
{
83+
Assert.IsFalse(failures.Contains(8));
84+
}
85+
86+
[TestMethod]
87+
public void TestArrayContains()
88+
{
89+
Assert.IsFalse(failures.Contains(9));
90+
}
91+
92+
[TestMethod]
93+
public void TestRange()
94+
{
95+
Assert.IsFalse(failures.Contains(10));
96+
}
97+
98+
[TestMethod]
99+
public void TestTrue()
100+
{
101+
Assert.IsFalse(failures.Contains(11));
102+
}
103+
104+
[TestMethod]
105+
public void TestAnd1()
106+
{
107+
Assert.IsTrue(failures.Contains(101));
108+
}
109+
110+
[TestMethod]
111+
public void TestOr1()
112+
{
113+
Assert.IsFalse(failures.Contains(102));
114+
}
115+
116+
[TestMethod]
117+
public void TestAnd2()
118+
{
119+
Assert.IsTrue(failures.Contains(103));
120+
}
121+
122+
[TestMethod]
123+
public void TestOr2()
124+
{
125+
Assert.IsFalse(failures.Contains(104));
126+
}
127+
128+
[TestMethod]
129+
public void TestFailedFields()
130+
{
131+
Assert.AreEqual(2, result.failedFields.Count);
132+
Assert.IsTrue(result.failedFields.Contains("testString"));
133+
Assert.IsTrue(result.failedFields.Contains("testArray.*"));
134+
}
135+
136+
[TestMethod]
137+
public void TestFastFail()
138+
{
139+
Assert.AreEqual(1, ffResult.failures.Count);
140+
}
141+
}

0 commit comments

Comments
 (0)