Skip to content

Commit

Permalink
Changes based on comments and a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Jan 2, 2016
1 parent c6cbc3e commit 7680c5c
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String format(String fieldText) {
}

Matcher m = HTMLParagraphs.beforeNewLines.matcher(fieldText);
StringBuffer s = new StringBuffer(19);
StringBuffer s = new StringBuffer(19); // At least 19 characters are appended later
while (m.find()) {
String middle = m.group(1).trim();
if (!middle.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 Jabref-Team
*
* All programs in this directory and subdirectories are published under the GNU
* General Public License as described below.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* Further information about the GNU GPL is available at:
* http://www.gnu.org/copyleft/gpl.ja.html
*
*/
package net.sf.jabref.exporter.layout.format;

import org.junit.Assert;
import org.junit.Test;

public class AuthorFirstFirstCommasTest {

/**
* Test method for
* {@link net.sf.jabref.exporter.layout.format.AuthorLF_FF#format(java.lang.String)}.
*/
@Test
public void testFormat() {
Assert.assertEquals("John von Neumann, John Smith and Peter Black Brown, Jr",
new AuthorFirstFirstCommas()
.format("von Neumann,,John and John Smith and Black Brown, Jr, Peter"));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2006 Jabref-Team
*
*
* All programs in this directory and subdirectories are published under the GNU
* General Public License as described below.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 Jabref-Team
*
* All programs in this directory and subdirectories are published under the GNU
* General Public License as described below.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* Further information about the GNU GPL is available at:
* http://www.gnu.org/copyleft/gpl.ja.html
*
*/
package net.sf.jabref.exporter.layout.format;

import org.junit.Assert;
import org.junit.Test;

public class AuthorLF_FFAbbrTest {

/**
* Test method for
* {@link net.sf.jabref.exporter.layout.format.AuthorLF_FF#format(java.lang.String)}.
*/
@Test
public void testFormat() {
Assert.assertEquals("von Neumann, J. and J. Smith and P. Black Brown, Jr",
new AuthorLF_FFAbbr()
.format("von Neumann,,John and John Smith and Black Brown, Jr, Peter"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 Jabref-Team
*
* All programs in this directory and subdirectories are published under the GNU
* General Public License as described below.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* Further information about the GNU GPL is available at:
* http://www.gnu.org/copyleft/gpl.ja.html
*
*/
package net.sf.jabref.exporter.layout.format;

import org.junit.Assert;
import org.junit.Test;

public class AuthorLF_FFTest {

/**
* Test method for
* {@link net.sf.jabref.exporter.layout.format.AuthorLF_FF#format(java.lang.String)}.
*/
@Test
public void testFormat() {
Assert.assertEquals("von Neumann, John and John Smith and Peter Black Brown, Jr",
new AuthorLF_FF()
.format("von Neumann,,John and John Smith and Black Brown, Jr, Peter"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2015 Jabref-Team
*
* All programs in this directory and subdirectories are published under the GNU
* General Public License as described below.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* Further information about the GNU GPL is available at:
* http://www.gnu.org/copyleft/gpl.ja.html
*
*/
package net.sf.jabref.exporter.layout.format;

import org.junit.Assert;
import org.junit.Test;

public class AuthorNatBibTest {

/**
* Test method for
* {@link net.sf.jabref.exporter.layout.format.AuthorLF_FF#format(java.lang.String)}.
*/
@Test
public void testFormatThreeAuthors() {
Assert.assertEquals("von Neumann et al.",
new AuthorNatBib().format("von Neumann,,John and John Smith and Black Brown, Jr, Peter"));
}

/**
* Test method for
* {@link net.sf.jabref.exporter.layout.format.AuthorLF_FF#format(java.lang.String)}.
*/
@Test
public void testFormatTwoAuthors() {
Assert.assertEquals("von Neumann and Smith", new AuthorNatBib().format("von Neumann,,John and John Smith"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public void testFormat() {
// Works even when having a / at the front
Assert.assertEquals("http://doi.org/10.1145/354401.354407", lf.format("/10.1145/354401.354407"));

// Obviously a wrong doi, will not work.
// Obviously a wrong doi, will not change anything.
Assert.assertEquals("10", lf.format("10"));

// Obviously a wrong doi, will not work.
// Obviously a wrong doi, will not change anything.
Assert.assertEquals("1", lf.format("1"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2015 Jabref-Team
*
* All programs in this directory and subdirectories are published under the GNU
* General Public License as described below.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* Further information about the GNU GPL is available at:
* http://www.gnu.org/copyleft/gpl.ja.html
*
*/

package net.sf.jabref.exporter.layout.format;

import static org.junit.Assert.*;

import org.junit.Test;


public class FormatCharsTest {

@Test
public void testPlainFormat() {
assertEquals("aaa", new FormatChars().format("aaa"));
}

@Test
public void testFormatUmlaut() {
assertEquals("ä", new FormatChars().format("{\\\"{a}}"));
assertEquals("Ä", new FormatChars().format("{\\\"{A}}"));
}

@Test
public void testFormatStripLatexCommands() {
assertEquals("-", new FormatChars().format("\\mbox{-}"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class IfPluralTest {
public void testStandardUsageOneEditor() {
ParamLayoutFormatter a = new IfPlural();
a.setArgument("Eds.,Ed.");
Assert.assertEquals("Eds.", a.format("Bob Bruce and Jolly Jumper"));
Assert.assertEquals("Ed.", a.format("Bob Bruce"));
}

@Test
Expand All @@ -35,6 +35,12 @@ public void testFormatEmpty() {
Assert.assertEquals("", a.format(""));
}

@Test
public void testNoArgumentSet() {
ParamLayoutFormatter a = new IfPlural();
Assert.assertEquals("", a.format("Bob Bruce and Jolly Jumper"));
}

@Test
public void testNoProperArgument() {
ParamLayoutFormatter a = new IfPlural();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ public void testFormatDoubleDash() {
LayoutFormatter a = new LastPage();
Assert.assertEquals("350", a.format("345--350"));
}

@Test
public void testFinalCoverageCase() {
LayoutFormatter a = new LastPage();
Assert.assertEquals("", a.format("--"));
}
}

0 comments on commit 7680c5c

Please sign in to comment.