From 12eaa3d71c179f42d55539f8361eed710f42ee94 Mon Sep 17 00:00:00 2001 From: Tristan Isham Date: Sat, 25 May 2024 23:57:06 -0400 Subject: [PATCH] added markdown test (to become Rocket) --- include/lib.hpp | 2 ++ lang/encoding.fan | 42 ++++++++++++++++++++--------------------- src/main.cpp | 3 +-- src/vm/config.cpp | 10 ++++------ src/vm/std/encoding.cpp | 5 ++++- tests/std/markdown.fan | 16 ++++++++++++++++ 6 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 tests/std/markdown.fan diff --git a/include/lib.hpp b/include/lib.hpp index 3a28c8ca..c7140026 100644 --- a/include/lib.hpp +++ b/include/lib.hpp @@ -243,4 +243,6 @@ namespace encoding { void md_to_html(WrenVM* vm); } + + } // namespace lib diff --git a/lang/encoding.fan b/lang/encoding.fan index 94423c51..de0aa40a 100644 --- a/lang/encoding.fan +++ b/lang/encoding.fan @@ -20,24 +20,24 @@ class Markdown { foreign static toHTML(buff) } -foreign class JSON { - construct new() {} - - static fromMap(map) { - if (!(map is Map)) { - Fiber.abort("Paramater is not of type Map") - } - - var json = JSON.new() - - for (entry of map) { - json.set(entry.key, entry.value) - } - } - - foreign set(key, val); - - [set]=(value) { - this.set(key, value) - } -} \ No newline at end of file +// foreign class JSON { +// construct new() {} +// +// static fromMap(map) { +// if (!(map is Map)) { +// Fiber.abort("Parameter is not of type Map") +// } +// +// var json = JSON.new() +// +// for (entry of map) { +// json.set(entry.key, entry.value) +// } +// } +// +// foreign set(key, val); +// +// [set]=(value) { +// this.set(key, value) +// } +// } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 2b6cf632..903079c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,13 +3,12 @@ #include #include #include -#include #include #include #include /** - * Fan is a language runtime focused on making software devlopment easy, + * Fan is a language runtime focused on making software development easy, * performant, and fun. The Fan command line tool features a simple REPL and * the ability to execute a script, typically the last argument value on the * command line if no other commands or flags are passed. diff --git a/src/vm/config.cpp b/src/vm/config.cpp index 969ef417..31f6feae 100644 --- a/src/vm/config.cpp +++ b/src/vm/config.cpp @@ -94,10 +94,8 @@ std::string lib::wren_type_to_string(const WrenType& type) { return "null"; case WREN_TYPE_STRING: return "String"; - case WREN_TYPE_UNKNOWN: - return "unknown"; default: - return "invalid"; + return "unknown"; } } @@ -439,12 +437,12 @@ WrenInterpretResult vm::Runtime::execute(const std::string& code, const std::str } void vm::Runtime::repl() const { - std::string line; + std::string buffer; std::cout << rang::style::bold << "Fan " << cli::VERSION << " REPL" << std::endl; std::cout << rang::fg::blue << "%> " << rang::fg::reset; while (true) { - if (!std::getline(std::cin, line)) { + if (!std::getline(std::cin, buffer)) { if (std::cin.eof()) { // Handle EOF (Ctrl+D) here std::cin.clear(); @@ -455,7 +453,7 @@ void vm::Runtime::repl() const { break; } } - if (auto stat = this->execute(line); stat != WREN_RESULT_SUCCESS) { + if (auto stat = this->execute(buffer); stat != WREN_RESULT_SUCCESS) { // std::cerr << "Error: " + stat << std::endl; } std::cout << rang::fg::blue << "%> " << rang::fg::reset; diff --git a/src/vm/std/encoding.cpp b/src/vm/std/encoding.cpp index b9b3169f..544c2a72 100644 --- a/src/vm/std/encoding.cpp +++ b/src/vm/std/encoding.cpp @@ -69,7 +69,10 @@ void lib::encoding::md_to_html(WrenVM* vm) { auto const input = wrenGetSlotString(vm, 1); auto out = cmark_markdown_to_html(input, std::strlen(input), 0); - wrenSetSlotString(vm, 0, out); + std::string buffer{out}; + wrenSetSlotString(vm, 0, buffer.c_str()); + + // Free the memory returned by CMark if (out != nullptr) { std::free(out); out = nullptr; diff --git a/tests/std/markdown.fan b/tests/std/markdown.fan new file mode 100644 index 00000000..b5da350e --- /dev/null +++ b/tests/std/markdown.fan @@ -0,0 +1,16 @@ +import "std/encoding" for Markdown +import "std/fs" for Fs, Path + +var files = Fs.listAllRecursive(Fs.cwd()) + +// List of markdown files in the directory +var mdFiles = [] + +for (i in files) { + if (Path.ext(i) == "md") { + System.print(i) + mdFiles.add(i) + } +} + +System.print(mdFiles.count)