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

IEP-982 Test coverage for HintsUtil #791

Merged
merged 1 commit into from
Jul 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@

public class HintsUtil
{

public static List<ReHintPair> getReHintsList()
private HintsUtil()
{
}

File hintsYmFile = new File(getHintsYmlPath());
public static List<ReHintPair> getReHintsList(File hintsYmFile)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

had to change the API for testing

{
List<ReHintPair> reHintsPairArray = new ArrayList<>();
InputStream inputStream = null;
try
Expand Down Expand Up @@ -58,10 +59,10 @@ public static String getHintsYmlPath()
{
return IDFUtil.getIDFPath() + File.separator + "tools" + File.separator + "idf_py_actions" //$NON-NLS-1$ //$NON-NLS-2$
+ File.separator
+ "hints.yml"; // $NON-NLS-3$
+ "hints.yml"; //$NON-NLS-1$
}

private static List<ReHintPair> loadHintsYamlFis(InputStream inputStream) throws FileNotFoundException
private static List<ReHintPair> loadHintsYamlFis(InputStream inputStream)
{
Yaml yaml = new Yaml();
List<ReHintPair> reHintsPairArray = new ArrayList<>();
Expand All @@ -83,7 +84,7 @@ private static List<ReHintPair> loadHintsYamlFis(InputStream inputStream) throws
if (reHintVarsMapList.isEmpty())
{
reHintsPairArray.add(new ReHintPair(String.valueOf(entry.get("re")), //$NON-NLS-1$
String.valueOf(entry.get("hint")))); // $NON-NLS-2$
String.valueOf(entry.get("hint")))); //$NON-NLS-1$
}
}
return reHintsPairArray;
Expand All @@ -92,10 +93,11 @@ private static List<ReHintPair> loadHintsYamlFis(InputStream inputStream) throws
private static String formatEntry(List<String> vars, String entry)
{
int i = 0;
entry = entry.replaceAll("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
entry = entry.replace("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
while (entry.contains("{}")) //$NON-NLS-1$
{
entry = entry.replaceFirst(Pattern.quote("{}"), "{" + i++ + "}"); //$NON-NLS-1$ //$NON-NLS-2$ /$NON-NLS-3$
entry = entry.replaceFirst(Pattern.quote("{}"), "{" + i++ + "}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// /$NON-NLS-3$
}
return MessageFormat.format(entry, vars.toArray());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*******************************************************************************/
package com.espressif.idf.ui.dialogs;

import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void createPartControl(Composite parent)
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout layout = new GridLayout(1, true);
container.setLayout(layout);
reHintsList = HintsUtil.getReHintsList();
reHintsList = HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()));
if (reHintsList.isEmpty())
{
CLabel errorField = new CLabel(container, SWT.H_SCROLL);
Expand Down
Loading
Loading