PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/RubyPlugin/src/org/jedit/ruby/test/TestRubyCache.java

#
Java | 93 lines | 56 code | 15 blank | 22 comment | 0 complexity | 327514c5a6de4f0e9cfe0e1938fed04f MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * TestRubyCache.java -
  3. *
  4. * Copyright 2005 Robert McKinnon
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or any later version.
  10. *
  11. * This program 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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. package org.jedit.ruby.test;
  21. import org.jedit.ruby.cache.RubyCache;
  22. import org.jedit.ruby.ast.Member;
  23. import org.jedit.ruby.ast.Method;
  24. import java.util.List;
  25. import junit.framework.TestCase;
  26. /**
  27. * @author robmckinnon at users.sourceforge.net
  28. */
  29. public final class TestRubyCache extends TestCase {
  30. private static void addClassesToCache() {
  31. RubyCache.instance().addMembers(TestRubyParser.CLASS, "CLASS");
  32. RubyCache.instance().addMembers(TestRubyParser.ARR_CLASS, "ARR_CLASS");
  33. }
  34. private static void addModuleToCache() {
  35. RubyCache.instance().addMembers(TestRubyParser.DEF_IN_MODULE, "DEF_IN_MODULE");
  36. }
  37. public final void testGetMethods() {
  38. addClassesToCache();
  39. List<Method> methods = RubyCache.instance().getMethods("red");
  40. assertEquals("Assert file name correct", "CLASS", methods.get(0).getFileName());
  41. assertEquals("Assert file name correct", "red", methods.get(0).getName());
  42. }
  43. public final void testGetClassByMethod() {
  44. addClassesToCache();
  45. assertFindByMethodCorrect("red", 0, "Green", 1);
  46. assertFindByMethodCorrect("[]", 0, "Green", 1);
  47. }
  48. public final void testGetMethodByClass() {
  49. addClassesToCache();
  50. assertFindByClassCorrect("Green", 0, "[]", 2, "ARR_CLASS");
  51. assertFindByClassCorrect("Green", 1, "red", 2, "CLASS");
  52. }
  53. public final void testGetClassByCombo() {
  54. addClassesToCache();
  55. addModuleToCache();
  56. assertFindByMethodCorrect("red", 0, "Blue", 2);
  57. assertFindByMethodCorrect("red", 1, "Green", 2);
  58. assertFindByMethodCorrect("[]", 0, "Green", 1);
  59. }
  60. public final void testGetMethodByCombo() {
  61. addClassesToCache();
  62. addModuleToCache();
  63. assertFindByClassCorrect("Green", 0, "[]", 2, "ARR_CLASS");
  64. assertFindByClassCorrect("Green", 1, "red", 2, "CLASS");
  65. assertFindByClassCorrect("Blue", 0, "red", 1, "DEF_IN_MODULE");
  66. }
  67. private static void assertFindByMethodCorrect(String method, int index, String parentName, int parentCount) {
  68. List<Member> members = RubyCache.instance().getMembersWithMethodAsList(method);
  69. assertEquals("Assert parent match correct for: " + method, parentCount, members.size());
  70. assertEquals("Assert name correct", parentName, members.get(index).getName());
  71. }
  72. private static void assertFindByClassCorrect(String parentName, int index, String methodName, int methodCount, String filePath) {
  73. List<Method> members = RubyCache.instance().getMethodsOfMemberAsList(parentName);
  74. assertEquals("Assert child match correct", methodCount, members.size());
  75. assertEquals("Assert name correct", methodName, members.get(index).getName());
  76. assertEquals("Assert path correct", filePath, members.get(index).getFilePath());
  77. }
  78. }