Permalink
Browse files

Apply '-' behaviour to blank padded format directives.

This commit addresses jruby issue #289.  The expected behaviour is documented in this rubyspec pull request: https://github.com/rubyspec/rubyspec/pull/153
  • Loading branch information...
1 parent eca1076 commit 6f86d35018412c6327e5bed92ec7135addbd6fda @tychobrailleur committed Sep 7, 2012
Showing with 11 additions and 1 deletion.
  1. +1 −1 src/org/jruby/util/TimeOutputFormatter.java
  2. +10 −0 test/org/jruby/util/TimeOutputFormatterTest.java
View
2 src/org/jruby/util/TimeOutputFormatter.java
@@ -121,7 +121,7 @@ public String format(String sequence) {
paddedWith = '0';
break;
case '-':
- sequence = sequence.replaceAll("^[0]", "");
+ sequence = sequence.replaceAll("^[0 ]", "");
break;
}
}
View
10 test/org/jruby/util/TimeOutputFormatterTest.java
@@ -88,4 +88,14 @@ public void testPaddingWithUpperCase() {
TimeOutputFormatter formatter = TimeOutputFormatter.getFormatter("%^5H");
assertEquals(" UP", formatter.format("up"));
}
+
+ public void testFormatNoPaddingForBlankPaddedValues() {
+ TimeOutputFormatter formatter = TimeOutputFormatter.getFormatter("%-3H");
+ assertEquals("up", formatter.format(" up"));
+ }
+
+ public void testFormatNoPaddingForZeroPaddedValues() {
+ TimeOutputFormatter formatter = TimeOutputFormatter.getFormatter("%-3H");
+ assertEquals("up", formatter.format("0up"));
+ }
}

0 comments on commit 6f86d35

Please sign in to comment.