PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/sonar-colorizer/src/test/java/org/sonar/colorizer/RegexpTokenizerTest.java

https://github.com/ajub/sonar
Java | 47 lines | 21 code | 7 blank | 19 comment | 0 complexity | ac8e0a7e25bf2d55066c14c707040516 MD5 | raw file
  1. /*
  2. * Sonar, open source software quality management tool.
  3. * Copyright (C) 2008-2011 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * Sonar is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * Sonar is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Sonar; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package org.sonar.colorizer;
  21. import static org.hamcrest.Matchers.is;
  22. import static org.hamcrest.Matchers.not;
  23. import static org.junit.Assert.assertThat;
  24. import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight;
  25. import org.junit.Test;
  26. public class RegexpTokenizerTest {
  27. RegexpTokenizer tokenHighlighter;;
  28. @Test
  29. public void testHighlight() {
  30. tokenHighlighter = new RegexpTokenizer("<r>", "</r>", "[0-9]+");
  31. assertThat(highlight("123, word = 435;", tokenHighlighter), is("<r>123</r>, word = <r>435</r>;"));
  32. }
  33. @Test
  34. public void testClone() {
  35. RegexpTokenizer tokenizer = new RegexpTokenizer("<r>", "</r>", "[a-z]+");
  36. RegexpTokenizer cloneTokenizer = tokenizer.clone();
  37. assertThat(tokenizer, is(not(cloneTokenizer)));
  38. assertThat(highlight("public 1234", cloneTokenizer), is("<r>public</r> 1234"));
  39. }
  40. }