Ejemplo n.º 1
0
  public void testOnNativeMethodOffset() throws ModelException {
    String js = "search/NativeTypeA.js";
    FixtureManager m_fixtureManager = FixtureUtils.setUpFixture(this, js);
    try {
      IJSSourceModule module =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(js));

      IType[] types = module.getTypes();
      assertEquals("Wrong number of types", 1, types.length);
      // IJSType type = (IJSType) types[0];

      // VjoMatch[] matches=null;
      IType nativeType = getNativeType("Array");

      IJSMethod element = findMethodByName(nativeType.getMethods(), "reverse");
      ISourceRange range = element.getSourceRange();
      int offset = range.getOffset();
      assertNotSame("Invalid offset, the actrual value is -1", -1, offset);
      // assertTrue(offset != -1);

      // nativeType.getSourceModule().getChildren();
    } finally {
      FixtureUtils.tearDownFixture(m_fixtureManager);
    }
  }
Ejemplo n.º 2
0
  public void testOnNativeNeedOffset() throws ModelException {
    String js = "search/NativeTypeA.js";
    FixtureManager m_fixtureManager = FixtureUtils.setUpFixture(this, js);
    try {
      IJSSourceModule module =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(js));

      IType[] types = module.getTypes();
      assertEquals("Wrong number of types", 1, types.length);
      // IJSType type = (IJSType) types[0];

      // VjoMatch[] matches=null;
      IType nativeType = getNativeType("Array");

      IModelElement[] elements = nativeType.getSourceModule().getChildren();
      for (IModelElement element : elements) {
        if (element instanceof ImportContainer) {
          ISourceRange range = ((ImportContainer) element).getSourceRange();
          int offset = range.getOffset();
          assertNotSame("Invalid offset, the actrual value is -1", -1, offset);
        }
      }

    } finally {
      FixtureUtils.tearDownFixture(m_fixtureManager);
    }
  }
  public void testIndent3() throws Exception {
    String js = "autoEdit/indentTest3";
    String goldenJs = js + "Golden";
    FixtureManager m_fixtureManager = FixtureUtils.setUpFixture(this, js + ".js");
    try {
      IJSSourceModule module =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(js + ".js"));
      IJSSourceModule goldenModule =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(goldenJs + ".js"));

      basicTest(module, 130, goldenModule);
    } finally {
      FixtureUtils.tearDownFixture(m_fixtureManager);
    }
  }
  public void testBug4579a() throws Exception {
    String js = "autoEdit/indentBug4579a";

    String goldenJs = js + "Golden";
    FixtureManager m_fixtureManager = FixtureUtils.setUpFixture(this, js + ".js");
    try {
      IJSSourceModule module =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(js + ".js"));
      IJSSourceModule goldenModule =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(goldenJs + ".js"));

      String text = "myProp: 234,\r\n\tmyProp2: \"hello world\",";
      basicTest(module, 89, text, goldenModule);
    } finally {
      FixtureUtils.tearDownFixture(m_fixtureManager);
    }
  }
  public void testBug7679() throws Exception {
    String js = "autoEdit/indentTest7679";

    String goldenJs = js + "Golden";
    FixtureManager m_fixtureManager = FixtureUtils.setUpFixture(this, js + ".js");
    try {
      IJSSourceModule module =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(js + ".js"));
      IJSSourceModule goldenModule =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(goldenJs + ".js"));

      String text = "\r\n\tx : function(){\r\n\t}";
      basicTest(module, 111, 10, text, goldenModule);
    } finally {
      FixtureUtils.tearDownFixture(m_fixtureManager);
    }
  }
  public void testBug7553() throws Exception {
    String js = "autoEdit/indentBug7553";

    String goldenJs = js + "Golden";
    FixtureManager m_fixtureManager = FixtureUtils.setUpFixture(this, js + ".js");
    try {
      IJSSourceModule module =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(js + ".js"));
      IJSSourceModule goldenModule =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(goldenJs + ".js"));

      String text =
          "\t//>public constructs()\r\n\tconstructs : function(){\r\n        this.ia = 10;\r\n\t}";
      basicTest(module, 82, 77, text, goldenModule);
    } finally {
      FixtureUtils.tearDownFixture(m_fixtureManager);
    }
  }
  /**
   * Test the source viewer of Vjet editor and if the start and end line equal the given value, it
   * passes.
   *
   * <p>Add by Oliver.
   *
   * @throws Exception
   */
  public void testBug3811() throws Exception {
    String js = "autoEdit/test3811";
    FixtureManager m_fixtureManager = FixtureUtils.setUpFixture(this, js + ".js");
    IFile file =
        ResourcesPlugin.getWorkspace()
            .getRoot()
            .getFile(new Path(getProjectName() + "/src/" + js + ".js"));

    VjoEditor editor =
        (VjoEditor)
            IDE.openEditor(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);

    try {
      try {
        Class clazz =
            editor
                .getClass()
                .getClassLoader()
                .loadClass("org.eclipse.vjet.eclipse.internal.ui.editor.VjoEditor");
        Field fSourceViewer = clazz.getDeclaredField("fSourceViewer");
        fSourceViewer.setAccessible(true);
        ISourceViewer sourceViewer = (ISourceViewer) fSourceViewer.get(editor);
        boolean hasIcon = RangeIndicatorUtil.hasRangeIndication(sourceViewer, 0, 3);
        assertEquals(hasIcon, true);
      } catch (SecurityException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchFieldException e) {
        e.printStackTrace();
      }

    } finally {
      FixtureUtils.tearDownFixture(m_fixtureManager);
    }
  }
Ejemplo n.º 8
0
  public void testOnNativeSource() throws ModelException {
    String js = "search/NativeTypeA.js";
    FixtureManager m_fixtureManager = FixtureUtils.setUpFixture(this, js);
    try {
      IJSSourceModule module =
          (IJSSourceModule) getSourceModule(getProjectName(), "src", new Path(js));

      IType[] types = module.getTypes();
      assertEquals("Wrong number of types", 1, types.length);
      IJstType nativeJstType = getNativeJstType("Array");
      IJstMethod element = nativeJstType.getMethod("reverse");

      assertNotSame("native type source is null", null, element.getSource());
      if (element.getSource() != null) {
        int offset = element.getSource().getStartOffSet();
        assertNotSame("Invalid offset, the actrual value is -1", -1, offset);
      }
    } finally {
      FixtureUtils.tearDownFixture(m_fixtureManager);
    }
  }
  public void testBug2512() throws Exception {
    String js = "autoEdit/indentTest2512";

    FixtureManager m_fixtureManager = FixtureUtils.setUpFixture(this, js + ".js");
    IFile file =
        ResourcesPlugin.getWorkspace()
            .getRoot()
            .getFile(new Path(getProjectName() + "/src/" + js + ".js"));

    VjoEditor editor =
        (VjoEditor)
            IDE.openEditor(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);

    try {
      IPreferenceStore store = VjetUIPlugin.getDefault().getPreferenceStore();
      testTabSize(store.getInt(CodeFormatterConstants.FORMATTER_TAB_SIZE), editor);
      store.setValue(CodeFormatterConstants.FORMATTER_TAB_SIZE, 10);
      testTabSize(10, editor);

    } finally {
      FixtureUtils.tearDownFixture(m_fixtureManager);
    }
  }