Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/internal/reader_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@ Value jsonToValue(nlohmann::json value)
{
if (value.is_string())
return value.get<std::string>();
else if (value.is_number()) {
// Set locale to C to avoid conversion issues
std::string oldLocale = std::setlocale(LC_NUMERIC, nullptr);
std::setlocale(LC_NUMERIC, "C");

double converted = std::stod(value.dump());

// Restore old locale
std::setlocale(LC_NUMERIC, oldLocale.c_str());

return converted;
} else if (value.is_boolean())
else if (value.is_boolean())
return value.get<bool>();
else
return value.dump();
Expand Down
25 changes: 22 additions & 3 deletions test/load_project/load_project_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ TEST(LoadProjectTest, LoadTestProject)

// Stage: lists
ASSERT_LIST(stage, "list1");
ASSERT_EQ(GET_LIST(stage, "list1")->toString(), "3 1 4 8 7 6 7 7 2 4");
ASSERT_EQ(GET_LIST(stage, "list1")->size(), 10);
ASSERT_EQ(GET_LIST(stage, "list1")->toString(), "3148767724");

// Sprite1
ASSERT_NE(engine->findTarget("Sprite1"), -1);
Expand Down Expand Up @@ -282,7 +283,8 @@ TEST(LoadProjectTest, LoadTestProject)

// Sprite1: lists
ASSERT_LIST(sprite1, "list2");
ASSERT_EQ(GET_LIST(sprite1, "list2")->toString(), "9 6 3 8 0 4 4 2 9 7");
ASSERT_EQ(GET_LIST(sprite1, "list2")->size(), 10);
ASSERT_EQ(GET_LIST(sprite1, "list2")->toString(), "9638044297");

// Sprite1: blocks
ASSERT_EQ(sprite1->greenFlagBlocks().size(), 1);
Expand Down Expand Up @@ -445,7 +447,8 @@ TEST(LoadProjectTest, LoadTestProject)

// Balloon1: lists
ASSERT_LIST(sprite2, "list2");
ASSERT_EQ(GET_LIST(sprite2, "list2")->toString(), "0 4 3 4 1 5 6 9 4 8");
ASSERT_EQ(GET_LIST(sprite2, "list2")->size(), 10);
ASSERT_EQ(GET_LIST(sprite2, "list2")->toString(), "0434156948");

// Monitors
const auto &monitors = engine->monitors();
Expand Down Expand Up @@ -740,3 +743,19 @@ TEST(LoadProjectTest, LoadDoubleValue)

std::setlocale(LC_NUMERIC, oldLocale.c_str());
}

TEST(LoadProjectTest, LoadScientificNotationNumber)
{
// Regtest for #488
std::string name = "regtest_projects/488_scientific_notation_conversion.sb3";
Project p(name);
ASSERT_TRUE(p.load());

auto stage = p.engine()->stage();
ASSERT_TRUE(stage);
ASSERT_VAR(stage, "test1");
ASSERT_EQ(GET_VAR(stage, "test1")->value().toDouble(), 5000);

ASSERT_VAR(stage, "test2");
ASSERT_EQ(GET_VAR(stage, "test2")->value().toDouble(), 0);
}
Binary file not shown.