Example #1
0
 @Test
 public void testHypthenatedName() throws RecognitionException, IOException {
   VM vm = new VM(new File("src/test/resources/net/sf/jabref/logic/bst/abbrv.bst"));
   List<BibEntry> v = new ArrayList<>();
   v.add(TestVM.bibtexString2BibtexEntry("@article{canh05, author = \"Jean-Paul Sartre\" }"));
   Assert.assertTrue(vm.run(v).contains("J.-P. Sartre"));
 }
Example #2
0
  @Test
  public void testMissing() throws RecognitionException, IOException {

    VM vm =
        new VM( //
            "ENTRY    { title }  { }  { label } "
                + //
                "FUNCTION {presort} { cite$ 'sort.key$ := } "
                + //
                "ITERATE  {presort} "
                + //
                "READ SORT "
                + //
                "FUNCTION {test}{ title missing$ cite$ } "
                + //
                "ITERATE  { test }");

    List<BibEntry> v = new ArrayList<>();
    v.add(t1BibtexEntry());
    v.add(TestVM.bibtexString2BibtexEntry("@article{test, author=\"No title\"}"));
    vm.run(v);

    Assert.assertEquals(4, vm.getStack().size());

    Assert.assertEquals("test", vm.getStack().pop());
    Assert.assertEquals(1, vm.getStack().pop());
    Assert.assertEquals("canh05", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().pop());
  }
Example #3
0
  @Test
  public void testIterate() throws RecognitionException, IOException {

    VM vm =
        new VM(
            "ENTRY  { "
                + "  address "
                + "  author "
                + "  title "
                + "  type "
                + "}  {}  { label } "
                + "FUNCTION {test}{ cite$ } "
                + "READ "
                + "ITERATE { test }");

    List<BibEntry> v = new ArrayList<>();
    v.add(t1BibtexEntry());

    v.add(TestVM.bibtexString2BibtexEntry("@article{test, title=\"BLA\"}"));

    vm.run(v);

    Assert.assertEquals(2, vm.getStack().size());

    String s1 = (String) vm.getStack().pop();
    String s2 = (String) vm.getStack().pop();

    if ("canh05".equals(s1)) {
      Assert.assertEquals("test", s2);
    } else {
      Assert.assertEquals("canh05", s2);
      Assert.assertEquals("test", s1);
    }
  }
Example #4
0
  @Test
  public void testEmpty() throws RecognitionException, IOException {
    VM vm =
        new VM(
            "ENTRY {title}{}{} READ STRINGS { s } FUNCTION {test} "
                + "{ s empty$ "
                + // FALSE
                "\"\" empty$ "
                + // FALSE
                "\"   \" empty$ "
                + // FALSE
                " title empty$ "
                + // FALSE
                " \" HALLO \" empty$ } ITERATE {test} ");

    List<BibEntry> v = new ArrayList<>();
    v.add(TestVM.bibtexString2BibtexEntry("@article{a, author=\"AAA\"}"));
    vm.run(v);
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #5
0
  @Test
  public void testType() throws RecognitionException, IOException {

    VM vm =
        new VM(
            "ENTRY  { title }  { }  { label }"
                + "FUNCTION {presort} { cite$ 'sort.key$ := } ITERATE { presort } SORT FUNCTION {test} { type$ } ITERATE { test }");

    List<BibEntry> v = new ArrayList<>();
    v.add(TestVM.bibtexString2BibtexEntry("@article{a, author=\"AAA\"}"));
    v.add(TestVM.bibtexString2BibtexEntry("@book{b, author=\"BBB\"}"));
    v.add(TestVM.bibtexString2BibtexEntry("@misc{c, author=\"CCC\"}"));
    v.add(TestVM.bibtexString2BibtexEntry("@inproceedings{d, author=\"DDD\"}"));
    vm.run(v);

    Assert.assertEquals(4, vm.getStack().size());
    Assert.assertEquals("inproceedings", vm.getStack().pop());
    Assert.assertEquals("misc", vm.getStack().pop());
    Assert.assertEquals("book", vm.getStack().pop());
    Assert.assertEquals("article", vm.getStack().pop());
  }
Example #6
0
  @Test
  public void testSort() throws RecognitionException, IOException {

    VM vm =
        new VM(
            "ENTRY  { title }  { }  { label }"
                + "FUNCTION {presort} { cite$ 'sort.key$ := } ITERATE { presort } SORT");

    List<BibEntry> v = new ArrayList<>();
    v.add(TestVM.bibtexString2BibtexEntry("@article{a, author=\"AAA\"}"));
    v.add(TestVM.bibtexString2BibtexEntry("@article{b, author=\"BBB\"}"));
    v.add(TestVM.bibtexString2BibtexEntry("@article{d, author=\"DDD\"}"));
    v.add(TestVM.bibtexString2BibtexEntry("@article{c, author=\"CCC\"}"));
    vm.run(v);

    List<BstEntry> v2 = vm.getEntries();
    Assert.assertEquals("a", v2.get(0).getBibtexEntry().getCiteKey());
    Assert.assertEquals("b", v2.get(1).getBibtexEntry().getCiteKey());
    Assert.assertEquals("c", v2.get(2).getBibtexEntry().getCiteKey());
    Assert.assertEquals("d", v2.get(3).getBibtexEntry().getCiteKey());
  }
Example #7
0
  @Test
  public void testFormatName2() throws RecognitionException, IOException {
    VM vm =
        new VM(
            "ENTRY  { author }  { }  { label } "
                + "FUNCTION {presort} { cite$ 'sort.key$ := } "
                + "ITERATE { presort } "
                + "READ "
                + "SORT "
                + "FUNCTION {format}{ author #2 \"{vv~}{ll}{, jj}{, f}?\" format.name$ }"
                + "ITERATE {format}");

    List<BibEntry> v = new ArrayList<>();
    v.add(t1BibtexEntry());
    v.add(
        TestVM.bibtexString2BibtexEntry(
            "@book{test, author=\"Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin\"}"));
    vm.run(v);
    Assert.assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J?", vm.getStack().pop());
    Assert.assertEquals("Annabi, H?", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #8
0
  @Test
  public void testCallType() throws RecognitionException, IOException {

    VM vm =
        new VM(
            "ENTRY  { title }  { }  { label } FUNCTION {presort} { cite$ 'sort.key$ := } ITERATE { presort } READ SORT "
                + "FUNCTION {inproceedings}{ \"InProceedings called on \" title * } "
                + "FUNCTION {book}{ \"Book called on \" title * } "
                + " ITERATE { call.type$ }");

    List<BibEntry> v = new ArrayList<>();
    v.add(t1BibtexEntry());
    v.add(TestVM.bibtexString2BibtexEntry("@book{test, title=\"Test\"}"));
    vm.run(v);

    Assert.assertEquals(2, vm.getStack().size());

    Assert.assertEquals("Book called on Test", vm.getStack().pop());
    Assert.assertEquals(
        "InProceedings called on Effective work practices for floss development: A model and propositions",
        vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #9
0
 private BibEntry t1BibtexEntry() throws IOException {
   return TestVM.bibtexString2BibtexEntry(t1BibtexString());
 }