Skip to content

Commit

Permalink
Add the "Latex" output.
Browse files Browse the repository at this point in the history
This addressed issue:
#6
  • Loading branch information
ArthurSonzogni committed Jun 20, 2020
1 parent d38777f commit 2f11c19
Show file tree
Hide file tree
Showing 34 changed files with 498 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/.clang-format → .clang-format
@@ -1,3 +1,3 @@
BasedOnStyle: Chromium
Standard: Cpp11
IndentPPDirectives: BeforeHash
PointerAlignment: Left
13 changes: 9 additions & 4 deletions src/http/tools.json
Expand Up @@ -4,10 +4,15 @@
"description": "Mathematical expression",
"options": [
{
"type":"checkbox",
"default":false,
"label":"ASCII-only",
"name":"ascii_only"
"type":"combobox",
"default":true,
"label":"Style",
"name":"style",
"values": [
"Unicode",
"ASCII",
"Latex"
]
},
{
"type":"checkbox",
Expand Down
30 changes: 27 additions & 3 deletions src/input_output_test.cpp
Expand Up @@ -19,21 +19,45 @@ std::string ReadFile(std::filesystem::path path) {
return ss.str();
}

void ParseDirectoryName(std::string name,
std::string* translator_name,
std::string* options) {
std::vector<std::string> parts;
int left = 0;
int right = 0;
while (right < name.size()) {
if (name[right] == '_' || name[right] == '=') {
parts.push_back(name.substr(left, right - left));
left = right + 1;
}
++right;
}
parts.push_back(name.substr(left, right - left));

*translator_name = parts[0];
for(int i = 1; i<parts.size(); ++i) {
*options += parts[i] + "\n";
}
}

int main(int, const char**) {
auto translator_list = TranslatorList();
int result = 0;

std::string path = test_directory;
std::cout << "test_directory = " << test_directory << std::endl;
for (auto& dir : std::filesystem::directory_iterator(path)) {
std::string type = dir.path().filename();
std::string translator_name;
std::string options;
ParseDirectoryName(dir.path().filename(), &translator_name, &options);

for (auto& test : std::filesystem::directory_iterator(dir.path())) {
auto translator = translator_list[type]();
auto translator = translator_list[translator_name]();

std::string input = ReadFile(test.path() / "input");
std::string output = ReadFile(test.path() / "output");

std::string output_computed = translator->Translate(input, "");
std::string output_computed = translator->Translate(input, options);

if (output_computed == output) {
std::cout << " [PASS] " << test << std::endl;
Expand Down
5 changes: 3 additions & 2 deletions src/main.cpp
Expand Up @@ -69,8 +69,9 @@ TRANSLATOR-OPTIONS:
* stdin : diagon Math
Providing options:
diagon Math -ascii-only=false -- 1 + 1/2
diagon Math -ascii-only=true -- 1 + 1/2
diagon Math -style=Unicode -- 1 + 1/2
diagon Math -style=Ascii -- 1 + 1/2
diagon Math -style=Latex -- 1 + 1/2
WEBSITE:
This tool can also be used as a WebAssembly application on the website:
Expand Down

0 comments on commit 2f11c19

Please sign in to comment.