Skip to content

Commit

Permalink
Bug 582486 Improve help for queries
Browse files Browse the repository at this point in the history
Check anchors etc.

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=582486
Change-Id: I519868c5f3982e29a94708f736c66cf70310f3d7
  • Loading branch information
ajohnson1 committed Oct 1, 2023
1 parent 8c49ad1 commit 615b4c5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.mat.query.IQuery;
import org.eclipse.mat.query.IQueryContext;
import org.eclipse.mat.query.annotations.Argument.Advice;
import org.eclipse.mat.query.annotations.Category;
import org.eclipse.mat.query.registry.ArgumentDescriptor;
import org.eclipse.mat.query.registry.QueryDescriptor;
import org.eclipse.mat.query.registry.QueryRegistry;
Expand Down Expand Up @@ -130,12 +131,19 @@ public void testHelpUrl() throws MalformedURLException, IOException
// Tests don't have help
assumeThat(qd.getCommandType().getName(),not(startsWith("org.eclipse.mat.tests.")));
// Not all queries have help yet, so skip rather than fail those.
assumeThat("Normally should be some help", helpUrl, not(nullValue()));
if (Category.HIDDEN.equals(qd.getCategory()))
{
assumeThat("Normally should be some help", helpUrl, not(nullValue()));
}
else
{
assertThat("Should be some help", helpUrl, not(nullValue()));
}
// All the help is currently in the help plugin
assertThat(helpUrl, startsWith("/org.eclipse.mat.ui.help/"));
URL url = new URL(new URL("platform:/plugin/"), helpUrl.substring(1));
URL url2 = FileLocator.find(url);
assertThat(url2, not(nullValue()));
assertThat("Should find help URL in bundle "+url, url2, not(nullValue()));
String encoding = StandardCharsets.UTF_8.name();
String s;
try (InputStream is = url2.openStream();
Expand All @@ -151,6 +159,9 @@ public void testHelpUrl() throws MalformedURLException, IOException
s = sb.toString();
}
GeneralSnapshotTests.basicHTMLcheck(url2, s, encoding);
String anchor = url.getRef();
if (anchor != null)
GeneralSnapshotTests.checkAnchor(url2, url, anchor, s);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,22 +909,7 @@ public void checkHTMLFile(File f, Map<File, String>seen, String anchor, File ref
{
if (anchor.length() > 0)
{
// The fragment should exist as an id or name
Pattern p = Pattern.compile(" (id|name)=\"" + Pattern.quote(anchor) + "\"");
Matcher m = p.matcher(s);
String v;
int id = 0;
int name = 0;
while (m.find())
{
if ("id".equals(m.group(1)))
++id;
else if ("name".equals(m.group(1)))
++name;
}
if (id == 0 && name > 0)
id = 1;
assertThat(f + " from " + referrer + " Expected anchor "+ anchor + " to occur once: " + s, id, equalTo(1));
checkAnchor(f.toURI().toURL(), referrer.toURI().toURL(), anchor, s);
}
seen.put(new File(canonfile.getPath() + "#" + anchor), s);
if (seenFile)
Expand Down Expand Up @@ -1053,6 +1038,26 @@ else if (link.getType() == QueryObjectLink.Type.DETAIL_RESULT)
}
}

static void checkAnchor(URL f, URL referrer, String anchor, String s)
{
// The fragment should exist as an id or name
Pattern p = Pattern.compile(" (id|name)=\"" + Pattern.quote(anchor) + "\"");
Matcher m = p.matcher(s);
String v;
int id = 0;
int name = 0;
while (m.find())
{
if ("id".equals(m.group(1)))
++id;
else if ("name".equals(m.group(1)))
++name;
}
if (id == 0 && name > 0)
id = 1;
assertThat(f + " from " + referrer + " Expected anchor "+ anchor + " to occur once: " + s, id, equalTo(1));
}

static void basicHTMLcheck(URL f, String s, String encoding)
{
// Some basic checks
Expand Down

0 comments on commit 615b4c5

Please sign in to comment.