ModuleNameUtil { public static String toModuleName(String fileName) { String extension = FileUtil.getExtension(fileName); if (!extension.equals("js") || extension.isEmpty()) { return fileName; } return fileName.substring( 0, fileName.length() - extension.length() - 1); }  static String getDependencyPath(
		String moduleName, String dependency); static String getModuleId(JSPackage jsPackage, String moduleName); static String getModuleResolvedId(
		JSPackage jsPackage, String moduleName); static String getPackageName(String moduleName); static String getPackagePath(String moduleName); static boolean isLocalModuleName(String moduleName); static boolean isReservedModuleName(String moduleName); static String toFileName(String moduleName); static String toModuleName(String fileName);  }
@Test public void testToModuleName() { Assert.assertEquals( "a-module", ModuleNameUtil.toModuleName("a-module")); Assert.assertEquals( "a-module", ModuleNameUtil.toModuleName("a-module.js")); Assert.assertEquals( "a-package/a-module", ModuleNameUtil.toModuleName("a-package/a-module")); Assert.assertEquals( "a-package/a-module", ModuleNameUtil.toModuleName("a-package/a-module.js")); Assert.assertEquals( "a-package/a-folder/a-module", ModuleNameUtil.toModuleName("a-package/a-folder/a-module")); Assert.assertEquals( "a-package/a-folder/a-module", ModuleNameUtil.toModuleName("a-package/a-folder/a-module.js")); }
@Test public void testToModuleNameWithNonjsExtensions() { Assert.assertEquals( "a-module.es", ModuleNameUtil.toModuleName("a-module.es")); Assert.assertEquals( "a-folder/a-module.es", ModuleNameUtil.toModuleName("a-folder/a-module.es")); }
@Test public void testToModuleNameWithRelativePaths() { Assert.assertEquals( "./a-module", ModuleNameUtil.toModuleName("./a-module")); Assert.assertEquals( "./a-module", ModuleNameUtil.toModuleName("./a-module.js")); Assert.assertEquals( "../a-module", ModuleNameUtil.toModuleName("../a-module")); Assert.assertEquals( "../a-module", ModuleNameUtil.toModuleName("../a-module.js")); }