Skip to content

Commit

Permalink
Write system tests for lobster-json regarding directory input
Browse files Browse the repository at this point in the history
- Add a requirement to specify the behavior when a directory is specified as input
- Add system tests
  • Loading branch information
phiwuu committed Feb 12, 2025
1 parent bb92390 commit 07fdd7c
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lobster/tools/json/input_directory.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package json_req
import req
/*
req.System_Requirement Parse_Input_File {
description = '''
IF a list element given through the command line option "FILE_OR_DIR" is a file,

(OTHERWISE, the tool shall exit with a non-zero return code.)
'''
}

req.System_Requirement_Aspect Parse_Input_File_JSON_Extension {
description = '''
AND if the file extension is "json" (case-insensitive),
'''
}

req.System_Requirement_Aspect Parse_Input_File_Valid_JSON {
description = '''
AND if the file content is valid JSON,
'''
}

req.System_Requirement_Aspect Parse_Input_File_Input_Items {
description = '''
THEN each key-value pair of the outer-most dictionary of the JSON data struct
'''
}

req.System_Requirement_Aspect Parse_Input_File_To_Lobster {
description = '''
SHALL be written in the LOBSTER interchange format
'''
}

// missing aspect: how to convert (i.e. what is the item name)?

req.System_Requirement_Aspect Parse_Input_File_To_Stdout {
description = '''
to the file given in the command line option "out",
IF that option is given and is not an empty string,
'''
}

req.System_Requirement_Aspect Parse_Input_File_To_File {
description = '''
OTHERWISE to STDOUT.
'''
}
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"data": [
{
"tag": "json ./file.json:tree on island",
"location": {
"kind": "file",
"file": "./file.json",
"line": null,
"column": null
},
"name": "./file.json:tree on island",
"messages": [],
"just_up": [],
"just_down": [],
"just_global": [],
"framework": "JSON",
"kind": "Test Vector",
"status": null
}
],
"generator": "lobster-json",
"schema": "lobster-act-trace",
"version": 3
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lobster-json: wrote 1 items to output.lobster
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--single
--tag-attribute=something
--name-attribute=name
--out=output.lobster
dir1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"data": [
{
"tag": "json ./dir1/dir2/deeply-nested.json:dir1.dir2.deeply-nested.1",
"location": {
"kind": "file",
"file": "./dir1/dir2/deeply-nested.json",
"line": null,
"column": null
},
"name": "./dir1/dir2/deeply-nested.json:dir1.dir2.deeply-nested.1",
"messages": [],
"just_up": [],
"just_down": [],
"just_global": [],
"framework": "JSON",
"kind": "Test Vector",
"status": null
},
{
"tag": "json ./dir1/nested.json:dir1.nested.1",
"location": {
"kind": "file",
"file": "./dir1/nested.json",
"line": null,
"column": null
},
"name": "./dir1/nested.json:dir1.nested.1",
"messages": [],
"just_up": [],
"just_down": [],
"just_global": [],
"framework": "JSON",
"kind": "Test Vector",
"status": null
},
{
"tag": "json ./file.json:file.1",
"location": {
"kind": "file",
"file": "./file.json",
"line": null,
"column": null
},
"name": "./file.json:file.1",
"messages": [],
"just_up": [],
"just_down": [],
"just_global": [],
"framework": "JSON",
"kind": "Test Vector",
"status": null
}
],
"generator": "lobster-json",
"schema": "lobster-act-trace",
"version": 3
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lobster-json: wrote 3 items to output.lobster
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--single
--tag-attribute=something
--out=output.lobster
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"cherry": {
"data": [
{
"name": "element three"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"banana": {
"data": [
{
"name": "element two"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"apple": {
"data": [
{
"name": "element one"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The input file of this test defines a JSON data struct which has got data items in its
outer-most dictionary, as well as nested items.
According to the requirement only the data items from the outer-most dictionary must be considered.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lobster-json: wrote 1 items to output.lobster
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--single
--tag-attribute=something
--out=output.lobster
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"outer1": {
"data": [
{
"name": "Take this item!"
},
{

"name": "unclear"
}
]
},
"outer2": {
"data": [
{
"name": "Take this item!"
},
{

"name": "unclear"
}
]
}
}

0 comments on commit 07fdd7c

Please sign in to comment.