Skip to content

Commit

Permalink
test: JavaScript unit tests
Browse files Browse the repository at this point in the history
Implements unit tests for the Javascript bindings based on duktape. All errors found are fixed in the same commit.

This commit also includes the complete implementation for classes that were only placeholders, including conversions to dom::Value and related wrapper classes for objects, arrays, and functions.

The changes are only related to bindings from Javascript to C++. Bindings from C++ to Javascript will be addressed in a later commit.
  • Loading branch information
alandefreitas committed Oct 25, 2023
1 parent 60d79ff commit d5b7b3d
Show file tree
Hide file tree
Showing 8 changed files with 2,031 additions and 111 deletions.
8 changes: 8 additions & 0 deletions include/mrdox/Dom/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ class MRDOX_DECL
virtual void set(String key, Value value) = 0;

/** Invoke the visitor for each key/value pair.
The visitor function must return `true` to
continue iteration, or `false` to stop.
The visit function returns `true` if the
visitor returned `true` for all elements,
otherwise `false`.
*/
virtual bool visit(std::function<bool(String, Value)>) const = 0;

Expand Down
35 changes: 24 additions & 11 deletions include/mrdox/Dom/Value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,32 @@ class MRDOX_DECL
*/
bool isTruthy() const noexcept;

/** Return the underlying boolean value.
@note Behaviour is undefined if `!isBoolean()`
*/
bool getBool() const noexcept
{
MRDOX_ASSERT(isBoolean());
return b_ != 0;
}

/** Return the underlying integer value.
@note Behaviour is undefined if `!isInteger()`
*/
std::int64_t
getInteger() const noexcept
{
MRDOX_ASSERT(isInteger());
return i_;
}

/** Return the underlying string value.
@note Behaviour is undefined if `!isString()`
*/
String const&
getString() const noexcept
{
Expand Down Expand Up @@ -333,6 +346,16 @@ class MRDOX_DECL
bool
exists(std::string_view key) const;

/** Return if an Array or Object is empty.
*/
bool
empty() const;

/** Return if an Array or Object is empty.
*/
std::size_t
size() const;

/** Invoke the function.
If the Value is not an object, or the key
Expand All @@ -349,16 +372,6 @@ class MRDOX_DECL
return getFunction()(std::forward<Args>(args)...);
}

/** Return if an Array or Object is empty.
*/
bool
empty() const;

/** Return if an Array or Object is empty.
*/
std::size_t
size() const;

/// @copydoc isTruthy()
explicit
operator bool() const noexcept
Expand Down Expand Up @@ -506,7 +519,7 @@ class MRDOX_DECL
return lhs && Value(rhs);
}

/** Return a diagnostic string.
/** Return value as a string.
*/
friend
std::string
Expand Down
Loading

0 comments on commit d5b7b3d

Please sign in to comment.