Skip to content
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

Write tags to separate file #238

Merged
merged 4 commits into from
Oct 13, 2023
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
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ obj/
# Plugin files
.ionide/

# Generated analysis files
tests/**/analysis.json

launchSettings.json

# Generated analysis files
/tests/**/*/analysis.json
/tests/**/*/tags.json
3 changes: 2 additions & 1 deletion bin/update-golden-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
# Example:
# ./bin/update-golden-tests.sh

# Generate the up-to-date analysis.json files
# Generate the up-to-date analysis.json and tags.json files
./bin/run-tests-in-docker.sh

# Overwrite the existing files
find tests -name analysis.json -execdir cp analysis.json expected_analysis.json \;
find tests -name tags.json -execdir cp tags.json expected_tags.json \;
24 changes: 22 additions & 2 deletions src/Exercism.Analyzers.CSharp/Output.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ internal static class Output
};

public static void WriteToFile(Options options, Analysis analysis)
{
WriteAnalysisJsonFile(options, analysis);
WriteTagsJsonFile(options, analysis);
}

private static void WriteAnalysisJsonFile(Options options, Analysis analysis)
{
using var fileStream = File.Create(GetAnalysisFilePath(options));
var jsonWriter = new Utf8JsonWriter(fileStream, JsonWriterOptions);
jsonWriter.WriteStartObject();
jsonWriter.WriteComments(analysis.Comments);
jsonWriter.WriteTags(analysis.Tags);
jsonWriter.WriteEndObject();
jsonWriter.Flush();
fileStream.Write(Encoding.UTF8.GetBytes(Environment.NewLine));
Expand Down Expand Up @@ -70,10 +75,25 @@ private static void WriteCommentParameters(this Utf8JsonWriter jsonTextWriter, C

private static void WriteCommentParameter(this Utf8JsonWriter jsonTextWriter, CommentParameter parameter) =>
jsonTextWriter.WriteString(parameter.Key, parameter.Value);

private static void WriteTagsJsonFile(Options options, Analysis analysis)
{
using var fileStream = File.Create(GetTagsFilePath(options));
var jsonWriter = new Utf8JsonWriter(fileStream, JsonWriterOptions);
jsonWriter.WriteStartObject();
jsonWriter.WriteTags(analysis.Tags);
jsonWriter.WriteEndObject();
jsonWriter.Flush();
fileStream.Write(Encoding.UTF8.GetBytes(Environment.NewLine));
}

private static string GetTagsFilePath(Options options) =>
Path.GetFullPath(Path.Combine(options.OutputDirectory, "tags.json"));

private static void WriteTags(this Utf8JsonWriter jsonTextWriter, List<string> tags)
{
jsonTextWriter.WriteStartArray("tags");
jsonTextWriter.WritePropertyName("tags");
jsonTextWriter.WriteStartArray();

foreach (var tag in tags.ToSortedSet())
jsonTextWriter.WriteStringValue(tag);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
{
"comments": [],
"tags": [
"construct:assignment",
"construct:boolean",
"construct:class",
"construct:constructor",
"construct:decimal",
"construct:expression-bodied-member",
"construct:field",
"construct:floating-point-number",
"construct:if",
"construct:lock",
"construct:method",
"construct:parameter",
"construct:property",
"construct:read-only",
"construct:string",
"construct:ternary",
"construct:throw",
"construct:throw-expression",
"construct:using-directive",
"construct:variable",
"construct:visibility-modifiers",
"paradigm:imperative",
"paradigm:object-oriented",
"technique:exceptions",
"technique:locks"
]
"comments": []
}
29 changes: 29 additions & 0 deletions tests/bank-account/approaches/lock-statement/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"tags": [
"construct:assignment",
"construct:boolean",
"construct:class",
"construct:constructor",
"construct:decimal",
"construct:expression-bodied-member",
"construct:field",
"construct:floating-point-number",
"construct:if",
"construct:lock",
"construct:method",
"construct:parameter",
"construct:property",
"construct:read-only",
"construct:string",
"construct:ternary",
"construct:throw",
"construct:throw-expression",
"construct:using-directive",
"construct:variable",
"construct:visibility-modifiers",
"paradigm:imperative",
"paradigm:object-oriented",
"technique:exceptions",
"technique:locks"
]
}
32 changes: 1 addition & 31 deletions tests/bank-account/approaches/mutex/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
{
"comments": [],
"tags": [
"construct:assignment",
"construct:boolean",
"construct:class",
"construct:constructor",
"construct:decimal",
"construct:expression-bodied-member",
"construct:field",
"construct:finally",
"construct:floating-point-number",
"construct:if",
"construct:invocation",
"construct:method",
"construct:parameter",
"construct:property",
"construct:read-only",
"construct:string",
"construct:ternary",
"construct:throw",
"construct:throw-expression",
"construct:try",
"construct:using-directive",
"construct:variable",
"construct:visibility-modifiers",
"paradigm:imperative",
"paradigm:object-oriented",
"technique:exceptions",
"technique:mutexes",
"uses:Mutex"
]
"comments": []
}
32 changes: 32 additions & 0 deletions tests/bank-account/approaches/mutex/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"tags": [
"construct:assignment",
"construct:boolean",
"construct:class",
"construct:constructor",
"construct:decimal",
"construct:expression-bodied-member",
"construct:field",
"construct:finally",
"construct:floating-point-number",
"construct:if",
"construct:invocation",
"construct:method",
"construct:parameter",
"construct:property",
"construct:read-only",
"construct:string",
"construct:ternary",
"construct:throw",
"construct:throw-expression",
"construct:try",
"construct:using-directive",
"construct:variable",
"construct:visibility-modifiers",
"paradigm:imperative",
"paradigm:object-oriented",
"technique:exceptions",
"technique:mutexes",
"uses:Mutex"
]
}
33 changes: 1 addition & 32 deletions tests/bob/approaches/answer-array/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
{
"comments": [],
"tags": [
"construct:add",
"construct:boolean",
"construct:char",
"construct:class",
"construct:field",
"construct:if",
"construct:implicit-conversion",
"construct:indexer",
"construct:initializer",
"construct:int",
"construct:integral-number",
"construct:invocation",
"construct:lambda",
"construct:linq",
"construct:logical-and",
"construct:method",
"construct:number",
"construct:parameter",
"construct:read-only",
"construct:return",
"construct:string",
"construct:ternary",
"construct:using-directive",
"construct:variable",
"construct:visibility-modifiers",
"paradigm:functional",
"paradigm:object-oriented",
"technique:boolean-logic",
"technique:higher-order-functions"
]
"comments": []
}
33 changes: 33 additions & 0 deletions tests/bob/approaches/answer-array/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"tags": [
"construct:add",
"construct:boolean",
"construct:char",
"construct:class",
"construct:field",
"construct:if",
"construct:implicit-conversion",
"construct:indexer",
"construct:initializer",
"construct:int",
"construct:integral-number",
"construct:invocation",
"construct:lambda",
"construct:linq",
"construct:logical-and",
"construct:method",
"construct:number",
"construct:parameter",
"construct:read-only",
"construct:return",
"construct:string",
"construct:ternary",
"construct:using-directive",
"construct:variable",
"construct:visibility-modifiers",
"paradigm:functional",
"paradigm:object-oriented",
"technique:boolean-logic",
"technique:higher-order-functions"
]
}
21 changes: 0 additions & 21 deletions tests/bob/approaches/if/expected_analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,5 @@
"name": "IsSilence"
}
}
],
"tags": [
"construct:boolean",
"construct:char",
"construct:class",
"construct:if",
"construct:implicit-conversion",
"construct:invocation",
"construct:lambda",
"construct:linq",
"construct:logical-and",
"construct:method",
"construct:parameter",
"construct:return",
"construct:string",
"construct:using-directive",
"construct:visibility-modifiers",
"paradigm:functional",
"paradigm:object-oriented",
"technique:boolean-logic",
"technique:higher-order-functions"
]
}
23 changes: 23 additions & 0 deletions tests/bob/approaches/if/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"tags": [
"construct:boolean",
"construct:char",
"construct:class",
"construct:if",
"construct:implicit-conversion",
"construct:invocation",
"construct:lambda",
"construct:linq",
"construct:logical-and",
"construct:method",
"construct:parameter",
"construct:return",
"construct:string",
"construct:using-directive",
"construct:visibility-modifiers",
"paradigm:functional",
"paradigm:object-oriented",
"technique:boolean-logic",
"technique:higher-order-functions"
]
}
18 changes: 0 additions & 18 deletions tests/bob/approaches/regular-expressions/expected_analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,5 @@
"name": "IsSilence"
}
}
],
"tags": [
"construct-verbatim-string",
"construct:boolean",
"construct:class",
"construct:if",
"construct:invocation",
"construct:logical-and",
"construct:method",
"construct:parameter",
"construct:return",
"construct:string",
"construct:using-directive",
"construct:visibility-modifiers",
"paradigm:object-oriented",
"technique:boolean-logic",
"technique:regular-expression",
"uses:Regex"
]
}
20 changes: 20 additions & 0 deletions tests/bob/approaches/regular-expressions/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"tags": [
"construct-verbatim-string",
"construct:boolean",
"construct:class",
"construct:if",
"construct:invocation",
"construct:logical-and",
"construct:method",
"construct:parameter",
"construct:return",
"construct:string",
"construct:using-directive",
"construct:visibility-modifiers",
"paradigm:object-oriented",
"technique:boolean-logic",
"technique:regular-expression",
"uses:Regex"
]
}
28 changes: 1 addition & 27 deletions tests/bob/approaches/switch-on-tuple/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
{
"comments": [],
"tags": [
"construct:boolean",
"construct:char",
"construct:class",
"construct:expression-bodied-member",
"construct:if",
"construct:implicit-conversion",
"construct:invocation",
"construct:lambda",
"construct:linq",
"construct:logical-and",
"construct:method",
"construct:parameter",
"construct:return",
"construct:string",
"construct:switch",
"construct:tuple",
"construct:using-directive",
"construct:variable",
"construct:visibility-modifiers",
"paradigm:functional",
"paradigm:object-oriented",
"technique:boolean-logic",
"technique:higher-order-functions",
"uses:ValueTuple"
]
"comments": []
}
Loading