From cb8f278f42f3c8c7c69314c8cf68175718298216 Mon Sep 17 00:00:00 2001 From: Florian Weikert Date: Thu, 10 Dec 2015 23:30:23 +0000 Subject: Skylark: implemented str.splitlines() -- MOS_MIGRATED_REVID=109942021 --- .../build/lib/syntax/MethodLibraryTest.java | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java') 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 @@ -39,6 +39,53 @@ public class MethodLibraryTest extends EvaluationTestCase { setFailFast(true); } + @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( -- cgit v1.2.3