aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
diff options
context:
space:
mode:
authorGravatar Florian Weikert <fwe@google.com>2015-12-10 23:30:23 +0000
committerGravatar David Chen <dzc@google.com>2015-12-11 17:08:32 +0000
commitcb8f278f42f3c8c7c69314c8cf68175718298216 (patch)
tree8f0f1cc806c15a1c2520c248f031794a640df0f5 /src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
parentcb237316c3b5deb1f4c58541ce736a3ed8dde693 (diff)
Skylark: implemented str.splitlines()
-- MOS_MIGRATED_REVID=109942021
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java47
1 files changed, 47 insertions, 0 deletions
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 a3f71fa2b9..76f46bfa35 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
@@ -40,6 +40,53 @@ public class MethodLibraryTest extends EvaluationTestCase {
}
@Test
+ public void testSplitLines_EmptyLine() throws Exception {
+ new SkylarkTest().testEval("''.splitlines()", "[]").testEval("'\\n'.splitlines()", "['']");
+ }
+
+ @Test
+ public void testSplitLines_StartsWithLineBreak() throws Exception {
+ new SkylarkTest().testEval("'\\ntest'.splitlines()", "['', 'test']");
+ }
+
+ @Test
+ public void testSplitLines_EndsWithLineBreak() throws Exception {
+ new SkylarkTest().testEval("'test\\n'.splitlines()", "['test']");
+ }
+
+ @Test
+ public void testSplitLines_DifferentLineBreaks() throws Exception {
+ new SkylarkTest().testEval(
+ "'this\\nis\\na\\ntest'.splitlines()", "['this', 'is', 'a', 'test']");
+ }
+
+ @Test
+ public void testSplitLines_OnlyLineBreaks() throws Exception {
+ new SkylarkTest()
+ .testEval("'\\n\\n\\n'.splitlines()", "['', '', '']")
+ .testEval("'\\r\\r\\r'.splitlines()", "['', '', '']")
+ .testEval("'\\n\\r\\n\\r'.splitlines()", "['', '', '']")
+ .testEval("'\\r\\n\\r\\n\\r\\n'.splitlines()", "['', '', '']");
+ }
+
+ @Test
+ public void testSplitLines_EscapedSequences() throws Exception {
+ new SkylarkTest().testEval("'\\n\\\\n\\\\\\n'.splitlines()", "['', '\\\\n\\\\']");
+ }
+
+ @Test
+ public void testSplitLines_KeepEnds() throws Exception {
+ new SkylarkTest()
+ .testEval("''.splitlines(True)", "[]")
+ .testEval("'\\n'.splitlines(True)", "['\\n']")
+ .testEval(
+ "'this\\nis\\r\\na\\rtest'.splitlines(True)", "['this\\n', 'is\\r\\n', 'a\\r', 'test']")
+ .testEval("'\\ntest'.splitlines(True)", "['\\n', 'test']")
+ .testEval("'test\\n'.splitlines(True)", "['test\\n']")
+ .testEval("'\\n\\\\n\\\\\\n'.splitlines(True)", "['\\n', '\\\\n\\\\\\n']");
+ }
+
+ @Test
public void testStackTraceLocation() throws Exception {
new SkylarkTest().testIfErrorContains(
"Traceback (most recent call last):\n\t"