Skip to content

Commit

Permalink
Remove unnecessary src folder prepend in useShapeWriter
Browse files Browse the repository at this point in the history
The SymbolProvider(SymbolVisitor) also includes the src folder, so this is
unnecessary.
  • Loading branch information
gosar authored and srchase committed Mar 17, 2023
1 parent e96e49c commit 527e3e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ void useShapeWriter(Shape shape, Consumer<TypeScriptWriter> writerConsumer) {
// Checkout/create the appropriate writer for the shape.
Symbol symbol = symbolProvider.toSymbol(shape);
String fileName = symbol.getDefinitionFile();
if (!fileName.startsWith(Paths.get(".", CodegenUtils.SOURCE_FOLDER).toString())) {
fileName = Paths.get(".", CodegenUtils.SOURCE_FOLDER, fileName).toString();
}
TypeScriptWriter writer = checkoutWriter(fileName);

// Add any needed DECLARE symbols.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.build.MockManifest;
import software.amazon.smithy.build.PluginContext;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
Expand All @@ -36,10 +35,10 @@ public void generatesRuntimeConfigFiles() {

// Did we generate the runtime config files?
// note that asserting the contents of runtime config files is handled in its own unit tests.
Assertions.assertTrue(manifest.hasFile("package.json"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/index.ts"));
assertTrue(manifest.hasFile("package.json"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/index.ts"));

// Does the package.json file point to the runtime config?
String packageJsonContents = manifest.getFileString("package.json").get();
Expand Down Expand Up @@ -69,8 +68,8 @@ public void decoratesSymbolProvider() {

new TypeScriptCodegenPlugin().execute(context);

Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/Foo.ts"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Foo.ts").get(), containsString("export class Foo"));
assertTrue(manifest.hasFile("Foo.ts"));
assertThat(manifest.getFileString("Foo.ts").get(), containsString("export class Foo"));
}

@Test
Expand All @@ -91,11 +90,11 @@ public void generatesServiceClients() {
.build();
new TypeScriptCodegenPlugin().execute(context);

Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/Example.ts"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/Example.ts"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Example.ts").get(),
containsString("export class Example extends ExampleClient"));

Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/ExampleClient.ts"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/ExampleClient.ts"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/ExampleClient.ts").get(), containsString("export class ExampleClient"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package software.amazon.smithy.typescript.codegen;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;

import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.build.MockManifest;
import software.amazon.smithy.codegen.core.Symbol;
Expand All @@ -11,13 +17,6 @@
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.Pair;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;

public class TypeScriptDelegatorTest {
@Test
public void vendsWritersForShapes() {
Expand All @@ -32,7 +31,7 @@ public void vendsWritersForShapes() {
delegator.useShapeWriter(fooShape, writer -> writer.write("Hello!"));
delegator.flushWriters();

assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Foo.txt").get(), equalTo("Hello!\n"));
assertThat(manifest.getFileString("Foo.txt").get(), equalTo("Hello!\n"));
}

@Test
Expand Down Expand Up @@ -61,7 +60,7 @@ public void appendsToOpenedWriterWithNewline() {
delegator.useShapeWriter(fooShape, writer -> writer.write("Goodbye!"));
delegator.flushWriters();

assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Foo.txt").get(), equalTo("Hello!\n\nGoodbye!\n"));
assertThat(manifest.getFileString("Foo.txt").get(), equalTo("Hello!\n\nGoodbye!\n"));
}

@Test
Expand Down

0 comments on commit 527e3e2

Please sign in to comment.