Package net.sf.jabref.bst

Examples of net.sf.jabref.bst.VM



public class TestVM extends TestCase {

  public void testAbbrv() throws RecognitionException, IOException {
    VM vm = new VM(new File("src/tests/net/sf/jabref/bst/abbrv.bst"));
    Vector<BibtexEntry> v = new Vector<BibtexEntry>();
    v.add(t1BibtexEntry());
   
    String expected = "\\begin{thebibliography}{1}\\bibitem{canh05}K.~Crowston, H.~Annabi, J.~Howison, and C.~Masango.\\newblock Effective work practices for floss development: A model and  propositions.\\newblock In {\\em Hawaii International Conference On System Sciences (HICSS)}, 2005.\\end{thebibliography}";
   
    assertEquals(expected.replaceAll("\\s", ""), vm.run(v).replaceAll("\\s", ""));
  }
View Full Code Here


    assertEquals(expected.replaceAll("\\s", ""), vm.run(v).replaceAll("\\s", ""));
  }

  public void testVMSimple() throws RecognitionException, IOException {

    VM vm = new VM("" + "ENTRY  { " + "  address " + "  author " + "  title " + "  type "
      + "}  {}  { label }" + "INTEGERS { output.state before.all"
      + " mid.sentence after.sentence after.block }"
      + "FUNCTION {init.state.consts}{ #0 'before.all := "
      + " #1 'mid.sentence :=  #2 'after.sentence :=  #3 'after.block := } "
      + "STRINGS { s t } " + "READ");

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

    vm.run(v);

    assertEquals(2, vm.getStrings().size());
    assertEquals(7, vm.getIntegers().size());
    assertEquals(1, vm.getEntries().size());
    assertEquals(5, (vm.getEntries().get(0)).getFields().size());
    assertEquals(38, vm.getFunctions().size());

  }
View Full Code Here

  }

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

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

    vm.run(v);

    assertEquals("Effective work practices for floss development: A model and propositions", vm
      .getStack().pop());

  }
View Full Code Here

  }

  public void testQuote() throws RecognitionException, IOException {

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

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

    assertEquals("\"\"", vm.getStack().pop());
  }
View Full Code Here

    assertEquals("\"\"", vm.getStack().pop());
  }

  public void testVMFunction1() throws RecognitionException, IOException {

    VM vm = new VM("FUNCTION {init.state.consts}{ #0 'before.all := } ");

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

    assertEquals(38, vm.getFunctions().size());

    assertTrue(vm.getFunctions().get("init.state.consts") instanceof StackFunction);

    StackFunction fun = (StackFunction) vm.getFunctions().get("init.state.consts");
    assertEquals(3, fun.getTree().getChildCount());
  }
View Full Code Here

  }

  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<BibtexEntry>();
      vm.run(v);
      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<BibtexEntry>();
      vm.run(v);

      assertEquals(VM.FALSE, vm.getStack().pop());
      assertEquals(VM.TRUE, vm.getStack().pop());
      assertEquals(VM.FALSE, vm.getStack().pop());
      assertEquals(VM.TRUE, vm.getStack().pop());
      assertEquals(VM.FALSE, vm.getStack().pop());
      assertEquals(VM.FALSE, vm.getStack().pop());
      assertEquals(VM.FALSE, vm.getStack().pop());
      assertEquals(VM.TRUE, vm.getStack().pop());
      assertEquals(VM.FALSE, vm.getStack().pop());
      assertEquals(VM.TRUE, vm.getStack().pop());
      assertEquals(0, vm.getStack().size());
    }
  }
View Full Code Here

      assertEquals(0, vm.getStack().size());
    }
  }

  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<BibtexEntry>();
    vm.run(v);
    assertEquals(VM.FALSE, vm.getStack().pop());
    assertEquals(VM.TRUE, vm.getStack().pop());
    assertEquals(VM.TRUE, vm.getStack().pop());
    assertEquals(VM.TRUE, vm.getStack().pop());
    assertEquals(VM.FALSE, vm.getStack().pop());
    assertEquals(VM.TRUE, vm.getStack().pop());
    assertEquals(VM.FALSE, vm.getStack().pop());
    assertEquals(VM.FALSE, vm.getStack().pop());
    assertEquals(VM.FALSE, vm.getStack().pop());
    assertEquals(VM.TRUE, vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }
View Full Code Here

    assertEquals(0, vm.getStack().size());
  }

  public void testVMArithmetic() throws RecognitionException, IOException {
    {
      VM vm = new VM("FUNCTION {test} { " + "#1 #1 + #5 #2 - }" + "EXECUTE {test}");

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

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

      try {
        vm.run(v);
        fail();
      } catch (VMException e) {

      }
    }
View Full Code Here

    }
  }

  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<BibtexEntry>();
      vm.run(v);
      assertEquals(new Integer(2), vm.getStack().pop());
      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<BibtexEntry>();
      vm.run(v);
      assertEquals(new Integer(1), vm.getStack().pop());
      assertEquals(0, vm.getStack().size());
    }
  }
View Full Code Here

    }
  }

  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<BibtexEntry>();
      vm.run(v);
      assertEquals("Johnny.}", vm.getStack().pop());
      assertEquals("Johnny?}", vm.getStack().pop());
      assertEquals("Johnny!}", vm.getStack().pop());
      assertEquals("Johnny.}", vm.getStack().pop());
      assertEquals("Johnny?", vm.getStack().pop());
      assertEquals("Johnny!", vm.getStack().pop());
      assertEquals("Johnny.", vm.getStack().pop());
      assertEquals("Johnny.", vm.getStack().pop());
      assertEquals("Hallo", vm.getStack().pop());
      assertEquals(0, vm.getStack().size());
    }
  }
View Full Code Here

TOP

Related Classes of net.sf.jabref.bst.VM

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.