aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-05-18 20:15:44 +0100
committerMichael Williamson <mike@zwobble.org>2017-05-18 20:15:44 +0100
commit62cdf68ff42c1887aac3c639226f878335a39a79 (patch)
tree7208db83cb77ded7a87f44d1ba0edcee99931f2f /src/test
parent81514169b8af735e7f2989f53f3b0920dd7833a3 (diff)
Add anchor on hyperlinks as fragment if present
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
index 4a750a5..2eaa16f 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
@@ -729,7 +729,7 @@ public class BodyXmlTests {
}
@Test
- public void hyperlinkIsReadIfItHasARelationshipId() {
+ public void hyperlinkIsReadAsExternalHyperlinkIfItHasARelationshipId() {
Relationships relationships = new Relationships(
map("r42", new Relationship("http://example.com")));
XmlElement element = element("w:hyperlink", map("r:id", "r42"), list(runXml(list())));
@@ -739,7 +739,29 @@ public class BodyXmlTests {
}
@Test
- public void hyperlinkIsReadIfItHasAnAnchorAttribute() {
+ public void hyperlinkIsReadAsExternalHyperlinkIfItHasARelationshipIdAndAnAnchor() {
+ Relationships relationships = new Relationships(
+ map("r42", new Relationship("http://example.com/"))
+ );
+ XmlElement element = element("w:hyperlink", map("r:id", "r42", "w:anchor", "fragment"), list(runXml(list())));
+ assertThat(
+ readSuccess(bodyReader(relationships), element),
+ deepEquals(Hyperlink.href("http://example.com/#fragment", list(run(withChildren())))));
+ }
+
+ @Test
+ public void hyperlinkExistingFragmentIsReplacedWhenAnchorIsSetOnExternalLink() {
+ Relationships relationships = new Relationships(
+ map("r42", new Relationship("http://example.com/#previous"))
+ );
+ XmlElement element = element("w:hyperlink", map("r:id", "r42", "w:anchor", "fragment"), list(runXml(list())));
+ assertThat(
+ readSuccess(bodyReader(relationships), element),
+ deepEquals(Hyperlink.href("http://example.com/#fragment", list(run(withChildren())))));
+ }
+
+ @Test
+ public void hyperlinkIsReadAsInternalHyperlinkIfItHasAnAnchorAttribute() {
XmlElement element = element("w:hyperlink", map("w:anchor", "start"), list(runXml(list())));
assertThat(
readSuccess(bodyReader(), element),