Skip to content

Commit

Permalink
Merge pull request #66 from spiltcoffee/tests
Browse files Browse the repository at this point in the history
 fix(@postdfm/dfm2ast): emptry string ('') marked as unknown syntax
  • Loading branch information
spiltcoffee authored Mar 11, 2019
2 parents 5071b4a + 95d69b0 commit 17d44b5
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 205 deletions.
4 changes: 4 additions & 0 deletions packages/@postdfm/dfm2ast/__test__/broken/form.dfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Form1: TForm1
Left = 192
Font.Name = 'MS Sans Serif'
Font.Style = []
11 changes: 11 additions & 0 deletions packages/@postdfm/dfm2ast/__test__/broken/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as fs from "fs";
import * as path from "path";
import * as dfm2ast from "../../src";

describe("dfm2ast", () => {
test("broken DFM throws error", () => {
const dfm = fs.readFileSync(path.join(__dirname, "form.dfm"), "ascii");

expect(() => dfm2ast.parse(dfm)).toThrowError("Unexpected End Of Input");
});
});
224 changes: 224 additions & 0 deletions packages/@postdfm/dfm2ast/__test__/everything/ast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
{
"astType": "object",
"kind": "object",
"name": "Form1",
"type": "TForm1",
"properties": [
{
"astType": "property",
"name": "Left",
"value": {
"astType": "integer",
"value": "192"
}
},
{
"astType": "property",
"name": "Font.Name",
"value": {
"astType": "string",
"value": "MS Sans Serif"
}
},
{
"astType": "property",
"name": "Font.Style",
"value": { "astType": "qualifiedList", "values": [] }
}
],
"children": [
{
"astType": "object",
"kind": "object",
"name": "Image1",
"type": "TImage",
"properties": [
{
"astType": "property",
"name": "Picture.Data",
"value": {
"astType": "hexString",
"value": "07544269746D617036550000424D365500000000000036000000280000005500000055000000010018000000000000550000C40E0000C40E0000000000000000"
}
},
{
"astType": "property",
"name": "Picture.MoreData",
"value": { "astType": "hexString", "value": "" }
}
],
"children": []
},
{
"astType": "object",
"kind": "inherited",
"name": "ListBox1",
"type": "TListBox",
"order": "2",
"properties": [
{
"astType": "property",
"name": "Items.Strings",
"value": {
"astType": "stringList",
"values": "this is string.\r\nand another one...and another one...now with apostrophe '\r\nhow fancy"
}
},
{
"astType": "property",
"name": "Items.MoreStrings",
"value": { "astType": "stringList", "values": [] }
}
],
"children": []
},
{
"astType": "object",
"kind": "object",
"name": "DBGrid1",
"type": "TDBGrid",
"properties": [
{
"astType": "property",
"name": "Options",
"value": {
"astType": "qualifiedList",
"values": [
{ "astType": "qualified", "value": "dgTitles" },
{ "astType": "qualified", "value": "dgIndicator" },
{ "astType": "qualified", "value": "dgColumnResize" },
{ "astType": "qualified", "value": "dgColLines" },
{ "astType": "qualified", "value": "dgRowLines" },
{ "astType": "qualified", "value": "dgTabs" },
{ "astType": "qualified", "value": "dgRowSelect" },
{
"astType": "qualified",
"value": "dgConfirmDelete"
},
{
"astType": "qualified",
"value": "dgCancelOnExit"
}
]
}
},
{
"astType": "property",
"name": "MoreOptions",
"value": {
"astType": "qualifiedList",
"values": []
}
},
{
"astType": "property",
"name": "Columns",
"value": {
"astType": "itemList",
"values": [
{
"astType": "item",
"properties": [
{
"astType": "property",
"name": "Expanded",
"value": {
"astType": "boolean",
"value": false
}
},
{
"astType": "property",
"name": "Visible",
"value": { "astType": "boolean", "value": true }
}
]
},
{
"astType": "item",
"properties": [
{
"astType": "property",
"name": "Expanded",
"value": { "astType": "boolean", "value": false }
},
{
"astType": "property",
"name": "Visible",
"value": { "astType": "boolean", "value": true }
}
]
}
]
}
},
{
"astType": "property",
"name": "MoreColumns",
"value": { "astType": "itemList", "values": [] }
}
],
"children": []
},
{
"astType": "object",
"kind": "inline",
"name": "Edit1",
"type": "TEdit",
"properties": [
{
"astType": "property",
"name": "MaxLength",
"value": { "astType": "double", "value": "6e20" }
},
{
"astType": "property",
"name": "MinLength",
"value": { "astType": "double", "value": "-20e1" }
},
{
"astType": "property",
"name": "SomeOtherLength",
"value": { "astType": "double", "value": "45.333e20" }
},
{
"astType": "property",
"name": "Color",
"value": { "astType": "integer", "value": "FF0000" }
}
],
"children": []
},
{
"astType": "object",
"kind": "object",
"name": "SubForm",
"type": "TForm2",
"properties": [],
"children": [
{
"astType": "object",
"kind": "inline",
"name": "SubEdit",
"type": "TEdit",
"properties": [
{
"astType": "property",
"name": "Value",
"value": { "astType": "string", "value": "" }
}
],
"children": []
}
]
},
{
"astType": "object",
"kind": "object",
"name": "Nothing",
"type": "TNothing",
"properties": [],
"children": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ object Form1: TForm1
07544269746D617036550000424D365500000000000036000000280000005500
000055000000010018000000000000550000C40E0000C40E0000000000000000
}
Picture.MoreData = {}
end
object ListBox1: TListBox
inherited ListBox1: TListBox [2]
Items.Strings =
( 'this is string.'
'and another one...'
+ 'and another one...'
+ 'now with apostrophe '''#13#10
+ 'now with apostrophe '''#13#10'how fancy'
)
Items.MoreStrings = ()
end
object DBGrid1: TDBGrid
Options = [dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgConfirmDelete, dgCancelOnExit]
MoreOptions = []
Columns = <
item
Expanded = False
Expand All @@ -27,5 +30,19 @@ object Form1: TForm1
Expanded = False
Visible = True
end>
MoreColumns = <>
end
inline Edit1: TEdit
MaxLength = 6e20
MinLength = -20e1
SomeOtherLength = 45.333e20
Color = $FF0000
end
object SubForm: TForm2
inline SubEdit: TEdit
Value = ''
end
end
object Nothing: TNothing
end
end
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as fs from "fs";
import * as path from "path";
import * as dfm2ast from "../src";

describe("dfm2ast", () => {
test("converted AST matches expected AST", () => {
const dfm = fs.readFileSync(path.join(__dirname, "sample.dfm"), "ascii");

const received = JSON.parse(JSON.stringify(dfm2ast.parse(dfm)));
const expected = JSON.parse(
fs.readFileSync(path.join(__dirname, "expected.json"), "utf8")
);

expect(received).toEqual(expected);
});
});
import * as fs from "fs";
import * as path from "path";
import * as dfm2ast from "../../src";

describe("dfm2ast", () => {
test("converted AST matches expected AST", () => {
const dfm = fs.readFileSync(path.join(__dirname, "form.dfm"), "ascii");

const received = JSON.parse(JSON.stringify(dfm2ast.parse(dfm)));
const expected = JSON.parse(
fs.readFileSync(path.join(__dirname, "ast.json"), "utf8")
);

expect(received).toEqual(expected);
});
});
Loading

0 comments on commit 17d44b5

Please sign in to comment.