Skip to content

Commit

Permalink
Merge pull request #96 from stengerh/fix-anchorlink-style
Browse files Browse the repository at this point in the history
Add missing entries in font and color settings
  • Loading branch information
madflow committed Jul 26, 2015
2 parents 484a679 + 17dff37 commit a80b67b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/flow/netbeans/markdown/resources/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Services/MIMEResolver/MarkdownResolver.xml=Markdown Files
Templates/Other/MarkdownTemplate.md=Markdown file
Editors/text/x-markdown=Markdown
text/x-markdown=Markdown
abbreviation=Abbreviation
autolink=Autolink
anchorlink=Anchor Link
blockquote=Block Quote
bulletlist=Bullet List
code=Code
Expand Down
2 changes: 2 additions & 0 deletions src/flow/netbeans/markdown/resources/FontAndColors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontscolors PUBLIC "-//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN" "http://www.netbeans.org/dtds/EditorFontsColors-1_1.dtd">
<fontscolors>
<fontcolor name='abbreviation' />
<fontcolor name='autolink' default='link' />
<fontcolor name='anchorlink' default='link' />
<fontcolor name='blockquote' default='comment' />
<fontcolor name='bulletlist' default='keyword' />
<fontcolor name='code' default='comment' />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package flow.netbeans.markdown.highlighter;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
* The unit tests in this class verify that all token IDs are correctly
* registered in the editor font and color settings.
*
* @author Holger Stenger
*/
@RunWith(Parameterized.class)
public class MarkdownTokenIdTest {

private static final String FONT_AND_COLORS_PATH = "flow/netbeans/markdown/resources/FontAndColors.xml";

private static final String BUNDLE_PATH = "flow/netbeans/markdown/resources/Bundle.properties";

private static Document fontAndColorsDoc;
private static Properties props;

private final MarkdownTokenId tokenId;

public MarkdownTokenIdTest(final MarkdownTokenId tokenId) {
this.tokenId = tokenId;
}

@Parameterized.Parameters
public static Collection<Object[]> getParameters() {
Collection<Object[]> parameters = new ArrayList<Object[]>();
for (MarkdownTokenId tokenId : MarkdownTokenId.values()) {
parameters.add(new Object[]{tokenId});
}
return parameters;
}

@BeforeClass
public static void readFontAndColorsXML() throws SAXException, IOException, ParserConfigurationException {
InputStream stream = MarkdownTokenIdTest.class.getClassLoader().getResourceAsStream(FONT_AND_COLORS_PATH);
assertNotNull("input stream for FontAndColors.xml", stream);
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
fontAndColorsDoc = docBuilder.parse(stream);
} finally {
try {
stream.close();
} catch (IOException ex) {
}
}
}

@BeforeClass
public static void readBundleProperties() throws IOException {
InputStream stream = MarkdownTokenIdTest.class.getClassLoader().getResourceAsStream(BUNDLE_PATH);
assertNotNull("input stream for Bundle.properties", stream);
try {
props = new Properties();
props.load(stream);
} finally {
try {
stream.close();
} catch (IOException ex) {
}
}
}

@Test
public void testFontAndColorsContainsEntryForPrimaryCategory() throws XPathExpressionException {
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/fontscolors/fontcolor[@name='" + tokenId.primaryCategory() + "']";
NodeList nodes = (NodeList) xpath.evaluate(expression, fontAndColorsDoc.getDocumentElement(), XPathConstants.NODESET);
assertEquals(tokenId.toString(), 1, nodes.getLength());
}

@Test
public void testBundleDefinesDisplayNameForPrimaryCategory() {
String displayName = props.getProperty(tokenId.primaryCategory());
assertNotNull(tokenId.toString(), displayName);
}
}

0 comments on commit a80b67b

Please sign in to comment.