Fix dict tests

This commit is contained in:
Konstantin Nazarov 2024-09-01 23:11:53 +01:00
parent 09693768f8
commit 6a5aad3ae9
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
4 changed files with 18 additions and 14 deletions

View file

@ -25,6 +25,7 @@ class Symbol;
class Syntax; class Syntax;
class Pair; class Pair;
class Array; class Array;
class Dict;
class ByteArray; class ByteArray;
class Writer; class Writer;
class Opcode; class Opcode;
@ -71,6 +72,9 @@ class Object {
virtual Result<short> cmp(const Array&) const { virtual Result<short> cmp(const Array&) const {
return cmp_tag(tag(), Tag::Array); return cmp_tag(tag(), Tag::Array);
} }
virtual Result<short> cmp(const Dict&) const {
return cmp_tag(tag(), Tag::Dict);
}
virtual Result<short> cmp(const ByteArray&) const { virtual Result<short> cmp(const ByteArray&) const {
return cmp_tag(tag(), Tag::ByteArray); return cmp_tag(tag(), Tag::ByteArray);
} }

View file

@ -517,22 +517,22 @@ bool Reader::forward_exponent() {
return forward_decimal_number(); return forward_decimal_number();
} }
Result<Value> read_one(const Value& value) { Result<Value> read_one(const Value& value, bool as_code) {
if (!value.is<String>()) return ERROR(TypeMismatch); if (!value.is<String>()) return ERROR(TypeMismatch);
auto r = Reader(*value.to<String>()); auto r = Reader(*value.to<String>(), as_code);
return r.read_one(); return r.read_one();
} }
Result<Value> read_one(const String& value) { Result<Value> read_one(const String& value, bool as_code) {
auto r = Reader(value); auto r = Reader(value, as_code);
return r.read_one(); return r.read_one();
} }
Result<Value> read_one(const char* value) { Result<Value> read_one(const char* value, bool as_code) {
auto s = TRY(String::create(value)); auto s = TRY(String::create(value));
auto r = Reader(s); auto r = Reader(s, as_code);
return r.read_one(); return r.read_one();
} }
Result<Value> read_multiple(const String& value) { Result<Value> read_multiple(const String& value, bool as_code) {
auto r = Reader(value); auto r = Reader(value, as_code);
return r.read_multiple(); return r.read_multiple();
} }

View file

@ -49,8 +49,8 @@ class Reader {
SourcePosition position_{1, 1, 0}; SourcePosition position_{1, 1, 0};
}; };
Result<Value> read_one(const Value& value); Result<Value> read_one(const Value& value, bool as_code = true);
Result<Value> read_one(const String& value); Result<Value> read_one(const String& value, bool as_code = true);
Result<Value> read_one(const char* value); Result<Value> read_one(const char* value, bool as_code = true);
Result<Value> read_multiple(const String& value); Result<Value> read_multiple(const String& value, bool as_code = true);

View file

@ -26,11 +26,11 @@ TEST_CASE(dict_insert) {
} }
TEST_CASE(dict_read) { TEST_CASE(dict_read) {
auto v = DIEX(read_one("{}")); auto v = DIEX(read_one("{}", false));
auto s = DIEX(write_one(v)); auto s = DIEX(write_one(v));
ASSERT_EQUALS(s, "{}"); ASSERT_EQUALS(s, "{}");
v = DIEX(read_one("{1 2 3 4}")); v = DIEX(read_one("{1 2 3 4}", false));
s = DIEX(write_one(v)); s = DIEX(write_one(v));
ASSERT_EQUALS(s, "{1 2 3 4}"); ASSERT_EQUALS(s, "{1 2 3 4}");