Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "text/Printer.h" |
| 18 | |
| 19 | #include "io/StringStream.h" |
| 20 | #include "test/Test.h" |
| 21 | |
| 22 | using ::aapt::io::StringOutputStream; |
| 23 | using ::android::StringPiece; |
| 24 | using ::testing::StrEq; |
| 25 | |
| 26 | namespace aapt { |
| 27 | namespace text { |
| 28 | |
| 29 | TEST(PrinterTest, PrintsToStreamWithIndents) { |
| 30 | std::string result; |
| 31 | StringOutputStream out(&result); |
| 32 | Printer printer(&out); |
| 33 | |
| 34 | printer.Print("Hello"); |
| 35 | out.Flush(); |
| 36 | EXPECT_THAT(result, StrEq("Hello")); |
| 37 | |
| 38 | printer.Println(); |
| 39 | out.Flush(); |
| 40 | EXPECT_THAT(result, StrEq("Hello\n")); |
| 41 | |
| 42 | // This shouldn't print anything yet. |
| 43 | printer.Indent(); |
| 44 | out.Flush(); |
| 45 | EXPECT_THAT(result, StrEq("Hello\n")); |
| 46 | |
| 47 | // Now we should see the indent. |
| 48 | printer.Print("world!"); |
| 49 | out.Flush(); |
| 50 | EXPECT_THAT(result, StrEq("Hello\n world!")); |
| 51 | |
| 52 | printer.Println(" What a\nlovely day."); |
| 53 | out.Flush(); |
| 54 | EXPECT_THAT(result, StrEq("Hello\n world! What a\n lovely day.\n")); |
| 55 | |
| 56 | // This shouldn't print anything yet. |
| 57 | printer.Undent(); |
| 58 | out.Flush(); |
| 59 | EXPECT_THAT(result, StrEq("Hello\n world! What a\n lovely day.\n")); |
| 60 | |
| 61 | printer.Println("Isn't it?"); |
| 62 | out.Flush(); |
| 63 | EXPECT_THAT(result, StrEq("Hello\n world! What a\n lovely day.\nIsn't it?\n")); |
| 64 | } |
| 65 | |
| 66 | } // namespace text |
| 67 | } // namespace aapt |