-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
houmaster
committed
Sep 17, 2019
1 parent
3baeb72
commit fb0d66d
Showing
3 changed files
with
59 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
#include "test.h" | ||
#include "config/ParseConfig.h" | ||
#include "runtime/Stage.h" | ||
#include <set> | ||
#include <random> | ||
|
||
namespace { | ||
Stage create_stage(const char* string) { | ||
static auto parse_config = ParseConfig(); | ||
auto stream = std::stringstream(string); | ||
auto config = parse_config(stream); | ||
auto mappings = std::vector<Mapping>(); | ||
for (auto& command : config.commands) | ||
mappings.push_back({ | ||
std::move(command.input), | ||
std::move(command.default_mapping) | ||
}); | ||
return Stage(std::move(mappings), { }); | ||
} | ||
} // namespace | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
TEST_CASE("Fuzz #1", "[Fuzz]") { | ||
auto config = R"( | ||
Ext = IntlBackslash | ||
Ext >> | ||
Ext{W{K}} >> 1 | ||
Ext{W{L}} >> 2 | ||
Ext{W{J}} >> 3 | ||
Ext{W{Any}} >> | ||
)"; | ||
Stage stage = create_stage(config); | ||
|
||
auto keys = std::vector<KeyCode>(); | ||
for (auto k : { "IntlBackslash", "W", "K", "L", "J", "I" }) | ||
keys.push_back(parse_input(k).front().key); | ||
auto pressed = std::set<KeyCode>(); | ||
|
||
auto rand = std::mt19937(0); | ||
auto dist = std::uniform_int_distribution<size_t>(0, keys.size() - 1); | ||
for (auto i = 0; i < 1000; i++) { | ||
const auto key = keys[dist(rand)]; | ||
if (auto it = pressed.find(key); it != end(pressed)) { | ||
pressed.erase(it); | ||
stage.apply_input({ key, KeyState::Up }); | ||
} | ||
else { | ||
pressed.insert(key); | ||
stage.apply_input({ key, KeyState::Down }); | ||
} | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------------- |