Skip to content

Commit

Permalink
test(parse): add some tests for the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Jul 4, 2018
1 parent a76fe2b commit 76d522c
Show file tree
Hide file tree
Showing 27 changed files with 484 additions and 46 deletions.
7 changes: 7 additions & 0 deletions test/parse/04-labels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"title": "simple states with labels",
"programInputFile": "fixtures/states-with-a-label.smcat",
"astFixtureFile": "fixtures/states-with-a-label.json"
}
]
23 changes: 23 additions & 0 deletions test/parse/13-label-errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

[
{
"title": "composite states - forgot the ']'",
"program": "a [;"
},
{
"title": "composite states - nothing between []",
"program": "a [];"
},
{
"title": "composite states - illegal stuff between []",
"program": "a [ fluffy unicorns ];"
},
{
"title": "composite states - label but no equals or lhs",
"program": "a [ label];"
},
{
"title": "composite states - label but lhs",
"program": "a [ label=];"
}
]
48 changes: 48 additions & 0 deletions test/parse/fixtures/states-with-a-label.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
digraph "state transitions" {
pack=42 splines=true ordering=out compound=true overlap=scale K=0.9 epsilon=0.9 nodesep=0.2
fontname="Helvetica" fontsize=12 penwidth=2.0

node [shape=plaintext style=filled fillcolor=white fontname=Helvetica fontsize=12 penwidth=2.0]
edge [fontname=Helvetica fontsize=10]

"unset" [margin=0 label= <
<table align="center" cellborder="0" border="2" style="rounded" width="48">
<tr><td width="48" cellpadding="7">alarm not set</td></tr>
</table>
>]
subgraph "cluster_set" {
label= <
<table cellborder="0" border="0">
<tr><td>alarm set</td></tr>
<hr/>
<tr><td align="left">show a bell</td></tr>
</table>
> style=rounded penwidth=2.0
"set" [shape=point style=invis margin=0 width=0 height=0 fixedsize=true]
"silent" [margin=0 label= <
<table align="center" cellborder="0" border="2" style="rounded" width="48">
<tr><td width="48" cellpadding="7">silent</td></tr>
</table>
>]
"ringing" [margin=0 label= <
<table align="center" cellborder="0" border="2" style="rounded" width="48">
<tr><td width="48" cellpadding="7">bzzzz!</td></tr>
</table>
>]
"snoozing" [margin=0 label= <
<table align="center" cellborder="0" border="2" style="rounded" width="48">
<tr><td width="48" cellpadding="2">snoozing</td></tr>
<hr/>
<tr><td align="left" cellpadding="2">show a plus behind the bell</td></tr>
</table>
>]

}

"unset" -> "set" [label="time entered \l" lhead="cluster_set"]
"silent" -> "ringing" [label="time >= alarm time \l"]
"ringing" -> "silent" [label="off \l"]
"ringing" -> "snoozing" [label="snooze time := time + 9 min \l"]
"snoozing" -> "ringing" [label="time >= snooze time \l"]
"snoozing" -> "silent" [label="off \l"]
}
File renamed without changes.
73 changes: 73 additions & 0 deletions test/parse/fixtures/states-with-a-label.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"states": [
{
"name": "unset",
"type": "regular",
"label": "alarm not set"
},
{
"name": "set",
"type": "regular",
"label": "alarm set",
"statemachine": {
"states": [
{
"name": "silent",
"type": "regular"
},
{
"name": "ringing",
"type": "regular",
"label": "bzzzz!"
},
{
"name": "snoozing",
"type": "regular",
"activities": "show a plus behind the bell"
}
],
"transitions": [
{
"from": "silent",
"to": "ringing",
"label": "time >= alarm time",
"event": "time >= alarm time"
},
{
"from": "ringing",
"to": "silent",
"label": "off",
"event": "off"
},
{
"from": "ringing",
"to": "snoozing",
"label": "snooze time := time + 9 min",
"event": "snooze time := time + 9 min"
},
{
"from": "snoozing",
"to": "ringing",
"label": "time >= snooze time",
"event": "time >= snooze time"
},
{
"from": "snoozing",
"to": "silent",
"label": "off",
"event": "off"
}
]
},
"activities": "show a bell"
}
],
"transitions": [
{
"from": "unset",
"to": "set",
"label": "time entered",
"event": "time entered"
}
]
}
17 changes: 17 additions & 0 deletions test/parse/fixtures/states-with-a-label.smcat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


unset [label="alarm not set"],
set [label="alarm set"]: show a bell {
silent,
ringing [label="bzzzz!"],
snoozing: show a plus behind the bell;

silent => ringing: time >= alarm time;
ringing => silent: off;
ringing => snoozing: snooze time := time + 9 min;
snoozing => ringing: time >= snooze time;
snoozing => silent: off;
};


unset => set: time entered;
6 changes: 4 additions & 2 deletions test/parse/smcat-parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ const programASTPairs =
const syntaxErrors =
require("./10-no-transitions-errors.json")
.concat(require("./11-transition-errors.json"))
.concat(require("./12-composition-errors.json"));
.concat(require("./12-composition-errors.json"))
.concat(require("./13-label-errors.json"));

const fileBasedPairs =
require("./02-comments.json");
require("./02-comments.json")
.concat(require("./04-labels.json"));


describe('#parse() - happy day ASTs - ', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/render/dot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const testPairs = [{
"expectedOutput": "../parse/fixtures/pseudostates.dot"
}, {
"title": "renders pseudo states",
"input": "./states-with-a-label.json",
"expectedOutput": "./states-with-a-label.dot"
"input": "../parse/fixtures/states-with-a-label.json",
"expectedOutput": "../parse/fixtures/states-with-a-label.dot"
}];

describe('render dot', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"states": [
{
"name": "set",
"type": "regular",
"label": "alarm set",
"statemachine": {
"states": [
{
"name": "silent",
"type": "regular"
},
{
"name": "ringing",
"type": "regular"
},
{
"name": "snoozing",
"type": "regular"
}
],
"transitions": [
{
"from": "silent",
"to": "ringing",
"label": "time >= alarm time",
"event": "time >= alarm time"
},
{
"from": "ringing",
"to": "silent",
"label": "off",
"event": "off"
},
{
"from": "ringing",
"to": "snoozing",
"label": "snooze time := time + 9 min",
"event": "snooze time := time + 9 min"
},
{
"from": "snoozing",
"to": "ringing",
"label": "time >= snooze time",
"event": "time >= snooze time"
},
{
"from": "snoozing",
"to": "silent",
"label": "off",
"event": "off"
}
]
},
"activities": "some activities"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"states": [
{
"kind": "state",
"id": "set",
"onentries": [
"some activities"
],
"states": [
{
"kind": "state",
"id": "silent",
"transitions": [
{
"target": "ringing",
"event": "time____alarm_time"
}
]
},
{
"kind": "state",
"id": "ringing",
"transitions": [
{
"target": "silent",
"event": "off"
},
{
"target": "snoozing",
"event": "snooze_time_:__time___9_min"
}
]
},
{
"kind": "state",
"id": "snoozing",
"transitions": [
{
"target": "ringing",
"event": "time____snooze_time"
},
{
"target": "silent",
"event": "off"
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0">
<state id="set">
<state id="silent">
<transition event="time____alarm_time" target="ringing"/>
</state>
<state id="ringing">
<transition event="off" target="silent"/>
<transition event="snooze_time_:__time___9_min" target="snoozing"/>
</state>
<state id="snoozing">
<transition event="time____snooze_time" target="ringing"/>
<transition event="off" target="silent"/>
</state>
<onentry>some activities</onentry>
</state>
</scxml>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set [label="alarm set"]: some activities {
silent,
ringing,
snoozing;

silent => ringing: time >= alarm time;
ringing => silent: off;
ringing => snoozing: snooze time := time + 9 min;
snoozing => ringing: time >= snooze time;
snoozing => silent: off;
};
Loading

0 comments on commit 76d522c

Please sign in to comment.