Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: tools/gn/functions_unittest.cc

Issue 2095043005: Add GN split_list function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/functions.cc ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/functions_unittest.cc
diff --git a/tools/gn/functions_unittest.cc b/tools/gn/functions_unittest.cc
index 22670710704c6969255185ae5b3c34ca2b910a50..c6681bf5909b78362e2c0a80c77abfbe5ef956e6 100644
--- a/tools/gn/functions_unittest.cc
+++ b/tools/gn/functions_unittest.cc
@@ -90,3 +90,39 @@ TEST(Functions, FunctionsWithBlock) {
result = defined_with_scope.parsed()->Execute(setup.scope(), &err);
EXPECT_TRUE(err.has_error());
}
+
+TEST(Functions, SplitList) {
+ TestWithScope setup;
+
+ TestParseInput input(
+ // Empty input with varying result items.
+ "out1 = split_list([], 1)\n"
+ "out2 = split_list([], 3)\n"
+ "print(\"empty = $out1 $out2\")\n"
+
+ // One item input.
+ "out3 = split_list([1], 1)\n"
+ "out4 = split_list([1], 2)\n"
+ "print(\"one = $out3 $out4\")\n"
+
+ // Multiple items.
+ "out5 = split_list([1, 2, 3, 4, 5, 6, 7, 8, 9], 2)\n"
+ "print(\"many = $out5\")\n"
+
+ // Rounding.
+ "out6 = split_list([1, 2, 3, 4, 5, 6], 4)\n"
+ "print(\"rounding = $out6\")\n"
+ );
+ ASSERT_FALSE(input.has_error());
+
+ Err err;
+ input.parsed()->Execute(setup.scope(), &err);
+ ASSERT_FALSE(err.has_error()) << err.message();
+
+ EXPECT_EQ(
+ "empty = [[]] [[], [], []]\n"
+ "one = [[1]] [[1], []]\n"
+ "many = [[1, 2, 3, 4, 5], [6, 7, 8, 9]]\n"
+ "rounding = [[1, 2], [3, 4], [5], [6]]\n",
+ setup.print_output());
+}
« no previous file with comments | « tools/gn/functions.cc ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698