From 90b082ff77009a79ff51a972a0fdd548bbd35037 Mon Sep 17 00:00:00 2001 From: Ned Palacios Date: Wed, 20 Mar 2024 21:32:35 +0800 Subject: [PATCH] tests(error_templates): add another test case for public class filename mismatch error --- .../ReverseString.java | 29 ++++++++++++++++ .../test.txt | 33 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 error_templates/java/test_files/public_class_filename_mismatch_error_2/ReverseString.java create mode 100644 error_templates/java/test_files/public_class_filename_mismatch_error_2/test.txt diff --git a/error_templates/java/test_files/public_class_filename_mismatch_error_2/ReverseString.java b/error_templates/java/test_files/public_class_filename_mismatch_error_2/ReverseString.java new file mode 100644 index 0000000..4b790c6 --- /dev/null +++ b/error_templates/java/test_files/public_class_filename_mismatch_error_2/ReverseString.java @@ -0,0 +1,29 @@ +/* +String Reversal Utility + +Description: +You're developing a feature for a text-editing app that reverses the input string from the user. This feature is crucial for certain text manipulation tasks but currently faces runtime exceptions, logic errors, and syntax issues. + +Task: +Correct the issues causing runtime exceptions, logic errors, and syntax issues to ensure the feature can reverse a string successfully. + +Example Output: +"dcba" +*/ + +public class ReverzeString { + public static void main(String[] args) { + String str = "abcd"; + String reversed = reverse(str); + System.out.println(reversal); + } + + public static String reverse(String s) { + String result = ""; + for(int i = s.length(); i >= 0; i--) { + result += s.charAt(i); + } + return result; + } +} + diff --git a/error_templates/java/test_files/public_class_filename_mismatch_error_2/test.txt b/error_templates/java/test_files/public_class_filename_mismatch_error_2/test.txt new file mode 100644 index 0000000..c9a112a --- /dev/null +++ b/error_templates/java/test_files/public_class_filename_mismatch_error_2/test.txt @@ -0,0 +1,33 @@ +name: "2" +template: "Java.PublicClassFilenameMismatchError" +--- +ReverseString.java:14: error: class ReverzeString is public, should be declared in a file named ReverzeString.java +public class ReverzeString { + ^ +1 error +=== +template: "Java.PublicClassFilenameMismatchError" +--- +# PublicClassFilenameMismatchError +This error occurs because the name of the Java file does not match the name of the public class within it. +``` + +public class ReverzeString { + ^^^^^^^^^^^^^ + public static void main(String[] args) { + String str = "abcd"; +``` +## Steps to fix +### 1. Rename your file +Rename the file to "ReverzeString.java" to match the class. + +### 2. Rename the public class +The filename should match the name of the public class in the file. To resolve this, change the class name to match the filename. +```diff +*/ + +- public class ReverzeString { ++ public class ReverseString { + public static void main(String[] args) { + String str = "abcd"; +``` \ No newline at end of file