Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement conversion of witness object into DataTree #5

Open
sylvainhalle opened this issue Jan 25, 2021 · 0 comments
Open

Implement conversion of witness object into DataTree #5

sylvainhalle opened this issue Jan 25, 2021 · 0 comments
Assignees
Labels
todo Thing to do

Comments

@sylvainhalle
Copy link
Contributor

A witness is an array of DesignatedObject that explains the violation of a condition. Each DesignatedObject contains a Designator, which points to a part of an object, and an Object it refers to.

In the context of DOM nodes, the designated object can have two forms.

First form

The designator is a CompoundDesignator, which is a composition of elementary ("atomic") designators. The composition ends with a Path, followed by a ConstantDesignator. The object is an HTMLBodyElement. This means that this piece of the witness points to an element of the DOM tree, indicated by the XPath expression contained in the Path instance.

For example, the following picture shows the structure of such a designated object (dob1) in one of the unit tests.

vs_dob

Second form

The second form is any designated object that does not correspond to the previous structure (it should normally end with a ConstantDesignator). Typically, it will point to objects that are user-provided constants, such as numbers or strings, that cannot be linked to the DOM tree.

To do

As a first step before transforming an arbitrary and-or tree into a DataTree (see #2), we will convert a witness into a DataTree. The process is as follows:

  1. Each element of the witness becomes a leaf of the data tree.
  • If the designated object is of the first form, the subject attribute contains the XPath of the Path designator. The part attribute contains an array with the string representation of all the designators that come before the path.
  • If the designated object is of the second form, the subject attribute contains the object pointed by the DesignatedObject (obtained through the getObject()) method. The part attribute contains an array with the string representation of all the designators (except the last ConstantDesignator).
  1. These leaves are topped by an "and" node, as per the structure described in the Google Drive document.

This should be implemented in index.mjs through a function called getTreeFromWitness(w), which takes a witness and returns the corresponding DataTree. Unit tests should be added to a new file called test/index.test.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
todo Thing to do
Projects
None yet
Development

No branches or pull requests

2 participants