Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

IntelligentLinkingTest.java 4.9KB

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