Skip to content

Commit d5b7b3d

Browse files
committed
test: JavaScript unit tests
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.
1 parent 60d79ff commit d5b7b3d

File tree

8 files changed

+2031
-111
lines changed

8 files changed

+2031
-111
lines changed

include/mrdox/Dom/Object.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,14 @@ class MRDOX_DECL
357357
virtual void set(String key, Value value) = 0;
358358

359359
/** Invoke the visitor for each key/value pair.
360+
361+
The visitor function must return `true` to
362+
continue iteration, or `false` to stop.
363+
364+
The visit function returns `true` if the
365+
visitor returned `true` for all elements,
366+
otherwise `false`.
367+
360368
*/
361369
virtual bool visit(std::function<bool(String, Value)>) const = 0;
362370

include/mrdox/Dom/Value.hpp

+24-11
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,32 @@ class MRDOX_DECL
238238
*/
239239
bool isTruthy() const noexcept;
240240

241+
/** Return the underlying boolean value.
242+
243+
@note Behaviour is undefined if `!isBoolean()`
244+
245+
*/
241246
bool getBool() const noexcept
242247
{
243248
MRDOX_ASSERT(isBoolean());
244249
return b_ != 0;
245250
}
246251

252+
/** Return the underlying integer value.
253+
254+
@note Behaviour is undefined if `!isInteger()`
255+
*/
247256
std::int64_t
248257
getInteger() const noexcept
249258
{
250259
MRDOX_ASSERT(isInteger());
251260
return i_;
252261
}
253262

263+
/** Return the underlying string value.
264+
265+
@note Behaviour is undefined if `!isString()`
266+
*/
254267
String const&
255268
getString() const noexcept
256269
{
@@ -333,6 +346,16 @@ class MRDOX_DECL
333346
bool
334347
exists(std::string_view key) const;
335348

349+
/** Return if an Array or Object is empty.
350+
*/
351+
bool
352+
empty() const;
353+
354+
/** Return if an Array or Object is empty.
355+
*/
356+
std::size_t
357+
size() const;
358+
336359
/** Invoke the function.
337360
338361
If the Value is not an object, or the key
@@ -349,16 +372,6 @@ class MRDOX_DECL
349372
return getFunction()(std::forward<Args>(args)...);
350373
}
351374

352-
/** Return if an Array or Object is empty.
353-
*/
354-
bool
355-
empty() const;
356-
357-
/** Return if an Array or Object is empty.
358-
*/
359-
std::size_t
360-
size() const;
361-
362375
/// @copydoc isTruthy()
363376
explicit
364377
operator bool() const noexcept
@@ -506,7 +519,7 @@ class MRDOX_DECL
506519
return lhs && Value(rhs);
507520
}
508521

509-
/** Return a diagnostic string.
522+
/** Return value as a string.
510523
*/
511524
friend
512525
std::string

0 commit comments

Comments
 (0)