// Path: em.common/src/main/java/com/commsen/em/maven/util/Version.java
// public class Version {
// 	
// 	
// 	public static String semantic (String version) {
// 		
// 		if (version == null || version.trim().isEmpty()) return "0.0.0";
// 
// 		int dashIndex = version.indexOf("-");
// 		String main = version;
// 		String rest = "";
// 		if (dashIndex >= 0) {
// 			main = version.substring(0, dashIndex);
// 			rest = version.substring(dashIndex+1);
// 		}
// 
// 		String[] groups = main.split("\\.");
// 		
// 		StringBuilder result = new StringBuilder();
// 		StringBuilder additional = new StringBuilder();
// 
// 		int semGroups = 0;
// 		for (int i = 0; i < groups.length; i++) {
// 			Pair<Integer, String> pair = digitalize(groups[i]);
// 			if (pair.getFirst() > 0 || semGroups < 3) {
// 				if (semGroups != 0) {
// 					result.append(".");
// 				}
// 				result.append(pair.getFirst());
// 				semGroups++;
// 			}
// 			if (!pair.getSecond().isEmpty()) {
// 				if (additional.length() > 0 ) additional.append("_");
// 				additional.append(pair.getSecond().replaceAll("\\.", "_"));
// 			}
// 		}
// 		
// 		if (semGroups == 0) {
// 			result.append("0.0.0");
// 		} else {
// 			while (semGroups++ < 3) {
// 				result.append(".0");
// 			}
// 		}
// 		
// 		String delimiter = ".";
// 		if (additional.length() > 0) {
// 			result.append(delimiter).append(additional);
// 			delimiter = "-";
// 		}
// 
// 		if (rest.length() > 0) {
// 			result.append(delimiter).append(rest.replaceAll("\\.", "_"));
// 		}
// 		
// 		return result.toString();
// 	}
// 
// 	public static Pair<Integer, String> digitalize (String string) {
// 		
// 		int i = 0;
// 		while (i < string.length() && Character.isDigit(string.charAt(i))) i++;
// 		
// 		if (i == 0) {
// 			return  new Pair<Integer, String>(0, string.trim());
// 		}
// 		
// 		Integer number = Integer.parseInt(string.substring(0, i));
// 		String rest = string.substring(i).trim();
// 		
// 		return  new Pair<Integer, String>(number, rest);
// 	}
// 	
// 	
// }


import org.junit.Assert;
import org.junit.Test;
import com.commsen.em.maven.util.Version;
package com.commsen.en.maven.util;



public class VersionTest {

	@Test
	public void semanticVersioning () {

		// more than 3 digits
		Assert.assertEquals("1.2.3.4", Version.semantic("1.2.3.4"));
		Assert.assertEquals("1.2.3.4.5", Version.semantic("1.2.3.4.5"));
		
		// 3 digits
		Assert.assertEquals("1.2.3", Version.semantic("1.2.3"));
		Assert.assertEquals("1.2.3.RC1", Version.semantic("1.2.3.RC1"));
		Assert.assertEquals("1.2.3.SNAPSHOT", Version.semantic("1.2.3-SNAPSHOT"));
		Assert.assertEquals("1.2.3.a", Version.semantic("1.2.3a"));
		Assert.assertEquals("1.2.3.a_b", Version.semantic("1.2a.3b"));
		Assert.assertEquals("1.2.3.a_b_c", Version.semantic("1a.2b.3c"));
		Assert.assertEquals("1.2.3.a_b_c_RC1", Version.semantic("1a.2b.3c.RC1"));
		Assert.assertEquals("1.2.3.a_b_c_RC1-SNAPSHOT", Version.semantic("1a.2b.3c.RC1-SNAPSHOT"));
		
		// 2 digits
		Assert.assertEquals("1.2.0", Version.semantic("1.2"));
		Assert.assertEquals("1.2.0.RC1", Version.semantic("1.2.RC1"));
		Assert.assertEquals("1.2.0.SNAPSHOT", Version.semantic("1.2-SNAPSHOT"));
		Assert.assertEquals("1.2.0.a", Version.semantic("1.2a"));
		Assert.assertEquals("1.2.0.a_b", Version.semantic("1a.2b"));
		Assert.assertEquals("1.2.0.a_b_RC1", Version.semantic("1a.2b.RC1"));
		Assert.assertEquals("1.2.0.a_b_RC1-SNAPSHOT", Version.semantic("1a.2b.RC1-SNAPSHOT"));

		// 1 digit
		Assert.assertEquals("1.0.0", Version.semantic("1"));
		Assert.assertEquals("1.0.0.RC1", Version.semantic("1.RC1"));
		Assert.assertEquals("1.0.0.SNAPSHOT", Version.semantic("1-SNAPSHOT"));
		Assert.assertEquals("1.0.0.a", Version.semantic("1a"));
		Assert.assertEquals("1.0.0.a_RC1", Version.semantic("1a.RC1"));
		Assert.assertEquals("1.0.0.a_RC1-SNAPSHOT", Version.semantic("1a.RC1-SNAPSHOT"));

		// no digit
		Assert.assertEquals("0.0.0", Version.semantic(null));
		Assert.assertEquals("0.0.0", Version.semantic(""));
		Assert.assertEquals("0.0.0", Version.semantic("   \t  "));
// Path: em.common/src/main/java/com/commsen/em/maven/util/Version.java
// public class Version {
// 	
// 	
// 	public static String semantic (String version) {
// 		
// 		if (version == null || version.trim().isEmpty()) return "0.0.0";
// 
// 		int dashIndex = version.indexOf("-");
// 		String main = version;
// 		String rest = "";
// 		if (dashIndex >= 0) {
// 			main = version.substring(0, dashIndex);
// 			rest = version.substring(dashIndex+1);
// 		}
// 
// 		String[] groups = main.split("\\.");
// 		
// 		StringBuilder result = new StringBuilder();
// 		StringBuilder additional = new StringBuilder();
// 
// 		int semGroups = 0;
// 		for (int i = 0; i < groups.length; i++) {
// 			Pair<Integer, String> pair = digitalize(groups[i]);
// 			if (pair.getFirst() > 0 || semGroups < 3) {
// 				if (semGroups != 0) {
// 					result.append(".");
// 				}
// 				result.append(pair.getFirst());
// 				semGroups++;
// 			}
// 			if (!pair.getSecond().isEmpty()) {
// 				if (additional.length() > 0 ) additional.append("_");
// 				additional.append(pair.getSecond().replaceAll("\\.", "_"));
// 			}
// 		}
// 		
// 		if (semGroups == 0) {
// 			result.append("0.0.0");
// 		} else {
// 			while (semGroups++ < 3) {
// 				result.append(".0");
// 			}
// 		}
// 		
// 		String delimiter = ".";
// 		if (additional.length() > 0) {
// 			result.append(delimiter).append(additional);
// 			delimiter = "-";
// 		}
// 
// 		if (rest.length() > 0) {
// 			result.append(delimiter).append(rest.replaceAll("\\.", "_"));
// 		}
// 		
// 		return result.toString();
// 	}
// 
// 	public static Pair<Integer, String> digitalize (String string) {
// 		
// 		int i = 0;
// 		while (i < string.length() && Character.isDigit(string.charAt(i))) i++;
// 		
// 		if (i == 0) {
// 			return  new Pair<Integer, String>(0, string.trim());
// 		}
// 		
// 		Integer number = Integer.parseInt(string.substring(0, i));
// 		String rest = string.substring(i).trim();
// 		
// 		return  new Pair<Integer, String>(number, rest);
// 	}
// 	
// 	
// }


// Path: em-maven-extension/src/test/java/com/commsen/en/maven/util/VersionTest.java
import org.junit.Assert;
import org.junit.Test;
import com.commsen.em.maven.util.Version;

package com.commsen.en.maven.util;



public class VersionTest {

	@Test
	public void semanticVersioning () {

		// more than 3 digits
		Assert.assertEquals("1.2.3.4", Version.semantic("1.2.3.4"));
		Assert.assertEquals("1.2.3.4.5", Version.semantic("1.2.3.4.5"));
		
		// 3 digits
		Assert.assertEquals("1.2.3", Version.semantic("1.2.3"));
		Assert.assertEquals("1.2.3.RC1", Version.semantic("1.2.3.RC1"));
		Assert.assertEquals("1.2.3.SNAPSHOT", Version.semantic("1.2.3-SNAPSHOT"));
		Assert.assertEquals("1.2.3.a", Version.semantic("1.2.3a"));
		Assert.assertEquals("1.2.3.a_b", Version.semantic("1.2a.3b"));
		Assert.assertEquals("1.2.3.a_b_c", Version.semantic("1a.2b.3c"));
		Assert.assertEquals("1.2.3.a_b_c_RC1", Version.semantic("1a.2b.3c.RC1"));
		Assert.assertEquals("1.2.3.a_b_c_RC1-SNAPSHOT", Version.semantic("1a.2b.3c.RC1-SNAPSHOT"));
		
		// 2 digits
		Assert.assertEquals("1.2.0", Version.semantic("1.2"));
		Assert.assertEquals("1.2.0.RC1", Version.semantic("1.2.RC1"));
		Assert.assertEquals("1.2.0.SNAPSHOT", Version.semantic("1.2-SNAPSHOT"));
		Assert.assertEquals("1.2.0.a", Version.semantic("1.2a"));
		Assert.assertEquals("1.2.0.a_b", Version.semantic("1a.2b"));
		Assert.assertEquals("1.2.0.a_b_RC1", Version.semantic("1a.2b.RC1"));
		Assert.assertEquals("1.2.0.a_b_RC1-SNAPSHOT", Version.semantic("1a.2b.RC1-SNAPSHOT"));

		// 1 digit
		Assert.assertEquals("1.0.0", Version.semantic("1"));
		Assert.assertEquals("1.0.0.RC1", Version.semantic("1.RC1"));
		Assert.assertEquals("1.0.0.SNAPSHOT", Version.semantic("1-SNAPSHOT"));
		Assert.assertEquals("1.0.0.a", Version.semantic("1a"));
		Assert.assertEquals("1.0.0.a_RC1", Version.semantic("1a.RC1"));
		Assert.assertEquals("1.0.0.a_RC1-SNAPSHOT", Version.semantic("1a.RC1-SNAPSHOT"));

		// no digit
		Assert.assertEquals("0.0.0", Version.semantic(null));
		Assert.assertEquals("0.0.0", Version.semantic(""));
		Assert.assertEquals("0.0.0", Version.semantic("   \t  "));
		Assert.assertEquals("0.0.0.A", Version.semantic("A"));