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.

IntelligentLinkingTest.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2006-2014 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 com.dmdirc.DMDircMBassador;
  24. import com.dmdirc.interfaces.Connection;
  25. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  26. import java.util.Arrays;
  27. import java.util.List;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import org.junit.runners.Parameterized;
  31. import org.mockito.Mock;
  32. import static org.junit.Assert.assertEquals;
  33. import static org.mockito.Mockito.mock;
  34. import static org.mockito.Mockito.when;
  35. @RunWith(Parameterized.class)
  36. public class IntelligentLinkingTest {
  37. @Mock private DMDircMBassador eventBus;
  38. private final String input, expected;
  39. private final Styliser styliser;
  40. public IntelligentLinkingTest(final String input, final String expected) {
  41. this.input = input;
  42. this.expected = expected;
  43. final AggregateConfigProvider manager = mock(AggregateConfigProvider.class);
  44. final Connection connection = mock(Connection.class);
  45. when(connection.getChannelPrefixes()).thenReturn("#&+");
  46. styliser = new Styliser(connection, manager, new ColourManager(manager,
  47. mock(DMDircMBassador.class)));
  48. }
  49. @Test
  50. public void testLink() throws InterruptedException {
  51. assertEquals(expected, styliser.doLinks(input)
  52. .replace(Styliser.CODE_HYPERLINK, '~')
  53. .replace(Styliser.CODE_CHANNEL, '@'));
  54. }
  55. @Parameterized.Parameters
  56. public static List<String[]> data() {
  57. final String[][] tests = {
  58. {"no links here!", "no links here!"},
  59. {"www.google.com", "~www.google.com~"},
  60. {"www.google.com.", "~www.google.com~."},
  61. {"'www.google.com'", "'~www.google.com~'"},
  62. {"www.google.com, foo", "~www.google.com~, foo"},
  63. {"http://www.google.com", "~http://www.google.com~"},
  64. {"www.google.com www.google.com", "~www.google.com~ ~www.google.com~"},
  65. {"http://www.google.com:80/test#flub", "~http://www.google.com:80/test#flub~"},
  66. {"(www.google.com)", "(~www.google.com~)"},
  67. {"(foo: www.google.com)", "(foo: ~www.google.com~)"},
  68. {"(foo: 'www.google.com')", "(foo: '~www.google.com~')"},
  69. {"foo: www.google.com, bar", "foo: ~www.google.com~, bar"},
  70. {"www.google.com?", "~www.google.com~?"},
  71. {"www.google.com!", "~www.google.com~!"},
  72. {"http://...", "http://..."},
  73. {"www...", "www..."},
  74. {"(www.foo.com www.bar.com)", "(~www.foo.com~ ~www.bar.com~)"},
  75. {"(www.foo.com/)/ www.bar.com)", "(~www.foo.com/)/~ ~www.bar.com~)"},
  76. {"(\"http://example.org\")->", "(\"~http://example.org~\")->"},
  77. {"('http://example.org')->", "('~http://example.org~')->"},
  78. {"('www.foo.com')->ss('http://example.org');",
  79. "('~www.foo.com~')->ss('~http://example.org~');"},
  80. {"svn+ssh://foo@bar", "~svn+ssh://foo@bar~"},
  81. {"/var/web/www.foo.com/bar", "/var/web/www.foo.com/bar"},
  82. {"\"foo\" www.google.com \"www.google.com\"",
  83. "\"foo\" ~www.google.com~ \"~www.google.com~\""},
  84. {"www.example.com/blah(foobar)", "~www.example.com/blah(foobar)~"},
  85. {"000000http://www.google.com/", "000000~http://www.google.com/~"},
  86. {"ABCDEFhttp://www.google.com/", "ABCDEF~http://www.google.com/~"},
  87. // ------------ Channels -------------------
  88. {"#test", "@#test@"},
  89. {"&test", "@&test@"},
  90. {"+test", "@+test@"},
  91. {"(#test)", "(@#test@)"},
  92. {"\"#test\"", "\"@#test@\""},
  93. {"'#test'", "'@#test@'"},
  94. {"(join #test)", "(join @#test@)"},
  95. {"\"join #test\"", "\"join @#test@\""},
  96. {"'join #test'", "'join @#test@'"},
  97. {"#test.", "@#test@."},
  98. {"#test1,#test2,#test3", "@#test1@,@#test2@,@#test3@"},
  99. {"(\"join #test!\")", "(\"join @#test@!\")"},
  100. };
  101. return Arrays.asList(tests);
  102. }
  103. }