예제 #1
0
 @Test
 public void testHypthenatedName() throws RecognitionException, IOException {
   VM vm = new VM(new File("src/test/resources/net/sf/jabref/bst/abbrv.bst"));
   Vector<BibtexEntry> v = new Vector<>();
   v.add(TestVM.bibtexString2BibtexEntry("@article{canh05, author = \"Jean-Paul Sartre\" }"));
   Assert.assertTrue(vm.run(v).contains("J.-P. Sartre"));
 }
예제 #2
0
  @Test
  public void testFormatName() throws RecognitionException, IOException {
    {
      VM vm =
          new VM(
              "FUNCTION {format}{ \"Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin\" #1 \"{vv~}{ll}{, jj}{, f}?\" format.name$ }"
                  + "EXECUTE {format}");

      Vector<BibtexEntry> v = new Vector<>();
      vm.run(v);
      Assert.assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J?", vm.getStack().pop());
      Assert.assertEquals(0, vm.getStack().size());
    }
    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}");

    Vector<BibtexEntry> v = new Vector<>();
    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());
  }
예제 #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 }");

    Vector<BibtexEntry> v = new Vector<>();
    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 (s1.equals("canh05")) {
      Assert.assertEquals("test", s2);
    } else {
      Assert.assertEquals("canh05", s2);
      Assert.assertEquals("test", s1);
    }
  }
예제 #4
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 }");

    Vector<BibtexEntry> v = new Vector<>();
    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());
  }
예제 #5
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} ");

    Vector<BibtexEntry> v = new Vector<>();
    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());
  }
예제 #6
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 }");

    Vector<BibtexEntry> v = new Vector<>();
    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());
  }
예제 #7
0
  @Test
  public void testSort() throws RecognitionException, IOException {

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

    Vector<BibtexEntry> v = new Vector<>();
    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);

    Vector<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());
  }
예제 #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$ }");

    Vector<BibtexEntry> v = new Vector<>();
    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());
  }
예제 #9
0
 BibtexEntry t1BibtexEntry() throws IOException {
   return TestVM.bibtexString2BibtexEntry(t1BibtexString());
 }