summaryrefslogtreecommitdiff
path: root/Tests/LibMarkdown/TestCommonmark.cpp
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-03-10 13:45:14 +0000
committerTim Flynn <trflynn89@pm.me>2022-03-10 12:04:22 -0500
commit2b2ddee77c99e23a5ed607a76901331bb1856437 (patch)
tree3e641047f9409d434196e61d31b6fccf59a02411 /Tests/LibMarkdown/TestCommonmark.cpp
parent7ff99c397219abe2354971c847efe7052b0558ca (diff)
downloadserenity-2b2ddee77c99e23a5ed607a76901331bb1856437.zip
Tests: Port TestCommonmark to Core::Stream
This passes the same number of tests that it did before this change: > Out of 652 tests, 273 passed and 379 failed.
Diffstat (limited to 'Tests/LibMarkdown/TestCommonmark.cpp')
-rw-r--r--Tests/LibMarkdown/TestCommonmark.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/Tests/LibMarkdown/TestCommonmark.cpp b/Tests/LibMarkdown/TestCommonmark.cpp
index 4f1c284cf6..f60cc9e7db 100644
--- a/Tests/LibMarkdown/TestCommonmark.cpp
+++ b/Tests/LibMarkdown/TestCommonmark.cpp
@@ -8,20 +8,23 @@
#include <AK/JsonObject.h>
#include <AK/JsonParser.h>
#include <AK/String.h>
-#include <LibCore/File.h>
+#include <LibCore/Stream.h>
#include <LibMarkdown/Document.h>
#include <LibTest/TestCase.h>
#include <LibTest/TestSuite.h>
TEST_SETUP
{
- auto file = Core::File::construct("/home/anon/commonmark.spec.json");
- if (!file->open(Core::OpenMode::ReadOnly)) {
- file = Core::File::construct("./commonmark.spec.json");
- VERIFY(file->open(Core::OpenMode::ReadOnly));
- }
-
- String test_data(file->read_all(), AK::ShouldChomp::NoChomp);
+ auto file_or_error = Core::Stream::File::open("/home/anon/commonmark.spec.json", Core::Stream::OpenMode::Read);
+ if (file_or_error.is_error())
+ file_or_error = Core::Stream::File::open("./commonmark.spec.json", Core::Stream::OpenMode::Read);
+ VERIFY(!file_or_error.is_error());
+ auto file = file_or_error.release_value();
+ auto file_size = MUST(file->size());
+ auto content = MUST(ByteBuffer::create_uninitialized(file_size));
+ if (!file->read_or_error(content.bytes()))
+ VERIFY_NOT_REACHED();
+ String test_data { content.bytes() };
auto tests = JsonParser(test_data).parse().value().as_array();
for (size_t i = 0; i < tests.size(); ++i) {