Skip to content

Commit

Permalink
feat, csharp: Unit Test Generation + IR Bump (#4047)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcb6 authored Jul 21, 2024
1 parent 132ea45 commit c2a09c1
Show file tree
Hide file tree
Showing 665 changed files with 6,900 additions and 6,317 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ generators/**/out
seed/**/gradlew
seed/**/gradlew.bat
seed/**/gradle
generators/csharp/playground/**/obj/

# don't ignore the ruby lib within the playground
!generators/ruby/playground/lib
Expand Down
27 changes: 10 additions & 17 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion generators/csharp/codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@fern-api/fs-utils": "workspace:*",
"@fern-api/generator-commons": "workspace:*",
"@fern-api/logging-execa": "workspace:*",
"@fern-fern/ir-sdk": "^32",
"@fern-fern/ir-sdk": "^51",
"lodash-es": "^4.17.21",
"zod": "^3.22.3"
},
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/asIs/Template.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
22 changes: 22 additions & 0 deletions generators/csharp/codegen/src/asIs/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ jobs:
- name: Build Release
run: dotnet build src -c Release /p:ContinuousIntegrationBuild=true

unit-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- uses: actions/checkout@master

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.x

- name: Install tools
run: |
dotnet tool restore
- name: Run Tests
run: |
dotnet test src
<% if (shouldWritePublishBlock) { %>
publish:
needs: [compile]
Expand Down
5 changes: 3 additions & 2 deletions generators/csharp/codegen/src/ast/Annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ export class Annotation extends AstNode {

public write(writer: Writer): void {
writer.addReference(this.reference);
writer.write(`${this.reference.name}(`);
writer.write(`${this.reference.name}`);
if (this.argument != null) {
writer.write("(");
if (typeof this.argument === "string") {
writer.write(this.argument);
} else {
this.argument.write(writer);
}
writer.write(")");
}
writer.write(")");
}
}
9 changes: 7 additions & 2 deletions generators/csharp/codegen/src/ast/Class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export class Class extends AstNode {
parentClassReference,
interfaceReferences,
isNestedClass,
record
record,
annotations
}: Class.Args) {
super();
this.name = name;
Expand All @@ -84,7 +85,7 @@ export class Class extends AstNode {

this.parentClassReference = parentClassReference;
this.interfaceReferences = interfaceReferences ?? [];

this.annotations = annotations ?? [];
this.reference = new ClassReference({
name: this.name,
namespace: this.namespace
Expand All @@ -111,6 +112,10 @@ export class Class extends AstNode {
this.nestedInterfaces.push(subInterface);
}

public addAnnotation(annotation: Annotation): void {
this.annotations.push(annotation);
}

public write(writer: Writer): void {
if (!this.isNestedClass) {
writer.writeLine(`namespace ${this.namespace};`);
Expand Down
3 changes: 2 additions & 1 deletion generators/csharp/codegen/src/ast/ClassInstantiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ClassInstantiation extends AstNode {
writer.write(`new ${this.classReference.name}`);

if (hasNamedArguments) {
writer.write("{");
writer.write("{ ");
} else {
writer.write("(");
}
Expand All @@ -55,6 +55,7 @@ export class ClassInstantiation extends AstNode {
writer.write(", ");
}
});
writer.writeLine();
writer.dedent();

if (hasNamedArguments) {
Expand Down
20 changes: 20 additions & 0 deletions generators/csharp/codegen/src/ast/CodeBlock.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { execSync } from "child_process";
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";

Expand All @@ -21,4 +22,23 @@ export class CodeBlock extends AstNode {
this.value(writer);
}
}

/**
* function for formatting snippets, useful in testing
*/
public toFormattedSnippet(addSemiColon = true): string {
let codeString = this.toString();
if (addSemiColon) {
codeString += ";";
}
try {
return CodeBlock.formatCSharpCode(codeString);
} catch (e: unknown) {
return codeString;
}
}

private static formatCSharpCode(code: string): string {
return execSync("dotnet csharpier", { input: code, encoding: "utf-8" });
}
}
26 changes: 26 additions & 0 deletions generators/csharp/codegen/src/ast/EnumInstantiation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ClassReference } from "./ClassReference";
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";

export declare namespace EnumInstantiation {
interface Args {
reference: ClassReference;
value: string;
}
}

export class EnumInstantiation extends AstNode {
private reference: ClassReference;
private value: string;

constructor({ reference, value }: EnumInstantiation.Args) {
super();
this.reference = reference;
this.value = value;
}

public write(writer: Writer): void {
writer.writeNode(this.reference);
writer.write(`.${this.value}`);
}
}
Loading

0 comments on commit c2a09c1

Please sign in to comment.