Skip to content

Commit

Permalink
DomainCode more tests
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-src-client-domain-code.js,AUTO-COMMIT-src-components-tools-domain-code-explorer.html,AUTO-COMMIT-src-components-tools-domain-code-explorer.js,AUTO-COMMIT-test-domain-code-test.js,
  • Loading branch information
JensLincke committed Nov 7, 2023
1 parent 17ec4f2 commit 18c855d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/client/domain-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ export class DomainObject {
})

// modify only after traversion
// for(let domainObject of domainObjectByOldId.values()) {
// var newNode = newTreeSitterNodeByOldId.get(domainObject.id)
// if (newNode) {
// domainObject.treeSitter = newNode
// domainObjectById.set(domainObject.id, domainObject)
// } else {
// obsolteDomainObjects.push(domainObject)
// }
// }
for(let domainObject of domainObjectByOldId.values()) {
var newNode = newTreeSitterNodeByOldId.get(domainObject.id)
if (newNode) {
domainObject.treeSitter = newNode
domainObjectById.set(domainObject.id, domainObject)
} else {
obsolteDomainObjects.push(domainObject)
}
}


for(let action of scriptGenerator.actions) {
Expand All @@ -242,7 +242,9 @@ export class DomainObject {
if (!parentDomainObject) {
throw new Error(`parent domain object (${action.parent.type} ${action.parent.id}) not found`)
}
var newDomainObject = new TreeSitterDomainObject(action.node)

let treeSitter = newTreeSitterNodeById.get(action.node.id)
var newDomainObject = new TreeSitterDomainObject(treeSitter)
newDomainObject.children = []
newDomainObject.parent = parentDomainObject

Expand Down
7 changes: 7 additions & 0 deletions src/components/tools/domain-code-explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
background: steelblue;
}

#log {
white-space: pre;
overflow: auto;
max-height: 100px
}

</style>

<div id="content" class="pane layout-column">
Expand Down Expand Up @@ -92,5 +98,6 @@
<lively-editor class="pane" id="editor"></lively-editor>
</div>
</div>
<div id="log"></div>
</div>
</template>
10 changes: 8 additions & 2 deletions src/components/tools/domain-code-explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export default class DomainCodeExplorer extends Morph {
if (evt.button === 2) this.autoUpdate = !this.autoUpdate;
this.update();
}

log(s) {
let log = this.get("#log")
log.append(<div class="entry">{s}</div>)
log.scrollTop = log.scrollHeight;
}

/*MD ## Initialization MD*/

Expand Down Expand Up @@ -163,10 +169,10 @@ export default class DomainCodeExplorer extends Morph {
}

onDomainCodeChanged() {
this.log("domain code changed " + this.isUpdating + " length: " + this.editor.getText().length)

if (this.lastSource == this.editor.getText()) return

lively.notify("domain code changed " + this.isUpdating)
// this.domainObjectInspector.inspect(this.domainObjectInspector.targetObject)

// prevent cycle....
Expand Down Expand Up @@ -206,7 +212,7 @@ export default class DomainCodeExplorer extends Morph {

async update() {
this.lastSource = this.source
lively.notify("on source code changed")
this.log("source code changed, length: " + this.source.length + "")

try {
var node = await this.astInspector.treeSitterParse(this.source)
Expand Down
53 changes: 53 additions & 0 deletions test/domain-code-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,59 @@ a = 3`


})


it('reconciles change when inserting ', () => {
let sourceOriginal = `let a = 3`
let sourceNew = `let a = 3\nx`
let root = TreeSitterDomainObject.fromSource(sourceOriginal)


DomainObject.edit(root, sourceNew)


let exressionStatement = root.children[1]
expect(exressionStatement.type).equals("expression_statement")
expect(exressionStatement.treeSitter.startIndex).equals(10)


})

it('reconciles update the source code', () => {
let sourceOriginal = `let a = 3`
let sourceNew = `let a = 3\nx`
let root = TreeSitterDomainObject.fromSource(sourceOriginal)

expect(root.treeSitter.tree.rootNode.text, "sourceOriginal").equals(sourceOriginal)

DomainObject.edit(root, sourceNew)


expect(root.treeSitter.tree.rootNode.text, "sourceNew").equals(sourceNew)
})

it('reconciles change when inserting again', () => {
let sourceOriginal = `let a = 3`
let sourceNew = `let a = 3\nx`
let root = TreeSitterDomainObject.fromSource(sourceOriginal)

DomainObject.edit(root, sourceNew)



let secondEdit = `let a = 3\nx\n`

expect(root.children.length).equals(2)

debugger
DomainObject.edit(root, secondEdit, undefined, {actions: editScript => {

expect(editScript.actions.length, "actions").equals(0)
}})

expect(root.children.length).equals(2)
})



it('reconciles changes with nothing ', () => {
Expand Down

0 comments on commit 18c855d

Please sign in to comment.