Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

WritableFrameContainerTest.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc;
  23. import com.dmdirc.config.IdentityManager;
  24. import com.dmdirc.config.InvalidIdentityFileException;
  25. import com.dmdirc.harness.TestWritableFrameContainer;
  26. import com.dmdirc.ui.interfaces.InputWindow;
  27. import java.util.Arrays;
  28. import org.junit.BeforeClass;
  29. import org.junit.Test;
  30. import static org.junit.Assert.*;
  31. public class WritableFrameContainerTest {
  32. @BeforeClass
  33. public static void setupClass() throws InvalidIdentityFileException {
  34. IdentityManager.load();
  35. }
  36. @Test
  37. public void testGetNumLines() {
  38. final WritableFrameContainer<?> container10
  39. = new TestWritableFrameContainer<InputWindow>(10, InputWindow.class);
  40. final int res0a = container10.getNumLines("");
  41. final int res0b = container10.getNumLines("\r");
  42. final int res0c = container10.getNumLines("\r\n");
  43. final int res1a = container10.getNumLines("0123456789");
  44. final int res1b = container10.getNumLines("\r\n123456789");
  45. final int res1c = container10.getNumLines("qaaa");
  46. final int res2a = container10.getNumLines("01234567890");
  47. final int res2b = container10.getNumLines("012345\r\n\r\n34567890");
  48. final int res2c = container10.getNumLines("01234567890\r\n\r\n");
  49. assertEquals(0, res0a);
  50. assertEquals(0, res0b);
  51. assertEquals(0, res0c);
  52. assertEquals(1, res1a);
  53. assertEquals(1, res1b);
  54. assertEquals(1, res1c);
  55. assertEquals(2, res2a);
  56. assertEquals(2, res2b);
  57. assertEquals(2, res2c);
  58. }
  59. @Test
  60. public void testSplitLine() {
  61. final WritableFrameContainer<?> container10
  62. = new TestWritableFrameContainer<InputWindow>(10, InputWindow.class);
  63. final String[][][] tests = new String[][][]{
  64. {{""}, {""}},
  65. {{"0123456789"}, {"0123456789"}},
  66. {{"01234567890"}, {"0123456789", "0"}},
  67. {{"012345678→"}, {"012345678","→"}},
  68. {{"0123456→"}, {"0123456→"}},
  69. {{"01→2345678"}, {"01→23456","78"}},
  70. {{"01→23456\n78"}, {"01→23456","78"}},
  71. {{"01\n→2345678"}, {"01","→2345678"}},
  72. {{"→→→00"}, {"→→→0", "0"}},
  73. };
  74. for (String[][] test : tests) {
  75. final String[] res = container10.splitLine(test[0][0]).toArray(new String[0]);
  76. assertTrue("'" + test[0][0] + "' → "
  77. + Arrays.toString(res) + " (expected: " + Arrays.toString(test[1]) + ")",
  78. Arrays.equals(res, test[1]));
  79. }
  80. }
  81. }