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

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