Example #1
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());
  }
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 }");

    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());
  }
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 }");

    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);
    }
  }
Example #4
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());
  }
Example #5
0
  @Test
  public void testVMExecuteSimple2() throws RecognitionException {
    VM vm =
        new VM(
            "FUNCTION {a}{ #5 #5 = "
                + "#1 #2 = "
                + "#3 #4 < "
                + "#4 #3 < "
                + "#4 #4 < "
                + "#3 #4 > "
                + "#4 #3 > "
                + "#4 #4 > "
                + "\"H\" \"H\" = "
                + "\"H\" \"Ha\" = } "
                + "EXECUTE {a}");

    List<BibEntry> v = new ArrayList<>();
    vm.run(v);

    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #6
0
  @Test
  public void testChangeCase() throws RecognitionException, IOException {
    VM vm =
        new VM(
            "STRINGS { title } "
                + "READ "
                + "FUNCTION {format.title}"
                + " { duplicate$ empty$ "
                + "    { pop$ \"\" } "
                + "    { \"t\" change.case$ } "
                + "  if$ "
                + "} "
                + "FUNCTION {test} {"
                + "  \"hello world\" \"u\" change.case$ format.title "
                + "  \"Hello World\" format.title "
                + "  \"\" format.title "
                + "  \"{A}{D}/{C}ycle: {I}{B}{M}'s {F}ramework for {A}pplication {D}evelopment and {C}ase\" \"u\" change.case$ format.title "
                + "}"
                + "EXECUTE {test} ");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);
    Assert.assertEquals(
        "{A}{D}/{C}ycle: {I}{B}{M}'s {F}ramework for {A}pplication {D}evelopment and {C}ase",
        vm.getStack().pop());
    Assert.assertEquals("", vm.getStack().pop());
    Assert.assertEquals("Hello world", vm.getStack().pop());
    Assert.assertEquals("Hello world", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #7
0
  @Test
  public void testVMChrToIntIntToChr() throws RecognitionException {
    VM vm = new VM("FUNCTION {test} { \"H\" chr.to.int$ int.to.chr$ }" + "EXECUTE {test}");

    List<BibEntry> v = new ArrayList<>();
    vm.run(v);
    Assert.assertEquals("H", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #8
0
  @Test
  public void testVMIntToStr() throws RecognitionException, IOException {
    VM vm = new VM("FUNCTION {test} { #3 int.to.str$ #9999 int.to.str$}" + "EXECUTE {test}");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);
    Assert.assertEquals("9999", vm.getStack().pop());
    Assert.assertEquals("3", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #9
0
  @Test
  public void testBuildIn() throws RecognitionException, IOException {
    VM vm = new VM("EXECUTE {global.max$}");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);

    Assert.assertEquals(Integer.MAX_VALUE, vm.getStack().pop());
    Assert.assertTrue(vm.getStack().empty());
  }
Example #10
0
  @Test
  public void testVMIfSkipPop() throws RecognitionException, IOException {
    VM vm =
        new VM(
            "FUNCTION {not}	{   { #0 }	    { #1 }  if$	}"
                + "FUNCTION {and}	{   'skip$	    { pop$ #0 }	  if$	}"
                + "FUNCTION {or}	{   { pop$ #1 }	    'skip$	  if$	}"
                + "FUNCTION {test} { "
                + "#1 #1 and #0 #1 and #1 #0 and #0 #0 and "
                + "#0 not #1 not "
                + "#1 #1 or #0 #1 or #1 #0 or #0 #0 or }"
                + "EXECUTE {test}");

    Vector<BibtexEntry> v = new Vector<>();
    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.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #11
0
  @Test
  public void testVMArithmetic() throws RecognitionException {

    VM vm = new VM("FUNCTION {test} { " + "#1 #1 + #5 #2 - }" + "EXECUTE {test}");

    List<BibEntry> v = new ArrayList<>();
    vm.run(v);
    Assert.assertEquals(3, vm.getStack().pop());
    Assert.assertEquals(2, vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #12
0
  @Test
  public void testFormatName() throws RecognitionException {
    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}");

    List<BibEntry> v = new ArrayList<>();
    vm.run(v);
    Assert.assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J?", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #13
0
  @Test
  public void testVMSwap() throws RecognitionException, IOException {

    VM vm = new VM("FUNCTION {a}{ #3 \"Hallo\" swap$ } EXECUTE { a }");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);

    Assert.assertEquals(2, vm.getStack().size());
    Assert.assertEquals(3, vm.getStack().pop());
    Assert.assertEquals("Hallo", vm.getStack().pop());
  }
  @Override
  public void execute(BstEntry context) {
    Stack<Object> stack = vm.getStack();

    if (stack.size() < 3) {
      throw new VMException("Not enough operands on stack for operation format.name$");
    }
    Object o1 = stack.pop();
    Object o2 = stack.pop();
    Object o3 = stack.pop();

    if (!(o1 instanceof String) && !(o2 instanceof Integer) && !(o3 instanceof String)) {
      // warning("A string is needed for change.case$");
      stack.push("");
      return;
    }

    String format = (String) o1;
    Integer name = (Integer) o2;
    String names = (String) o3;

    if (names == null) {
      stack.push("");
    } else {
      AuthorList a = AuthorList.parse(names);
      if (name > a.getNumberOfAuthors()) {
        throw new VMException("Author Out of Bounds. Number " + name + " invalid for " + names);
      }
      Author author = a.getAuthor(name - 1);

      stack.push(BibtexNameFormatter.formatName(author, format, vm));
    }
  }
Example #15
0
  @Test
  public void testVMChrToInt() throws RecognitionException, IOException {
    {
      VM vm = new VM("FUNCTION {test} { \"H\" chr.to.int$ }" + "EXECUTE {test}");

      Vector<BibtexEntry> v = new Vector<>();
      vm.run(v);
      Assert.assertEquals(72, vm.getStack().pop());
      Assert.assertEquals(0, vm.getStack().size());
    }
    VM vm = new VM("FUNCTION {test} { \"H\" chr.to.int$ int.to.chr$ }" + "EXECUTE {test}");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);
    Assert.assertEquals("H", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #16
0
  @Test
  public void testNumNames() throws RecognitionException {
    VM vm = new VM("FUNCTION {test} { \"Johnny Foo and Mary Bar\" num.names$ }" + "EXECUTE {test}");

    List<BibEntry> v = new ArrayList<>();
    vm.run(v);
    Assert.assertEquals(2, vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #17
0
  @Test
  public void testVMExecuteSimple() throws RecognitionException, IOException {

    {
      VM vm =
          new VM(
              ""
                  + "INTEGERS { variable.a } "
                  + "FUNCTION {init.state.consts}{ #5 'variable.a := } "
                  + "EXECUTE {init.state.consts}");

      Vector<BibtexEntry> v = new Vector<>();
      vm.run(v);
      Assert.assertEquals(new Integer(5), vm.getIntegers().get("variable.a"));
    }
    VM vm =
        new VM(
            "FUNCTION {a}{ #5 #5 = "
                + "#1 #2 = "
                + "#3 #4 < "
                + "#4 #3 < "
                + "#4 #4 < "
                + "#3 #4 > "
                + "#4 #3 > "
                + "#4 #4 > "
                + "\"H\" \"H\" = "
                + "\"H\" \"Ha\" = } "
                + "EXECUTE {a}");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);

    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(VM.FALSE, vm.getStack().pop());
    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #18
0
  @Test
  public void testNumNames() throws RecognitionException, IOException {
    {
      VM vm =
          new VM("FUNCTION {test} { \"Johnny Foo and Mary Bar\" num.names$ }" + "EXECUTE {test}");

      Vector<BibtexEntry> v = new Vector<>();
      vm.run(v);
      Assert.assertEquals(2, vm.getStack().pop());
      Assert.assertEquals(0, vm.getStack().size());
    }
    VM vm =
        new VM("FUNCTION {test} { \"Johnny Foo { and } Mary Bar\" num.names$ }" + "EXECUTE {test}");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);
    Assert.assertEquals(1, vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #19
0
  @Test
  public void testQuote() throws RecognitionException, IOException {

    VM vm = new VM("FUNCTION {a}{ quote$ quote$ * } EXECUTE {a}");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);

    Assert.assertEquals("\"\"", vm.getStack().pop());
  }
Example #20
0
  @Test
  public void testWhile() throws RecognitionException, IOException {

    VM vm =
        new VM(
            "STRINGS { t }            "
                + "FUNCTION {not}	{   "
                + " { #0 } { #1 }  if$ } "
                + "FUNCTION {n.dashify}              "
                + "{ \"HELLO-WORLD\"                 "
                + "  't :=                           "
                + " \"\"                                                 "
                + "	   { t empty$ not }                 "
                + "	   { t #1 #1 substring$ \"-\" =                      "
                + "	     { t #1 #2 substring$ \"--\" = not "
                + "	          { \"--\" *                                       "
                + "	            t #2 global.max$ substring$ 't :=                 "
                + "	          }                                                    "
                + "	          {   { t #1 #1 substring$ \"-\" = }                "
                + "	              { \"-\" *                                         "
                + "	                t #2 global.max$ substring$ 't :=               "
                + "	              }                                                  "
                + "	            while$                                                                  "
                + "	          }                                                                  "
                + "	        if$                                                                  "
                + "	      }                                                                  "
                + "	      { t #1 #1 substring$ *                                       "
                + "	        t #2 global.max$ substring$ 't :=                          "
                + "	      }                                                                  "
                + "	      if$                                                                  "
                + "	    }                                                                  "
                + "	  while$                                                                  "
                + "	}                                                                  "
                + " EXECUTE {n.dashify} ");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);

    Assert.assertEquals(1, vm.getStack().size());
    Assert.assertEquals("HELLO--WORLD", vm.getStack().pop());
  }
Example #21
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 #22
0
  @Test
  public void testTextLength() throws RecognitionException, IOException {
    VM vm =
        new VM(
            "FUNCTION {test} {"
                + "  \"hello world\" text.length$ "
                + "  \"Hello {W}orld\" text.length$ "
                + "  \"\" text.length$ "
                + "  \"{A}{D}/{Cycle}\" text.length$ "
                + "  \"{\\This is one character}\" text.length$ "
                + "  \"{\\This {is} {one} {c{h}}aracter as well}\" text.length$ "
                + "  \"{\\And this too\" text.length$ "
                + "  \"These are {\\11}\" text.length$ "
                + "} "
                + "EXECUTE {test} ");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);
    Assert.assertEquals(11, vm.getStack().pop());
    Assert.assertEquals(1, vm.getStack().pop());
    Assert.assertEquals(1, vm.getStack().pop());
    Assert.assertEquals(1, vm.getStack().pop());
    Assert.assertEquals(8, vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().pop());
    Assert.assertEquals(11, vm.getStack().pop());
    Assert.assertEquals(11, vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #23
0
  @Test
  public void testDuplicateEmptyPopSwapIf() throws RecognitionException, IOException {
    VM vm =
        new VM(
            "FUNCTION {emphasize} "
                + "{ duplicate$ empty$ "
                + "  { pop$ \"\" } "
                + "  { \"{\\em \" swap$ * \"}\" * } "
                + "  if$ "
                + "} "
                + "FUNCTION {test} {"
                + "  \"\" emphasize "
                + "  \"Hello\" emphasize "
                + "}"
                + "EXECUTE {test} ");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);
    Assert.assertEquals("{\\em Hello}", vm.getStack().pop());
    Assert.assertEquals("", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #24
0
  @Test
  public void testVMArithmetic() throws RecognitionException, IOException {
    {
      VM vm = new VM("FUNCTION {test} { " + "#1 #1 + #5 #2 - }" + "EXECUTE {test}");

      Vector<BibtexEntry> v = new Vector<>();
      vm.run(v);
      Assert.assertEquals(3, vm.getStack().pop());
      Assert.assertEquals(2, vm.getStack().pop());
      Assert.assertEquals(0, vm.getStack().size());
    }
    VM vm = new VM("FUNCTION {test} { " + "#1 \"HELLO\" + #5 #2 - }" + "EXECUTE {test}");

    Vector<BibtexEntry> v = new Vector<>();

    try {
      vm.run(v);
      Assert.fail();
    } catch (VMException ignored) {
      // Ignored
    }
  }
Example #25
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());
  }
Example #26
0
  @Test
  public void testVariables() throws RecognitionException, IOException {

    VM vm =
        new VM(
            " STRINGS { t }                          "
                + " FUNCTION {not}	{ { #0 } { #1 }  if$ } "
                + " FUNCTION {n.dashify} { \"HELLO-WORLD\" 't := t empty$ not } "
                + " EXECUTE {n.dashify}                    ");

    vm.run(new Vector<BibtexEntry>());

    Assert.assertEquals(VM.TRUE, vm.getStack().pop());
  }
Example #27
0
  @Test
  public void testSubstring() throws RecognitionException, IOException {
    VM vm =
        new VM(
            "FUNCTION {test} "
                + "{ \"123456789\" #2  #1  substring$ "
                + // 2
                "  \"123456789\" #4 global.max$ substring$ "
                + // 456789
                "  \"123456789\" #1  #9  substring$ "
                + // 123456789
                "  \"123456789\" #1  #10 substring$ "
                + // 123456789
                "  \"123456789\" #1  #99 substring$ "
                + // 123456789
                "  \"123456789\" #-7 #3  substring$ "
                + // 123
                "  \"123456789\" #-1 #1  substring$ "
                + // 9
                "  \"123456789\" #-1 #3  substring$ "
                + // 789
                "  \"123456789\" #-2 #2  substring$ "
                + // 78
                "} EXECUTE {test} ");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);
    Assert.assertEquals("78", vm.getStack().pop());
    Assert.assertEquals("789", vm.getStack().pop());
    Assert.assertEquals("9", vm.getStack().pop());
    Assert.assertEquals("123", vm.getStack().pop());

    Assert.assertEquals("123456789", vm.getStack().pop());
    Assert.assertEquals("123456789", vm.getStack().pop());
    Assert.assertEquals("123456789", vm.getStack().pop());
    Assert.assertEquals("456789", vm.getStack().pop());
    Assert.assertEquals("2", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #28
0
  @Test
  public void testLabel() throws RecognitionException, IOException {

    VM vm =
        new VM(
            "ENTRY  { title }  {}  { label } "
                + "FUNCTION { test } { label #0 = title 'label := #5 label #6 pop$ } "
                + "READ "
                + "ITERATE { test }");

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

    vm.run(v);

    Assert.assertEquals(
        "Effective work practices for floss development: A model and propositions",
        vm.getStack().pop());
  }
Example #29
0
  @Test
  public void testVMStringOps1() throws RecognitionException, IOException {
    VM vm =
        new VM(
            "FUNCTION {test} { \"H\" \"allo\" * \"Johnny\" add.period$ \"Johnny.\" add.period$"
                + "\"Johnny!\" add.period$ \"Johnny?\" add.period$ \"Johnny} }}}\" add.period$"
                + "\"Johnny!}\" add.period$ \"Johnny?}\" add.period$ \"Johnny.}\" add.period$ }"
                + "EXECUTE {test}");

    Vector<BibtexEntry> v = new Vector<>();
    vm.run(v);
    Assert.assertEquals("Johnny.}", vm.getStack().pop());
    Assert.assertEquals("Johnny?}", vm.getStack().pop());
    Assert.assertEquals("Johnny!}", vm.getStack().pop());
    Assert.assertEquals("Johnny.}", vm.getStack().pop());
    Assert.assertEquals("Johnny?", vm.getStack().pop());
    Assert.assertEquals("Johnny!", vm.getStack().pop());
    Assert.assertEquals("Johnny.", vm.getStack().pop());
    Assert.assertEquals("Johnny.", vm.getStack().pop());
    Assert.assertEquals("Hallo", vm.getStack().pop());
    Assert.assertEquals(0, vm.getStack().size());
  }
Example #30
0
  @Test
  public void testWidth() throws RecognitionException, IOException {

    VM vm =
        new VM(
            "ENTRY  { "
                + "  address "
                + "  author "
                + "  title "
                + "  type "
                + "}  {}  { label } "
                + //
                "STRINGS { longest.label } "
                + //
                "INTEGERS { number.label longest.label.width } "
                + //
                "FUNCTION {initialize.longest.label} "
                + //
                "{ \"\" 'longest.label := "
                + //
                "  #1 'number.label := "
                + //
                "  #0 'longest.label.width := "
                + //
                "} "
                + //
                " "
                + //
                "		FUNCTION {longest.label.pass} "
                + //
                "		{ number.label int.to.str$ 'label := "
                + //
                "		  number.label #1 + 'number.label := "
                + //
                "		  label width$ longest.label.width > "
                + //
                "		    { label 'longest.label := "
                + //
                "		      label width$ 'longest.label.width := "
                + //
                "		    } "
                + //
                "		    'skip$ "
                + //
                "		  if$ "
                + //
                "		} "
                + //
                " "
                + //
                "		EXECUTE {initialize.longest.label} "
                + //
                " "
                + //
                "		ITERATE {longest.label.pass} "
                + //
                "FUNCTION {begin.bib} "
                + //
                "{ preamble$ empty$"
                + //
                "    'skip$"
                + //
                "    { preamble$ write$ newline$ }"
                + //
                "  if$"
                + //
                "  \"\\begin{thebibliography}{\"  longest.label  * \"}\" *"
                + //
                "}"
                + //
                "EXECUTE {begin.bib}"
                + //
                ""); //

    Vector<BibtexEntry> v = new Vector<>();
    v.add(t1BibtexEntry());

    vm.run(v);

    Assert.assertTrue(vm.getIntegers().containsKey("longest.label.width"));
    Assert.assertEquals("\\begin{thebibliography}{1}", vm.getStack().pop());
  }