Skip to content

Commit

Permalink
Do another dependency upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
RauliL committed Feb 9, 2024
1 parent bc4e8d1 commit f05e92b
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 190 deletions.
14 changes: 7 additions & 7 deletions include/plorth/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace plorth::parser
{
return parse_result::error(token_result.error());
}
tokens.push_back(token_result.value());
tokens.push_back(*token_result);
}

return parse_result::ok(tokens);
Expand Down Expand Up @@ -193,7 +193,7 @@ namespace plorth::parser

if (value_result)
{
elements.push_back(value_result.value());
elements.push_back(*value_result);
if (utils::skip_whitespace(current, end, position)
|| (!utils::peek(current, end, U',')
&& !utils::peek(current, end, U']')))
Expand Down Expand Up @@ -294,8 +294,8 @@ namespace plorth::parser
}

properties.push_back(std::make_pair(
key_result.value()->value(),
value_result.value()
(*key_result)->value(),
*value_result
));

if (utils::skip_whitespace(current, end, position)
Expand Down Expand Up @@ -368,7 +368,7 @@ namespace plorth::parser

if (child_result)
{
children.push_back(child_result.value());
children.push_back(*child_result);
} else {
return parse_quote_result::error(child_result.error());
}
Expand Down Expand Up @@ -570,7 +570,7 @@ namespace plorth::parser
{
return parse_string_result::error(escape_sequence_result.error());
}
buffer.append(1, escape_sequence_result.value());
buffer.append(1, *escape_sequence_result);
} else {
buffer.append(1, utils::advance(current, position));
}
Expand Down Expand Up @@ -684,7 +684,7 @@ namespace plorth::parser
return parse_token_result::ok(
std::make_shared<ast::word>(
symbol_or_word_position,
symbol_result.value()
*symbol_result
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
peelonet/peelo-result@v0.3.0
peelonet/peelo-result@v0.5.0
peelonet/peelo-unicode@v1.0.0
8 changes: 7 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ FOREACH(TEST_FILENAME ${TEST_SOURCES})
cxx_std_17
)

IF(NOT WIN32)
IF(MSVC)
TARGET_COMPILE_OPTIONS(
${TEST_NAME}
PRIVATE
/W4 /WX
)
ELSE()
TARGET_COMPILE_OPTIONS(
${TEST_NAME}
PRIVATE
Expand Down
55 changes: 32 additions & 23 deletions test/test_array.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <cassert>
#include <cstdlib>

#include <plorth/parser.hpp>

using plorth::parser::parse_array;

static auto parse(const std::u32string& source)
static auto
parse(const std::u32string& source)
{
auto begin = std::cbegin(source);
const auto end = std::cend(source);
Expand All @@ -14,81 +14,92 @@ static auto parse(const std::u32string& source)
return parse_array<std::u32string::const_iterator>(begin, end, position);
}

static void test_eof_before_the_array()
static void
test_eof_before_the_array()
{
const auto result = parse(U"");

assert(!result);
}

static void test_no_bracket_found()
static void
test_no_bracket_found()
{
const auto result = parse(U"invalid");

assert(!result);
}

static void test_unterminated_array()
static void
test_unterminated_array()
{
const auto result = parse(U"[");

assert(!result);
}

static void test_unterminated_array_after_element()
static void
test_unterminated_array_after_element()
{
const auto result = parse(U"[\"foo\"");

assert(!result);
}

static void test_unterminated_array_after_comma()
static void
test_unterminated_array_after_comma()
{
const auto result = parse(U"[\"foo\",");

assert(!result);
}

static void test_elements_without_comma()
static void
test_elements_without_comma()
{
const auto result = parse(U"[\"foo\" \"bar\"");

assert(!result);
}

static void test_empty_array()
static void
test_empty_array()
{
const auto result = parse(U"[]");

assert(!!result);
assert(result.value()->elements().size() == 0);
assert(result.has_value());
assert((*result)->elements().size() == 0);
}

static void test_array_with_one_element()
static void
test_array_with_one_element()
{
const auto result = parse(U"[\"foo\"]");

assert(!!result);
assert(result.value()->elements().size() == 1);
assert(result.has_value());
assert((*result)->elements().size() == 1);
}

static void test_array_with_multiple_elements()
static void
test_array_with_multiple_elements()
{
const auto result = parse(U"[\"foo\", \"bar\", \"baz\"]");

assert(!!result);
assert(result.value()->elements().size() == 3);
assert(result.has_value());
assert((*result)->elements().size() == 3);
}

static void test_array_with_multiple_elements_with_dangling_comma()
static void
test_array_with_multiple_elements_with_dangling_comma()
{
const auto result = parse(U"[\"foo\", \"bar\", \"baz\",]");

assert(!!result);
assert(result.value()->elements().size() == 3);
assert(result.has_value());
assert((*result)->elements().size() == 3);
}

int main(int argc, char** argv)
int
main()
{
test_eof_before_the_array();
test_no_bracket_found();
Expand All @@ -101,6 +112,4 @@ int main(int argc, char** argv)
test_array_with_one_element();
test_array_with_multiple_elements();
test_array_with_multiple_elements_with_dangling_comma();

return EXIT_SUCCESS;
}
36 changes: 22 additions & 14 deletions test/test_escape_sequence.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <cassert>
#include <cstdlib>

#include <plorth/parser.hpp>

using plorth::parser::parse_escape_sequence;

static auto parse(const std::u32string& source)
static auto
parse(const std::u32string& source)
{
auto begin = std::cbegin(source);
const auto end = std::cend(source);
Expand All @@ -18,29 +18,34 @@ static auto parse(const std::u32string& source)
);
}

static void test_eof()
static void
test_eof()
{
assert(!parse(U""));
}

static void test_no_backslash()
static void
test_no_backslash()
{
assert(!parse(U"foo"));
}

static void test_eof_after_backslash()
static void
test_eof_after_backslash()
{
assert(!parse(U"\\"));
}

static void test_unrecognized()
static void
test_unrecognized()
{
assert(!parse(U"\\a"));
assert(!parse(U"\\c"));
assert(!parse(U"\\#"));
}

static void test_recognized()
static void
test_recognized()
{
assert(parse(U"\\b").value() == 010);
assert(parse(U"\\t").value() == 011);
Expand All @@ -53,31 +58,36 @@ static void test_recognized()
assert(parse(U"\\/").value() == U'/');
}

static void test_hex_escape()
static void
test_hex_escape()
{
assert(parse(U"\\u00e4").value() == 0x00e4);
assert(parse(U"\\u0fe3").value() == 0x0fe3);
}

static void test_unterminated_hex_escape()
static void
test_unterminated_hex_escape()
{
assert(!parse(U"\\u"));
assert(!parse(U"\\u0"));
assert(!parse(U"\\u00"));
assert(!parse(U"\\u000"));
}

static void test_non_hex_hex_escape()
static void
test_non_hex_hex_escape()
{
assert(!parse(U"\\uxe43"));
}

static void test_invalid_hex_escape()
static void
test_invalid_hex_escape()
{
assert(!parse(U"\\ud805"));
}

int main(int argc, char** argv)
int
main()
{
test_eof();
test_no_backslash();
Expand All @@ -88,6 +98,4 @@ int main(int argc, char** argv)
test_unterminated_hex_escape();
test_non_hex_hex_escape();
test_invalid_hex_escape();

return EXIT_SUCCESS;
}
12 changes: 5 additions & 7 deletions test/test_hello_world.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <cassert>
#include <cstdlib>

#include <plorth/parser.hpp>

int main(int argc, char** argv)
int
main()
{
const std::u32string source(U"'Hello, World!' println");
auto begin = std::cbegin(source);
Expand All @@ -12,9 +12,7 @@ int main(int argc, char** argv)
const auto result = plorth::parser::parse(begin, end, position);

assert(!!result);
assert(result.value().size() == 2);
assert(result.value()[0]->type() == plorth::parser::ast::token::type::string);
assert(result.value()[1]->type() == plorth::parser::ast::token::type::symbol);

return EXIT_SUCCESS;
assert(result->size() == 2);
assert(result->at(0)->type() == plorth::parser::ast::token::type::string);
assert(result->at(1)->type() == plorth::parser::ast::token::type::symbol);
}
Loading

0 comments on commit f05e92b

Please sign in to comment.