-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for parsing fixed point decimal strings
- Loading branch information
Showing
6 changed files
with
240 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ set(tests | |
missiles_test | ||
pack_test | ||
path_test | ||
parse_int_test | ||
player_test | ||
quests_test | ||
random_test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
String Byte Int Float | ||
Sample 145 70322 6.34 | ||
String Byte Int Float FloatOverflow | ||
Sample 145 70322 6.34 3.999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "utils/parse_int.hpp" | ||
|
||
namespace devilution { | ||
TEST(ParseIntTest, ParseInt) | ||
{ | ||
ParseIntResult<int> result = ParseInt<int>(""); | ||
ASSERT_FALSE(result.has_value()); | ||
EXPECT_EQ(result.error(), ParseIntError::ParseError); | ||
|
||
result = ParseInt<int>("abcd"); | ||
ASSERT_FALSE(result.has_value()); | ||
EXPECT_EQ(result.error(), ParseIntError::ParseError); | ||
|
||
result = ParseInt<int>("12"); | ||
ASSERT_TRUE(result.has_value()); | ||
EXPECT_EQ(result.value(), 12); | ||
|
||
result = ParseInt<int>(("99999999"), -5, 100); | ||
ASSERT_FALSE(result.has_value()); | ||
EXPECT_EQ(result.error(), ParseIntError::OutOfRange); | ||
|
||
ParseIntResult<int8_t> shortResult = ParseInt<int8_t>(("99999999")); | ||
ASSERT_FALSE(shortResult.has_value()); | ||
EXPECT_EQ(shortResult.error(), ParseIntError::OutOfRange); | ||
} | ||
|
||
TEST(ParseIntTest, ParseFixed6Fraction) | ||
{ | ||
EXPECT_EQ(ParseFixed6Fraction(""), 0); | ||
EXPECT_EQ(ParseFixed6Fraction("0"), 0); | ||
EXPECT_EQ(ParseFixed6Fraction("00781249"), 0); | ||
EXPECT_EQ(ParseFixed6Fraction("0078125"), 1); | ||
EXPECT_EQ(ParseFixed6Fraction("015625"), 1); | ||
EXPECT_EQ(ParseFixed6Fraction("03125"), 2); | ||
EXPECT_EQ(ParseFixed6Fraction("046875"), 3); | ||
EXPECT_EQ(ParseFixed6Fraction("0625"), 4); | ||
EXPECT_EQ(ParseFixed6Fraction("078125"), 5); | ||
EXPECT_EQ(ParseFixed6Fraction("09375"), 6); | ||
EXPECT_EQ(ParseFixed6Fraction("109375"), 7); | ||
EXPECT_EQ(ParseFixed6Fraction("125"), 8); | ||
EXPECT_EQ(ParseFixed6Fraction("140625"), 9); | ||
EXPECT_EQ(ParseFixed6Fraction("15625"), 10); | ||
EXPECT_EQ(ParseFixed6Fraction("171875"), 11); | ||
EXPECT_EQ(ParseFixed6Fraction("1875"), 12); | ||
EXPECT_EQ(ParseFixed6Fraction("203125"), 13); | ||
EXPECT_EQ(ParseFixed6Fraction("21875"), 14); | ||
EXPECT_EQ(ParseFixed6Fraction("234375"), 15); | ||
EXPECT_EQ(ParseFixed6Fraction("25"), 16); | ||
EXPECT_EQ(ParseFixed6Fraction("265625"), 17); | ||
EXPECT_EQ(ParseFixed6Fraction("28125"), 18); | ||
EXPECT_EQ(ParseFixed6Fraction("296875"), 19); | ||
EXPECT_EQ(ParseFixed6Fraction("3125"), 20); | ||
EXPECT_EQ(ParseFixed6Fraction("328125"), 21); | ||
EXPECT_EQ(ParseFixed6Fraction("34375"), 22); | ||
EXPECT_EQ(ParseFixed6Fraction("359375"), 23); | ||
EXPECT_EQ(ParseFixed6Fraction("375"), 24); | ||
EXPECT_EQ(ParseFixed6Fraction("390625"), 25); | ||
EXPECT_EQ(ParseFixed6Fraction("40625"), 26); | ||
EXPECT_EQ(ParseFixed6Fraction("421875"), 27); | ||
EXPECT_EQ(ParseFixed6Fraction("4375"), 28); | ||
EXPECT_EQ(ParseFixed6Fraction("453125"), 29); | ||
EXPECT_EQ(ParseFixed6Fraction("46875"), 30); | ||
EXPECT_EQ(ParseFixed6Fraction("484375"), 31); | ||
EXPECT_EQ(ParseFixed6Fraction("5"), 32); | ||
EXPECT_EQ(ParseFixed6Fraction("515625"), 33); | ||
EXPECT_EQ(ParseFixed6Fraction("53125"), 34); | ||
EXPECT_EQ(ParseFixed6Fraction("546875"), 35); | ||
EXPECT_EQ(ParseFixed6Fraction("5625"), 36); | ||
EXPECT_EQ(ParseFixed6Fraction("578125"), 37); | ||
EXPECT_EQ(ParseFixed6Fraction("59375"), 38); | ||
EXPECT_EQ(ParseFixed6Fraction("609375"), 39); | ||
EXPECT_EQ(ParseFixed6Fraction("625"), 40); | ||
EXPECT_EQ(ParseFixed6Fraction("640625"), 41); | ||
EXPECT_EQ(ParseFixed6Fraction("65625"), 42); | ||
EXPECT_EQ(ParseFixed6Fraction("671875"), 43); | ||
EXPECT_EQ(ParseFixed6Fraction("6875"), 44); | ||
EXPECT_EQ(ParseFixed6Fraction("703125"), 45); | ||
EXPECT_EQ(ParseFixed6Fraction("71875"), 46); | ||
EXPECT_EQ(ParseFixed6Fraction("734375"), 47); | ||
EXPECT_EQ(ParseFixed6Fraction("75"), 48); | ||
EXPECT_EQ(ParseFixed6Fraction("765625"), 49); | ||
EXPECT_EQ(ParseFixed6Fraction("78125"), 50); | ||
EXPECT_EQ(ParseFixed6Fraction("796875"), 51); | ||
EXPECT_EQ(ParseFixed6Fraction("8125"), 52); | ||
EXPECT_EQ(ParseFixed6Fraction("828125"), 53); | ||
EXPECT_EQ(ParseFixed6Fraction("84375"), 54); | ||
EXPECT_EQ(ParseFixed6Fraction("859375"), 55); | ||
EXPECT_EQ(ParseFixed6Fraction("875"), 56); | ||
EXPECT_EQ(ParseFixed6Fraction("890625"), 57); | ||
EXPECT_EQ(ParseFixed6Fraction("90625"), 58); | ||
EXPECT_EQ(ParseFixed6Fraction("921875"), 59); | ||
EXPECT_EQ(ParseFixed6Fraction("9375"), 60); | ||
EXPECT_EQ(ParseFixed6Fraction("953125"), 61); | ||
EXPECT_EQ(ParseFixed6Fraction("96875"), 62); | ||
EXPECT_EQ(ParseFixed6Fraction("984375"), 63); | ||
EXPECT_EQ(ParseFixed6Fraction("99218749"), 63); | ||
EXPECT_EQ(ParseFixed6Fraction("9921875"), 64); | ||
} | ||
} // namespace devilution |