Package net.sf.jabref.bst

Examples of net.sf.jabref.bst.VM


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

  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<BibtexEntry>();
    vm.run(v);
    assertEquals("78", vm.getStack().pop());
    assertEquals("789", vm.getStack().pop());
    assertEquals("9", vm.getStack().pop());
    assertEquals("123", vm.getStack().pop());

    assertEquals("123456789", vm.getStack().pop());
    assertEquals("123456789", vm.getStack().pop());
    assertEquals("123456789", vm.getStack().pop());
    assertEquals("456789", vm.getStack().pop());
    assertEquals("2", vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }
View Full Code Here


    assertEquals("2", vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }

  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<BibtexEntry>();
    v.add(bibtexString2BibtexEntry("@article{a, author=\"AAA\"}"));
    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.TRUE, vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }
View Full Code Here

    assertEquals(VM.TRUE, vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }

  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<BibtexEntry>();
    vm.run(v);
    assertEquals("{\\em Hello}", vm.getStack().pop());
    assertEquals("", vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }
View Full Code Here

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

  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<BibtexEntry>();
    vm.run(v);
    assertEquals(
      "{A}{D}/{C}ycle: {I}{B}{M}'s {F}ramework for {A}pplication {D}evelopment and {C}ase",
      vm.getStack().pop());
    assertEquals("", vm.getStack().pop());
    assertEquals("Hello world", vm.getStack().pop());
    assertEquals("Hello world", vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }
View Full Code Here

    assertEquals("Hello world", vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }

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

    assertEquals(new Integer(11), vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }

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

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

  public void testVMChrToInt() throws RecognitionException, IOException {
    {
      VM vm = new VM("FUNCTION {test} { \"H\" chr.to.int$ }" + "EXECUTE {test}");

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

    }
  }

  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<BibtexEntry>();
    v.add(bibtexString2BibtexEntry("@article{a, author=\"AAA\"}"));
    v.add(bibtexString2BibtexEntry("@article{b, author=\"BBB\"}"));
    v.add(bibtexString2BibtexEntry("@article{d, author=\"DDD\"}"));
    v.add(bibtexString2BibtexEntry("@article{c, author=\"CCC\"}"));
    vm.run(v);

    Vector<BstEntry> v2 = vm.getEntries();
    assertEquals("a", v2.get(0).getBibtexEntry().getCiteKey());
    assertEquals("b", v2.get(1).getBibtexEntry().getCiteKey());
    assertEquals("c", v2.get(2).getBibtexEntry().getCiteKey());
    assertEquals("d", v2.get(3).getBibtexEntry().getCiteKey());
  }
View Full Code Here

    assertEquals("c", v2.get(2).getBibtexEntry().getCiteKey());
    assertEquals("d", v2.get(3).getBibtexEntry().getCiteKey());
  }

  public void testBuildIn() throws RecognitionException, IOException {
    VM vm = new VM("EXECUTE {global.max$}");

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

    assertEquals(new Integer(Integer.MAX_VALUE), vm.getStack().pop());
    assertTrue(vm.getStack().empty());
  }
View Full Code Here

    assertTrue(vm.getStack().empty());
  }

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

    assertEquals(VM.TRUE, vm.getStack().pop());
  }
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.