You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LinePositionTest.java 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  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.ui.messages;
  23. import org.junit.Test;
  24. import static org.junit.Assert.assertEquals;
  25. public class LinePositionTest {
  26. @Test
  27. public void testNormaliseWithForwardMultiLineSelection() {
  28. final LinePosition input = new LinePosition(2, 5, 4, 1);
  29. assertEquals(input.toString(), input.getNormalised().toString());
  30. }
  31. @Test
  32. public void testNormaliseWithForwardSingleLineSelection() {
  33. final LinePosition input = new LinePosition(2, 5, 2, 8);
  34. assertEquals(input.toString(), input.getNormalised().toString());
  35. }
  36. @Test
  37. public void testNormaliseWithBackwardMultiLineSelection() {
  38. final LinePosition input = new LinePosition(5, 8, 2, 5);
  39. final LinePosition expected = new LinePosition(2, 5, 5, 8);
  40. assertEquals(expected.toString(), input.getNormalised().toString());
  41. }
  42. @Test
  43. public void testNormaliseWithBackwardSingleLineSelection() {
  44. final LinePosition input = new LinePosition(2, 8, 2, 5);
  45. final LinePosition expected = new LinePosition(2, 5, 2, 8);
  46. assertEquals(expected.toString(), input.getNormalised().toString());
  47. }
  48. @Test
  49. public void testCloneConstructor() {
  50. final LinePosition input = new LinePosition(2, 4, 6, 8);
  51. assertEquals(input.toString(), new LinePosition(input).toString());
  52. }
  53. @Test
  54. public void testGetters() {
  55. final LinePosition input = new LinePosition(2, 4, 6, 8);
  56. assertEquals(2, input.getStartLine());
  57. assertEquals(4, input.getStartPos());
  58. assertEquals(6, input.getEndLine());
  59. assertEquals(8, input.getEndPos());
  60. }
  61. @Test
  62. public void testSetters() {
  63. final LinePosition input = new LinePosition(2, 4, 6, 8);
  64. input.setStartLine(17);
  65. assertEquals(17, input.getStartLine());
  66. input.setStartPos(27);
  67. assertEquals(27, input.getStartPos());
  68. input.setEndLine(13);
  69. assertEquals(13, input.getEndLine());
  70. input.setEndPos(786);
  71. assertEquals(786, input.getEndPos());
  72. final LinePosition expected = new LinePosition(17, 27, 13, 786);
  73. assertEquals(expected.toString(), input.toString());
  74. }
  75. }