OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/functions.h" | 5 #include "tools/gn/functions.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 EXPECT_FALSE(defined_no_scope.has_error()); | 83 EXPECT_FALSE(defined_no_scope.has_error()); |
84 result = defined_no_scope.parsed()->Execute(setup.scope(), &err); | 84 result = defined_no_scope.parsed()->Execute(setup.scope(), &err); |
85 EXPECT_FALSE(err.has_error()); | 85 EXPECT_FALSE(err.has_error()); |
86 | 86 |
87 // A block to defined should fail. | 87 // A block to defined should fail. |
88 TestParseInput defined_with_scope("defined(foo) {}"); | 88 TestParseInput defined_with_scope("defined(foo) {}"); |
89 EXPECT_FALSE(defined_with_scope.has_error()); | 89 EXPECT_FALSE(defined_with_scope.has_error()); |
90 result = defined_with_scope.parsed()->Execute(setup.scope(), &err); | 90 result = defined_with_scope.parsed()->Execute(setup.scope(), &err); |
91 EXPECT_TRUE(err.has_error()); | 91 EXPECT_TRUE(err.has_error()); |
92 } | 92 } |
| 93 |
| 94 TEST(Functions, SplitList) { |
| 95 TestWithScope setup; |
| 96 |
| 97 TestParseInput input( |
| 98 // Empty input with varying result items. |
| 99 "out1 = split_list([], 1)\n" |
| 100 "out2 = split_list([], 3)\n" |
| 101 "print(\"empty = $out1 $out2\")\n" |
| 102 |
| 103 // One item input. |
| 104 "out3 = split_list([1], 1)\n" |
| 105 "out4 = split_list([1], 2)\n" |
| 106 "print(\"one = $out3 $out4\")\n" |
| 107 |
| 108 // Multiple items. |
| 109 "out5 = split_list([1, 2, 3, 4, 5, 6, 7, 8, 9], 2)\n" |
| 110 "print(\"many = $out5\")\n" |
| 111 |
| 112 // Rounding. |
| 113 "out6 = split_list([1, 2, 3, 4, 5, 6], 4)\n" |
| 114 "print(\"rounding = $out6\")\n" |
| 115 ); |
| 116 ASSERT_FALSE(input.has_error()); |
| 117 |
| 118 Err err; |
| 119 input.parsed()->Execute(setup.scope(), &err); |
| 120 ASSERT_FALSE(err.has_error()) << err.message(); |
| 121 |
| 122 EXPECT_EQ( |
| 123 "empty = [[]] [[], [], []]\n" |
| 124 "one = [[1]] [[1], []]\n" |
| 125 "many = [[1, 2, 3, 4, 5], [6, 7, 8, 9]]\n" |
| 126 "rounding = [[1, 2], [3, 4], [5], [6]]\n", |
| 127 setup.print_output()); |
| 128 } |
OLD | NEW |