Package krasa.formatter.eclipse

Source Code of krasa.formatter.eclipse.JSCodeFormatterFacadeTest

package krasa.formatter.eclipse;

import junit.framework.Assert;
import krasa.formatter.settings.Settings;
import krasa.formatter.settings.provider.JSPropertiesProvider;
import org.junit.Before;
import org.junit.Test;

/**
* @author Vojtech Krasa
*/
public class JSCodeFormatterFacadeTest {

  public static final String INPUT = "/**\n" +
      " * Wrapper for java.lang.Object.wait\n" +
      "       *\n" +
      "       * can be called only within a sync method\n" +
      " */\n" +
      "function wait(object) {\n" +
      "                 var objClazz = java.lang.Class.forName('java.lang.Object');\n" +
      "    var waitMethod = objClazz.getMethod('wait', null);\n" +
      "    waitMethod.invoke(object, null);\n" +
      "} \n" +
      "wait.docString = \"convenient wrapper for java.lang.Object.wait method\";";

  public static final String FORMATTED = "/**\n" +
      " * Wrapper for java.lang.Object.wait\n" +
      " *\n" +
      " * can be called only within a sync method\n" +
      " */\n" +
      "function wait(object) {\n" +
      "\tvar objClazz = java.lang.Class.forName('java.lang.Object');\n" +
      "\tvar waitMethod = objClazz.getMethod('wait', null);\n" +
      "\twaitMethod.invoke(object, null);\n" +
      "}\n" +
      "wait.docString = \"convenient wrapper for java.lang.Object.wait method\";";

  public static final String PATH_TO_CONFIG_FILE = "test/resources/org.eclipse.wst.jsdt.core.prefs";

  @Before
  public void setUp() throws Exception {
    Settings settings = new Settings();
    settings.setPathToConfigFileJS(PATH_TO_CONFIG_FILE);
    eclipseCodeFormatterFacade = new JSCodeFormatterFacade(new JSPropertiesProvider(settings));
  }

  protected CodeFormatterFacade eclipseCodeFormatterFacade;

  @Test
  public void testFormat() throws Exception {
    String output = eclipseCodeFormatterFacade.format(INPUT, 0, INPUT.length());
    Assert.assertEquals(FORMATTED, output);
  }

  @Test
  public void testFormat2() throws Exception {
    String output = eclipseCodeFormatterFacade.format(INPUT, 10, INPUT.length() - 10);
    Assert.assertEquals(FORMATTED, output);
  }

  @Test
  public void testEndOffset() throws Exception {
    eclipseCodeFormatterFacade.format(INPUT, INPUT.length() - 11, INPUT.length() - 10);
  }

}
TOP

Related Classes of krasa.formatter.eclipse.JSCodeFormatterFacadeTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.