Exemple #1
0
  public void testSimpleHebrewParagraph() {
    bd = new Bidi("\u05D0", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(1, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(1, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertFalse(bd.isMixed());
    assertTrue(bd.isRightToLeft());

    bd = new Bidi("\u05D0", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(1, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(1, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertFalse(bd.isMixed());
    assertTrue(bd.isRightToLeft());

    bd = new Bidi("\u05D0", Bidi.DIRECTION_RIGHT_TO_LEFT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(1, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(1, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertFalse(bd.isMixed());
    assertTrue(bd.isRightToLeft());
  }
Exemple #2
0
 public void testCreateLineBidi() {
   bd =
       new Bidi(
           "a\u05D0a\u05D0a\u05D0\"\u05D0a".toCharArray(),
           0,
           new byte[] {0, 0, 0, -3, -3, 2, 2, 0, 3},
           0,
           9,
           Bidi.DIRECTION_RIGHT_TO_LEFT);
   Bidi line = bd.createLineBidi(2, 7);
   assertFalse(line.baseIsLeftToRight());
   assertEquals(1, line.getBaseLevel());
   assertEquals(5, line.getLength());
   assertEquals(2, line.getLevelAt(0));
   assertEquals(3, line.getLevelAt(1));
   assertEquals(3, line.getLevelAt(2));
   assertEquals(3, line.getLevelAt(3));
   assertEquals(2, line.getLevelAt(4));
   assertEquals(1, line.getLevelAt(1000));
   assertEquals(3, line.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 2}, {1, 4, 3}, {4, 5, 2},
       },
       line);
   assertFalse(line.isLeftToRight());
   assertTrue(line.isMixed());
   assertFalse(line.isRightToLeft());
 }
Exemple #3
0
 public void testComplicatedOverrideBidi() {
   bd =
       new Bidi(
           "a\u05D0a\"a\u05D0\"\u05D0a".toCharArray(),
           0,
           new byte[] {0, 0, 0, -3, -3, 2, 2, 0, 3},
           0,
           9,
           Bidi.DIRECTION_RIGHT_TO_LEFT);
   assertFalse(bd.baseIsLeftToRight());
   assertEquals(1, bd.getBaseLevel());
   assertEquals(9, bd.getLength());
   assertEquals(2, bd.getLevelAt(0));
   assertEquals(1, bd.getLevelAt(1));
   assertEquals(2, bd.getLevelAt(2));
   assertEquals(3, bd.getLevelAt(3));
   assertEquals(3, bd.getLevelAt(4));
   assertEquals(3, bd.getLevelAt(5));
   assertEquals(2, bd.getLevelAt(6));
   assertEquals(1, bd.getLevelAt(7));
   assertEquals(4, bd.getLevelAt(8));
   assertEquals(1, bd.getLevelAt(1000));
   assertEquals(7, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 2}, {1, 2, 1}, {2, 3, 2}, {3, 6, 3}, {6, 7, 2}, {7, 8, 1}, {8, 9, 4},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Exemple #4
0
 public void testComplicatedBidi() {
   bd = new Bidi("a\u05D0a\"a\u05D0\"\u05D0a", Bidi.DIRECTION_RIGHT_TO_LEFT);
   assertFalse(bd.baseIsLeftToRight());
   assertEquals(1, bd.getBaseLevel());
   assertEquals(9, bd.getLength());
   assertEquals(2, bd.getLevelAt(0));
   assertEquals(1, bd.getLevelAt(1));
   assertEquals(2, bd.getLevelAt(2));
   assertEquals(2, bd.getLevelAt(3));
   assertEquals(2, bd.getLevelAt(4));
   assertEquals(1, bd.getLevelAt(5));
   assertEquals(1, bd.getLevelAt(6));
   assertEquals(1, bd.getLevelAt(7));
   assertEquals(2, bd.getLevelAt(8));
   assertEquals(1, bd.getLevelAt(1000));
   assertEquals(5, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 2}, {1, 2, 1}, {2, 5, 2}, {5, 8, 1}, {8, 9, 2},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Exemple #5
0
 public void testRelativeEmbeddings() {
   bd =
       new Bidi(
           new char[] {'s', 's', 's'},
           0,
           new byte[] {(byte) 1, (byte) 2, (byte) 3},
           0,
           3,
           Bidi.DIRECTION_RIGHT_TO_LEFT);
   assertFalse(bd.baseIsLeftToRight());
   assertEquals(1, bd.getBaseLevel());
   assertEquals(3, bd.getLength());
   assertEquals(2, bd.getLevelAt(0));
   assertEquals(2, bd.getLevelAt(1));
   assertEquals(4, bd.getLevelAt(2));
   assertEquals(1, bd.getLevelAt(1000));
   assertEquals(2, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 2, 2}, {2, 3, 4},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Exemple #6
0
 public void testIncompatibleLineAlgorithm() {
   // ICU treat a new line as in the same run, however RI does not
   bd =
       new Bidi(
           "aaaaa".toCharArray(),
           0,
           new byte[] {-2, -1, -3, -3, -2},
           0,
           5,
           Bidi.DIRECTION_RIGHT_TO_LEFT);
   Bidi line = bd.createLineBidi(1, 4);
   assertFalse(line.baseIsLeftToRight());
   assertEquals(1, line.getBaseLevel());
   assertEquals(3, line.getLength());
   assertEquals(1, line.getLevelAt(0));
   assertEquals(1, line.getLevelAt(1));
   assertEquals(1, line.getLevelAt(2));
   assertEquals(1, line.getLevelAt(1000));
   assertEquals(1, line.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 3, 1},
       },
       line);
   assertFalse(line.isLeftToRight());
   assertFalse(line.isMixed());
   assertTrue(line.isRightToLeft());
 }
Exemple #7
0
 // this is essentially the same bug as Bug_1
 public void testRIBug_2() {
   bd = new Bidi("\u05D0", Bidi.DIRECTION_LEFT_TO_RIGHT);
   assertTrue(bd.baseIsLeftToRight());
   assertEquals(0, bd.getBaseLevel());
   assertEquals(1, bd.getLength());
   assertEquals(1, bd.getLevelAt(0));
   assertEquals(0, bd.getLevelAt(1000));
   assertEquals(1, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 1},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Exemple #8
0
 public void testBadFlags() {
   bd = new Bidi("", 173);
   assertTrue(bd.baseIsLeftToRight());
   assertEquals(0, bd.getBaseLevel());
   assertEquals(0, bd.getLength());
   assertEquals(0, bd.getLevelAt(0));
   assertEquals(0, bd.getLevelAt(1000));
   assertEquals(1, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 0, 0},
       },
       bd);
   assertTrue(bd.isLeftToRight());
   assertFalse(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Exemple #9
0
 /*
  * spec reads: public static final int DIRECTION_RIGHT_TO_LEFT Constant
  * indicating base direction is right-to-left. according to that, the method
  * baseIsLeftToRight() here should return false. however, RI doesn't act so.
  */
 public void testRIBug_1() {
   bd = new Bidi("t", Bidi.DIRECTION_RIGHT_TO_LEFT);
   assertFalse(bd.baseIsLeftToRight());
   // the base level it the essential cause
   assertEquals(1, bd.getBaseLevel());
   assertEquals(1, bd.getLength());
   assertEquals(2, bd.getLevelAt(0));
   assertEquals(1, bd.getLevelAt(1000));
   assertEquals(1, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 2},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Exemple #10
0
  public void testHebrewOverrideEmbeddings() {
    bd =
        new Bidi(
            new char[] {'\u05D0', '\u05D0', '\u05D0'},
            0,
            new byte[] {(byte) -1, (byte) -2, (byte) -3},
            0,
            3,
            Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(3, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(2, bd.getLevelAt(1));
    assertEquals(3, bd.getLevelAt(2));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(3, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1}, {1, 2, 2}, {2, 3, 3},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertTrue(bd.isMixed());
    assertFalse(bd.isRightToLeft());

    bd =
        new Bidi(
            new char[] {'\u05D0', '\u05D0', '\u05D0'},
            0,
            new byte[] {(byte) -1, (byte) -2, (byte) -3},
            0,
            3,
            Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(3, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(2, bd.getLevelAt(1));
    assertEquals(3, bd.getLevelAt(2));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(3, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1}, {1, 2, 2}, {2, 3, 3},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertTrue(bd.isMixed());
    assertFalse(bd.isRightToLeft());

    bd =
        new Bidi(
            new char[] {'\u05D0', '\u05D0', '\u05D0'},
            0,
            new byte[] {(byte) -1, (byte) -2, (byte) -3},
            0,
            3,
            Bidi.DIRECTION_LEFT_TO_RIGHT);
    assertTrue(bd.baseIsLeftToRight());
    assertEquals(0, bd.getBaseLevel());
    assertEquals(3, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(2, bd.getLevelAt(1));
    assertEquals(3, bd.getLevelAt(2));
    assertEquals(0, bd.getLevelAt(1000));
    assertEquals(3, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1}, {1, 2, 2}, {2, 3, 3},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertTrue(bd.isMixed());
    assertFalse(bd.isRightToLeft());

    bd =
        new Bidi(
            new char[] {'\u05D0', '\u05D0', '\u05D0'},
            0,
            new byte[] {(byte) -1, (byte) -2, (byte) -3},
            0,
            3,
            Bidi.DIRECTION_RIGHT_TO_LEFT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(3, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(2, bd.getLevelAt(1));
    assertEquals(3, bd.getLevelAt(2));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(3, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1}, {1, 2, 2}, {2, 3, 3},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertTrue(bd.isMixed());
    assertFalse(bd.isRightToLeft());
  }