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

Fix incorrect file name regex logic #21

Merged
merged 5 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,13 @@ private static boolean fileContentEquals(File file, String code) throws IOExcept
}
return false;
}

private static String getDebugFileName( String file ) {
String result = file.replace( ".js", "-debug.js");
return result;
int extensionIndex = file.lastIndexOf( ".js" );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file.replaceFirst(".js$", "-debug.js"); might be a better way to express this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better! 👍
Applied in 9eb5223


if ( extensionIndex != -1 && file.endsWith(".js") ) {
return file.substring(0, extensionIndex) + "-debug.js";
}
return file;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.softwarementors.extjs.djn.jscodegen;
dbradicich marked this conversation as resolved.
Show resolved Hide resolved

import org.testng.annotations.Test;

import java.lang.reflect.Method;

import static org.testng.Assert.*;

public class CodeFileGeneratorTest {

private String getDebugFileName(String file) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just make getDebugFileName package protected (no modifier) instead of using reflection to invoke for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused because I didn't know the test rules of the project, but it's good that I can use protected function. 👍
Applied in 68d3969

try {
Method method = CodeFileGenerator.class.getDeclaredMethod("getDebugFileName", String.class);
method.setAccessible(true);
Object result = method.invoke(null, file);
return (String) result;
} catch (Exception e) {
e.printStackTrace();
return "";
}
}

@Test
public void getDebugFileNameTest() {
assertEquals(
"john.jspiner",
getDebugFileName("john.jspiner")
);
assertEquals(
"app-debug.js",
getDebugFileName("app.js")
);
}
}