OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/string_tokenizer.h" | 5 #include "base/string_tokenizer.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 using std::string; | 8 using std::string; |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 EXPECT_TRUE(t.GetNext()); | 24 EXPECT_TRUE(t.GetNext()); |
25 EXPECT_EQ(string("a"), t.token()); | 25 EXPECT_EQ(string("a"), t.token()); |
26 | 26 |
27 EXPECT_TRUE(t.GetNext()); | 27 EXPECT_TRUE(t.GetNext()); |
28 EXPECT_EQ(string("test"), t.token()); | 28 EXPECT_EQ(string("test"), t.token()); |
29 | 29 |
30 EXPECT_FALSE(t.GetNext()); | 30 EXPECT_FALSE(t.GetNext()); |
31 } | 31 } |
32 | 32 |
| 33 TEST(StringTokenizerTest, Reset) { |
| 34 string input = "this is a test"; |
| 35 StringTokenizer t(input, " "); |
| 36 |
| 37 for (int i = 0; i < 2; ++i) { |
| 38 EXPECT_TRUE(t.GetNext()); |
| 39 EXPECT_EQ(string("this"), t.token()); |
| 40 |
| 41 EXPECT_TRUE(t.GetNext()); |
| 42 EXPECT_EQ(string("is"), t.token()); |
| 43 |
| 44 EXPECT_TRUE(t.GetNext()); |
| 45 EXPECT_EQ(string("a"), t.token()); |
| 46 |
| 47 EXPECT_TRUE(t.GetNext()); |
| 48 EXPECT_EQ(string("test"), t.token()); |
| 49 |
| 50 EXPECT_FALSE(t.GetNext()); |
| 51 t.Reset(); |
| 52 } |
| 53 } |
| 54 |
33 TEST(StringTokenizerTest, RetDelims) { | 55 TEST(StringTokenizerTest, RetDelims) { |
34 string input = "this is a test"; | 56 string input = "this is a test"; |
35 StringTokenizer t(input, " "); | 57 StringTokenizer t(input, " "); |
36 t.set_options(StringTokenizer::RETURN_DELIMS); | 58 t.set_options(StringTokenizer::RETURN_DELIMS); |
37 | 59 |
38 EXPECT_TRUE(t.GetNext()); | 60 EXPECT_TRUE(t.GetNext()); |
39 EXPECT_EQ(string("this"), t.token()); | 61 EXPECT_EQ(string("this"), t.token()); |
40 | 62 |
41 EXPECT_TRUE(t.GetNext()); | 63 EXPECT_TRUE(t.GetNext()); |
42 EXPECT_EQ(string(" "), t.token()); | 64 EXPECT_EQ(string(" "), t.token()); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 t.set_quote_chars("'"); | 220 t.set_quote_chars("'"); |
199 | 221 |
200 EXPECT_TRUE(t.GetNext()); | 222 EXPECT_TRUE(t.GetNext()); |
201 EXPECT_EQ(string("foo='a, b'"), t.token()); | 223 EXPECT_EQ(string("foo='a, b'"), t.token()); |
202 | 224 |
203 EXPECT_TRUE(t.GetNext()); | 225 EXPECT_TRUE(t.GetNext()); |
204 EXPECT_EQ(string("bar"), t.token()); | 226 EXPECT_EQ(string("bar"), t.token()); |
205 | 227 |
206 EXPECT_FALSE(t.GetNext()); | 228 EXPECT_FALSE(t.GetNext()); |
207 } | 229 } |
OLD | NEW |