Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

IntelligentLinkingTest.java 5.2KB

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