diff options
author | Googler <noreply@google.com> | 2015-10-20 20:51:27 +0000 |
---|---|---|
committer | Han-Wen Nienhuys <hanwen@google.com> | 2015-10-21 14:39:02 +0000 |
commit | 84075f3584a2f38b489ed8fbc5da464c95653525 (patch) | |
tree | 7bd9cd62894885a4133e79e1150ee78c4ab43e3b /src | |
parent | 714873552264cc7eca6c1ec98b3b811837e3d707 (diff) |
Add some strip/rstrip/lstrip tests
and fix the bugs that showed up as a result.
--
MOS_MIGRATED_REVID=105896905
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java | 6 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java | 25 |
2 files changed, 20 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java index 62cb8df6b6..e14fbad18a 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java @@ -166,7 +166,7 @@ public class MethodLibrary { name = "chars", type = String.class, doc = "The characters to remove", - defaultValue = "' \t'" + defaultValue = "' \\t\\n\\r'" // \f \v are illegal in Skylark ) } ) @@ -195,7 +195,7 @@ public class MethodLibrary { name = "chars", type = String.class, doc = "The characters to remove", - defaultValue = "' \t'" + defaultValue = "' \\t\\n\\r'" // \f \v are illegal in Skylark ) } ) @@ -224,7 +224,7 @@ public class MethodLibrary { name = "chars", type = String.class, doc = "The characters to remove", - defaultValue = "' \t'" + defaultValue = "' \\t\\n\\r'" // \f \v are illegal in Skylark ) } ) diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java index 86e8d8fbdf..c78fba035c 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java @@ -1093,29 +1093,38 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testLStrip() throws Exception { new BothModesTest() - .testStatement("'abc'.lstrip('')", "abc") + .testStatement("'a b c'.lstrip('')", "a b c") .testStatement("'abcba'.lstrip('ba')", "cba") .testStatement("'abc'.lstrip('xyz')", "abc") - .testStatement("' abc '.lstrip()", "abc "); + .testStatement("' a b c '.lstrip()", "a b c ") + // the "\\"s are because Java absorbs one level of "\"s + .testStatement("' \\t\\na b c '.lstrip()", "a b c ") + .testStatement("' a b c '.lstrip('')", " a b c "); } @Test public void testRStrip() throws Exception { new BothModesTest() - .testStatement("'abc'.rstrip('')", "abc") + .testStatement("'a b c'.rstrip('')", "a b c") .testStatement("'abcba'.rstrip('ba')", "abc") .testStatement("'abc'.rstrip('xyz')", "abc") - .testStatement("' abc '.rstrip()", " abc"); + .testStatement("' a b c '.rstrip()", " a b c") + // the "\\"s are because Java absorbs one level of "\"s + .testStatement("' a b c \\t \\n'.rstrip()", " a b c") + .testStatement("' a b c '.rstrip('')", " a b c "); } @Test public void testStrip() throws Exception { new BothModesTest() - .testStatement("'abc'.strip('')", "abc") + .testStatement("'a b c'.strip('')", "a b c") .testStatement("'abcba'.strip('ba')", "c") .testStatement("'abc'.strip('xyz')", "abc") - .testStatement("' abc '.strip()", "abc") - .testStatement("' abc\t'.strip()", "abc") - .testStatement("'abc'.strip('.')", "abc"); + .testStatement("' a b c '.strip()", "a b c") + .testStatement("' a b c\\t'.strip()", "a b c") + .testStatement("'a b c'.strip('.')", "a b c") + // the "\\"s are because Java absorbs one level of "\"s + .testStatement("' \\t\\n\\ra b c \\t\\n\\r'.strip()", "a b c") + .testStatement("' a b c '.strip('')", " a b c "); } } |