|
|
@ -48,6 +48,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.eclipse.jgit.lib; |
|
|
|
package org.eclipse.jgit.lib; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static java.util.concurrent.TimeUnit.DAYS; |
|
|
|
|
|
|
|
import static java.util.concurrent.TimeUnit.HOURS; |
|
|
|
|
|
|
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
|
|
|
|
|
|
|
import static java.util.concurrent.TimeUnit.MINUTES; |
|
|
|
|
|
|
|
import static java.util.concurrent.TimeUnit.SECONDS; |
|
|
|
import static org.junit.Assert.assertArrayEquals; |
|
|
|
import static org.junit.Assert.assertArrayEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
@ -64,6 +69,7 @@ import java.util.Arrays; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
|
|
import org.eclipse.jgit.api.MergeCommand.FastForwardMode; |
|
|
|
import org.eclipse.jgit.api.MergeCommand.FastForwardMode; |
|
|
|
import org.eclipse.jgit.errors.ConfigInvalidException; |
|
|
|
import org.eclipse.jgit.errors.ConfigInvalidException; |
|
|
@ -870,4 +876,93 @@ public class ConfigTest { |
|
|
|
c.fromText(content); |
|
|
|
c.fromText(content); |
|
|
|
return c; |
|
|
|
return c; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testTimeUnit() throws ConfigInvalidException { |
|
|
|
|
|
|
|
assertEquals(0, parseTime("0", MILLISECONDS)); |
|
|
|
|
|
|
|
assertEquals(2, parseTime("2ms", MILLISECONDS)); |
|
|
|
|
|
|
|
assertEquals(200, parseTime("200 milliseconds", MILLISECONDS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(0, parseTime("0s", SECONDS)); |
|
|
|
|
|
|
|
assertEquals(2, parseTime("2s", SECONDS)); |
|
|
|
|
|
|
|
assertEquals(231, parseTime("231sec", SECONDS)); |
|
|
|
|
|
|
|
assertEquals(1, parseTime("1second", SECONDS)); |
|
|
|
|
|
|
|
assertEquals(300, parseTime("300 seconds", SECONDS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(2, parseTime("2m", MINUTES)); |
|
|
|
|
|
|
|
assertEquals(2, parseTime("2min", MINUTES)); |
|
|
|
|
|
|
|
assertEquals(1, parseTime("1 minute", MINUTES)); |
|
|
|
|
|
|
|
assertEquals(10, parseTime("10 minutes", MINUTES)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(5, parseTime("5h", HOURS)); |
|
|
|
|
|
|
|
assertEquals(5, parseTime("5hr", HOURS)); |
|
|
|
|
|
|
|
assertEquals(1, parseTime("1hour", HOURS)); |
|
|
|
|
|
|
|
assertEquals(48, parseTime("48hours", HOURS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(5, parseTime("5 h", HOURS)); |
|
|
|
|
|
|
|
assertEquals(5, parseTime("5 hr", HOURS)); |
|
|
|
|
|
|
|
assertEquals(1, parseTime("1 hour", HOURS)); |
|
|
|
|
|
|
|
assertEquals(48, parseTime("48 hours", HOURS)); |
|
|
|
|
|
|
|
assertEquals(48, parseTime("48 \t \r hours", HOURS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(4, parseTime("4d", DAYS)); |
|
|
|
|
|
|
|
assertEquals(1, parseTime("1day", DAYS)); |
|
|
|
|
|
|
|
assertEquals(14, parseTime("14days", DAYS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(7, parseTime("1w", DAYS)); |
|
|
|
|
|
|
|
assertEquals(7, parseTime("1week", DAYS)); |
|
|
|
|
|
|
|
assertEquals(14, parseTime("2w", DAYS)); |
|
|
|
|
|
|
|
assertEquals(14, parseTime("2weeks", DAYS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(30, parseTime("1mon", DAYS)); |
|
|
|
|
|
|
|
assertEquals(30, parseTime("1month", DAYS)); |
|
|
|
|
|
|
|
assertEquals(60, parseTime("2mon", DAYS)); |
|
|
|
|
|
|
|
assertEquals(60, parseTime("2months", DAYS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(365, parseTime("1y", DAYS)); |
|
|
|
|
|
|
|
assertEquals(365, parseTime("1year", DAYS)); |
|
|
|
|
|
|
|
assertEquals(365 * 2, parseTime("2years", DAYS)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private long parseTime(String value, TimeUnit unit) |
|
|
|
|
|
|
|
throws ConfigInvalidException { |
|
|
|
|
|
|
|
Config c = parse("[a]\na=" + value + "\n"); |
|
|
|
|
|
|
|
return c.getTimeUnit("a", null, "a", 0, unit); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testTimeUnitDefaultValue() throws ConfigInvalidException { |
|
|
|
|
|
|
|
// value not present
|
|
|
|
|
|
|
|
assertEquals(20, parse("[a]\na=0\n").getTimeUnit("a", null, "b", 20, |
|
|
|
|
|
|
|
MILLISECONDS)); |
|
|
|
|
|
|
|
// value is empty
|
|
|
|
|
|
|
|
assertEquals(20, parse("[a]\na=\" \"\n").getTimeUnit("a", null, "a", 20, |
|
|
|
|
|
|
|
MILLISECONDS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// value is not numeric
|
|
|
|
|
|
|
|
assertEquals(20, parse("[a]\na=test\n").getTimeUnit("a", null, "a", 20, |
|
|
|
|
|
|
|
MILLISECONDS)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testTimeUnitInvalid() throws ConfigInvalidException { |
|
|
|
|
|
|
|
expectedEx.expect(IllegalArgumentException.class); |
|
|
|
|
|
|
|
expectedEx |
|
|
|
|
|
|
|
.expectMessage("Invalid time unit value: a.a=1 monttthhh"); |
|
|
|
|
|
|
|
parseTime("1 monttthhh", DAYS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testTimeUnitInvalidWithSection() throws ConfigInvalidException { |
|
|
|
|
|
|
|
Config c = parse("[a \"b\"]\na=1 monttthhh\n"); |
|
|
|
|
|
|
|
expectedEx.expect(IllegalArgumentException.class); |
|
|
|
|
|
|
|
expectedEx.expectMessage("Invalid time unit value: a.b.a=1 monttthhh"); |
|
|
|
|
|
|
|
c.getTimeUnit("a", "b", "a", 0, DAYS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testTimeUnitNegative() throws ConfigInvalidException { |
|
|
|
|
|
|
|
expectedEx.expect(IllegalArgumentException.class); |
|
|
|
|
|
|
|
parseTime("-1", MILLISECONDS); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|