Skip to content

Commit

Permalink
Fixes #754
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Feb 22, 2018
1 parent feb7b51 commit 387e1e8
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,26 @@ public class RenderingEscapeUtils {

/**
* Produces an "escaped" rendering. If the original rendering contains
* spaces, the returned value is the original rendering enclosed in
* spaces, braces, brackets or commas, and various other symbols used as delimeters in the
* Manchester syntax parser then the returned value is the original rendering enclosed in
* single quotes.
* @param originalRendering The rendering to be escaped
* @return The escaped rendering.
*/
public static String getEscapedRendering(String originalRendering) {
if (originalRendering.indexOf(' ') != -1 || originalRendering.indexOf('(') != -1 || originalRendering.indexOf(
')') != -1) {
if (originalRendering.indexOf(' ') != -1
|| originalRendering.indexOf(',') != -1
|| originalRendering.indexOf('<') != -1
|| originalRendering.indexOf('>') != -1
|| originalRendering.indexOf('=') != -1
|| originalRendering.indexOf('^') != -1
|| originalRendering.indexOf('@') != -1
|| originalRendering.indexOf('{') != -1
|| originalRendering.indexOf('}') != -1
|| originalRendering.indexOf('[') != -1
|| originalRendering.indexOf(']') != -1
|| originalRendering.indexOf('(') != -1
|| originalRendering.indexOf(')') != -1) {
return "'" + originalRendering + "'";
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.protege.editor.owl.ui.renderer;

import org.hamcrest.Matchers;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 21 Feb 2018
*/
public class RenderingEscapeUtils_TestCase {

@Test
public void shouldNotEscapeRendering() {
String rendering = RenderingEscapeUtils.getEscapedRendering("AB");
assertThat(rendering, is("AB"));
}

@Test
public void shouldEscapeRenderingContainingSpace() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A B");
assertThat(rendering, is("'A B'"));
}

@Test
public void shouldEscapeRenderingContainingComma() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A,B");
assertThat(rendering, is("'A,B'"));
}

@Test
public void shouldEscapeRenderingContainingLeftBracket() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A(B");
assertThat(rendering, is("'A(B'"));
}

@Test
public void shouldEscapeRenderingContainingRightBracket() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A)B");
assertThat(rendering, is("'A)B'"));
}

@Test
public void shouldEscapeRenderingContainingLeftSquareBracket() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A[B");
assertThat(rendering, is("'A[B'"));
}

@Test
public void shouldEscapeRenderingContainingRightSquareBracket() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A]B");
assertThat(rendering, is("'A]B'"));
}

@Test
public void shouldEscapeRenderingContainingLeftBrace() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A{B");
assertThat(rendering, is("'A{B'"));
}

@Test
public void shouldEscapeRenderingContainingRightBrace() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A}B");
assertThat(rendering, is("'A}B'"));
}

@Test
public void shouldEscapeRenderingContainingHat() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A^B");
assertThat(rendering, is("'A^B'"));
}

@Test
public void shouldEscapeRenderingContainingAt() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A@B");
assertThat(rendering, is("'A@B'"));
}

@Test
public void shouldEscapeRenderingContainingLessThan() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A<B");
assertThat(rendering, is("'A<B'"));
}

@Test
public void shouldEscapeRenderingContainingGreaterThan() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A>B");
assertThat(rendering, is("'A>B'"));
}

@Test
public void shouldEscapeRenderingContainingEquals() {
String rendering = RenderingEscapeUtils.getEscapedRendering("A=B");
assertThat(rendering, is("'A=B'"));
}
}

0 comments on commit 387e1e8

Please sign in to comment.