@@ -2,14 +2,16 @@ import FS_LANGUAGE_JSON from "./fs-language.json";
2
2
import FS_MODEL from "./fs-model.json" ;
3
3
import { expect } from "chai" ;
4
4
import { deserializeChunk , deserializeLanguages , SerializationChunk } from "@lionweb/core" ;
5
- import { Children , Node } from "../../src" ;
5
+ import { Children , Node , walk } from "../../src" ;
6
6
import {
7
+ DynamicNode ,
7
8
findClassifier ,
8
9
LanguageMapping ,
9
10
STARLASU_LANGUAGE ,
10
11
STARLASU_LANGUAGE_MAPPING ,
11
12
TylasuInstantiationFacade
12
13
} from "../../src/interop/lionweb" ;
14
+ import { map , pipe , reduce } from "iter-ops" ;
13
15
14
16
abstract class File extends Node {
15
17
name : string ;
@@ -24,6 +26,9 @@ class TextFile extends File {
24
26
contents : string ;
25
27
}
26
28
29
+ function printSequence ( sequence : Generator < Node > ) : string {
30
+ return pipe ( sequence , map ( n => n . name ) , reduce ( ( s1 , s2 ) => s1 + ( s1 ? ", " : "" ) + s2 , "" ) ) . first ;
31
+ }
27
32
28
33
describe ( 'Lionweb integration' , function ( ) {
29
34
const FS_LANGUAGE = deserializeLanguages ( FS_LANGUAGE_JSON as SerializationChunk , STARLASU_LANGUAGE ) [ 0 ] ;
@@ -32,7 +37,7 @@ describe('Lionweb integration', function() {
32
37
FS_LANGUAGE_MAPPING . register ( File , findClassifier ( FS_LANGUAGE , "starlasu_language_com-strumenta-codeinsightstudio-model-filesystem_File" ) ) ;
33
38
FS_LANGUAGE_MAPPING . register ( TextFile , findClassifier ( FS_LANGUAGE , "starlasu_language_com-strumenta-codeinsightstudio-model-filesystem_TextFile" ) ) ;
34
39
35
- it ( "Can deserialize simple model" ,
40
+ it ( "can deserialize simple model" ,
36
41
function ( ) {
37
42
const nodes = deserializeChunk ( FS_MODEL , new TylasuInstantiationFacade ( [ FS_LANGUAGE_MAPPING ] ) , [ FS_LANGUAGE ] , [ ] ) ;
38
43
expect ( nodes ) . not . to . be . empty ;
@@ -50,5 +55,42 @@ describe('Lionweb integration', function() {
50
55
const file = dir . files [ 0 ] as TextFile ;
51
56
expect ( file . name ) . to . equal ( "delegate.egl" ) ;
52
57
expect ( file . contents . substring ( 0 , 10 ) ) . to . equal ( "Delegate F" ) ;
58
+
59
+ expect ( printSequence ( walk ( root . node ) ) ) . to . equal (
60
+ "resources.zip, resources, delegate.egl, rosetta-code-count-examples-2.egl, " +
61
+ "rosetta-code-count-examples-1.egl, sub1, sub2, foreach.egl, SQLDropTable.egl, for.egl, SQLBatch.egl, " +
62
+ "SQLCreateTable.egl, SQLDropTable.egl, hello.egl, foreach.egl, Calc.egl, SQLBatch.egl, " +
63
+ "multipleWhenCondition.egl, handler.egl, SQLCreateTable.egl, newExample.egl, SQLDropTable.egl, " +
64
+ "nestedLoop.egl, for.egl" ) ;
65
+ } ) ;
66
+
67
+ it ( "can deserialize simple model to dynamic nodes" ,
68
+ function ( ) {
69
+ const nodes = deserializeChunk ( FS_MODEL , new TylasuInstantiationFacade ( ) , [ FS_LANGUAGE ] , [ ] ) ;
70
+ expect ( nodes ) . not . to . be . empty ;
71
+ expect ( nodes . length ) . to . equal ( 1 ) ;
72
+ const root = nodes [ 0 ] ;
73
+ expect ( root . node ) . to . be . instanceof ( DynamicNode ) ;
74
+ let dir = root . node as DynamicNode & any ;
75
+ expect ( dir . nodeDefinition . name ) . to . equal ( "Directory" ) ;
76
+ expect ( dir . name ) . to . equal ( "resources.zip" ) ;
77
+ expect ( dir . files . length ) . to . equal ( 1 ) ;
78
+ expect ( dir . files [ 0 ] ) . to . be . instanceof ( DynamicNode ) ;
79
+ dir = dir . files [ 0 ] as DynamicNode & any ;
80
+ expect ( dir . nodeDefinition . name ) . to . equal ( "Directory" ) ;
81
+ expect ( dir . name ) . to . equal ( "resources" ) ;
82
+ expect ( dir . files . length ) . to . equal ( 15 ) ;
83
+ expect ( dir . files [ 0 ] ) . to . be . instanceof ( DynamicNode ) ;
84
+ const file = dir . files [ 0 ] as DynamicNode & any ;
85
+ expect ( file . nodeDefinition . name ) . to . equal ( "TextFile" ) ;
86
+ expect ( file . name ) . to . equal ( "delegate.egl" ) ;
87
+ expect ( file . contents . substring ( 0 , 10 ) ) . to . equal ( "Delegate F" ) ;
88
+
89
+ expect ( printSequence ( walk ( root . node ) ) ) . to . equal (
90
+ "resources.zip, resources, delegate.egl, rosetta-code-count-examples-2.egl, " +
91
+ "rosetta-code-count-examples-1.egl, sub1, sub2, foreach.egl, SQLDropTable.egl, for.egl, SQLBatch.egl, " +
92
+ "SQLCreateTable.egl, SQLDropTable.egl, hello.egl, foreach.egl, Calc.egl, SQLBatch.egl, " +
93
+ "multipleWhenCondition.egl, handler.egl, SQLCreateTable.egl, newExample.egl, SQLDropTable.egl, " +
94
+ "nestedLoop.egl, for.egl" ) ;
53
95
} ) ;
54
96
} ) ;
0 commit comments