|
| 1 | +#include <scratchcpp/textbubble.h> |
| 2 | + |
| 3 | +#include "../common.h" |
| 4 | + |
| 5 | +using namespace libscratchcpp; |
| 6 | + |
| 7 | +TEST(TextBubbleTest, BubbleType) |
| 8 | +{ |
| 9 | + TextBubble bubble; |
| 10 | + ASSERT_EQ(bubble.type(), TextBubble::Type::Say); |
| 11 | + |
| 12 | + bubble.setType(TextBubble::Type::Think); |
| 13 | + ASSERT_EQ(bubble.type(), TextBubble::Type::Think); |
| 14 | + |
| 15 | + bubble.setType(TextBubble::Type::Say); |
| 16 | + ASSERT_EQ(bubble.type(), TextBubble::Type::Say); |
| 17 | +} |
| 18 | + |
| 19 | +TEST(TextBubbleTest, BubbleText) |
| 20 | +{ |
| 21 | + TextBubble bubble; |
| 22 | + ASSERT_TRUE(bubble.text().empty()); |
| 23 | + |
| 24 | + bubble.setText("hello"); |
| 25 | + ASSERT_EQ(bubble.text(), "hello"); |
| 26 | + |
| 27 | + bubble.setText("world"); |
| 28 | + ASSERT_EQ(bubble.text(), "world"); |
| 29 | + |
| 30 | + // longstr.length = 384, should be limited to 330 in bubble text |
| 31 | + std::string longstr = |
| 32 | + "EY8OUNzAqwgh7NRGk5TzCP3dkAhJy9TX" |
| 33 | + "Y9mqKElPjdQpKddYqjyCwUk2hx6YgVZV" |
| 34 | + "6BOdmZGxDMs8Hjv8W9G6j4gTxAWdOkzs" |
| 35 | + "8Ih80xzEDbvLilWsDwoB6FxH2kVVI4xs" |
| 36 | + "IXOETNQ6QMsCKLWc5XjHk2BS9nYvDGpJ" |
| 37 | + "uEmp9zIzFGT1kRSrOlU3ZwnN1YtvqFx" |
| 38 | + "3hkWVNtJ71dQ0PJHhOVQPUy19V01SPu3" |
| 39 | + "KIIS2wdSUVAc4RYMzepSveghzWbdcizy" |
| 40 | + "Tm1KKAj4svu9YoL8b9vsolG8gKunvKO7" |
| 41 | + "MurRKSeUbECELnJEKV6683xCq7RvmjAu" |
| 42 | + "2djZ54apiQc1lTixWns5GoG0SVNuFzHl" |
| 43 | + "q97qUiqiMecjVFM51YVif7c1Stip52Hl"; |
| 44 | + |
| 45 | + bubble.setText(longstr); |
| 46 | + ASSERT_EQ(bubble.text().length(), 330); |
| 47 | + ASSERT_EQ(bubble.text(), longstr.substr(0, 330)); |
| 48 | + |
| 49 | + // Integers should be left unchanged |
| 50 | + bubble.setText("8"); |
| 51 | + ASSERT_EQ(bubble.text(), "8"); |
| 52 | + |
| 53 | + bubble.setText("-52"); |
| 54 | + ASSERT_EQ(bubble.text(), "-52"); |
| 55 | + |
| 56 | + bubble.setText("0"); |
| 57 | + ASSERT_EQ(bubble.text(), "0"); |
| 58 | + |
| 59 | + // Non-integers should be rounded to 2 decimal places (no more, no less), unless they're small enough that rounding would display them as 0.00 (#478) |
| 60 | + bubble.setText("8.324"); |
| 61 | + ASSERT_EQ(bubble.text(), "8.32"); |
| 62 | + |
| 63 | + bubble.setText("-52.576"); |
| 64 | + ASSERT_EQ(bubble.text(), "-52.58"); |
| 65 | + |
| 66 | + bubble.setText("3.5"); |
| 67 | + ASSERT_EQ(bubble.text(), "3.5"); |
| 68 | + |
| 69 | + bubble.setText("0.015"); |
| 70 | + ASSERT_EQ(bubble.text(), "0.02"); |
| 71 | + |
| 72 | + bubble.setText("-0.015"); |
| 73 | + ASSERT_EQ(bubble.text(), "-0.02"); |
| 74 | + |
| 75 | + bubble.setText("0.005"); |
| 76 | + ASSERT_EQ(bubble.text(), "0.005"); |
| 77 | + |
| 78 | + bubble.setText("-0.005"); |
| 79 | + ASSERT_EQ(bubble.text(), "-0.005"); |
| 80 | +} |
0 commit comments