Differential D15385 Diff 53339 source/blender/io/wavefront_obj/tests/obj_import_string_utils_tests.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/wavefront_obj/tests/obj_import_string_utils_tests.cc
| Show All 23 Lines | |||||
| static StringRef drop_whitespace(StringRef s) | static StringRef drop_whitespace(StringRef s) | ||||
| { | { | ||||
| return StringRef(drop_whitespace(s.begin(), s.end()), s.end()); | return StringRef(drop_whitespace(s.begin(), s.end()), s.end()); | ||||
| } | } | ||||
| static StringRef parse_int(StringRef s, int fallback, int &dst, bool skip_space = true) | static StringRef parse_int(StringRef s, int fallback, int &dst, bool skip_space = true) | ||||
| { | { | ||||
| return StringRef(parse_int(s.begin(), s.end(), fallback, dst, skip_space), s.end()); | return StringRef(parse_int(s.begin(), s.end(), fallback, dst, skip_space), s.end()); | ||||
| } | } | ||||
| static StringRef parse_float(StringRef s, float fallback, float &dst, bool skip_space = true) | static StringRef parse_float(StringRef s, | ||||
| float fallback, | |||||
| float &dst, | |||||
| bool skip_space = true, | |||||
| bool require_trailing_space = false) | |||||
| { | { | ||||
| return StringRef(parse_float(s.begin(), s.end(), fallback, dst, skip_space), s.end()); | return StringRef( | ||||
| parse_float(s.begin(), s.end(), fallback, dst, skip_space, require_trailing_space), s.end()); | |||||
| } | } | ||||
| TEST(obj_import_string_utils, drop_whitespace) | TEST(obj_import_string_utils, drop_whitespace) | ||||
| { | { | ||||
| /* Empty */ | /* Empty */ | ||||
| EXPECT_STRREF_EQ("", drop_whitespace("")); | EXPECT_STRREF_EQ("", drop_whitespace("")); | ||||
| /* Only whitespace */ | /* Only whitespace */ | ||||
| EXPECT_STRREF_EQ("", drop_whitespace(" ")); | EXPECT_STRREF_EQ("", drop_whitespace(" ")); | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | TEST(obj_import_string_utils, parse_float_invalid) | ||||
| /* Out of float range. Current float parser (fast_float) | /* Out of float range. Current float parser (fast_float) | ||||
| * clamps out of range numbers to +/- infinity, so this | * clamps out of range numbers to +/- infinity, so this | ||||
| * one gets a +inf instead of fallback -3.0. */ | * one gets a +inf instead of fallback -3.0. */ | ||||
| EXPECT_STRREF_EQ(" a", parse_float("9.0e500 a", -3.0f, val)); | EXPECT_STRREF_EQ(" a", parse_float("9.0e500 a", -3.0f, val)); | ||||
| EXPECT_EQ(val, std::numeric_limits<float>::infinity()); | EXPECT_EQ(val, std::numeric_limits<float>::infinity()); | ||||
| /* Has leading white-space when we don't expect it */ | /* Has leading white-space when we don't expect it */ | ||||
| EXPECT_STRREF_EQ(" 1", parse_float(" 1", -4.0f, val, false)); | EXPECT_STRREF_EQ(" 1", parse_float(" 1", -4.0f, val, false)); | ||||
| EXPECT_EQ(val, -4.0f); | EXPECT_EQ(val, -4.0f); | ||||
| /* Has trailing non-number characters when we don't want them */ | |||||
| EXPECT_STRREF_EQ("123.5.png", parse_float(" 123.5.png", -5.0f, val, true, true)); | |||||
| EXPECT_EQ(val, -5.0f); | |||||
| } | } | ||||
| } // namespace blender::io::obj | } // namespace blender::io::obj | ||||