Skip to content

Commit 80380fd

Browse files
committed
Import more tests
1 parent 3900ea2 commit 80380fd

File tree

118 files changed

+86164
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+86164
-5
lines changed

.autofonce

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[project]
2+
# name to use to infer config
3+
name = "superbol-studio-oss"
4+
5+
# files used to locate the project top directory
6+
# and to set the AUTOFONCE_SOURCE_DIR
7+
source_anchors = [ "import/gnucobol/tests/testsuite.at", "!" ]
8+
9+
# files used to locate the project build directory
10+
# where the _autofonce/ directory will be created
11+
# and to set the AUTOFONCE_BUILD_DIR
12+
# use "!" to trigger an error if build dir is mandatory
13+
build_anchors = [ "default" ]
14+
15+
# paths in project sources that are good candidates to
16+
# be tested as build dirs. Useful to run autofonce
17+
# from outside the build directory
18+
build_dir_candidates = [ "_build" ]
19+
20+
# where the _autofonce/ dir should be created:
21+
# * 'build': in the build directory
22+
# * 'source': in the source directory
23+
# * 'config': in the directory of the config file
24+
run_from = "build"
25+
26+
[testsuites]
27+
# alias = "path-from-topdir"
28+
[testsuites.testsuite]
29+
file = "import/gnucobol/tests/testsuite.at"
30+
path = [ "import/gnucobol/tests/testsuite.src"]
31+
env = "testsuite"
32+
33+
[envs]
34+
# env_name = """..."""
35+
# env_name = "<local-path-to-env-file"
36+
testsuite = """
37+
export COMPILE_ONLY="$AUTOFONCE_BUILD_DIR/default/src/superbol/main.exe x-parse file"
38+
export COB_CONFIG_DIR="$AUTOFONCE_SOURCE_DIR/import/gnucobol/config"
39+
"""
40+
41+
[project]
42+
# files to be captured into results.log
43+
# in case of test failure.
44+
captured_files = [ ]
45+

.drom

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version:0.9.0
55

66
# hash of toml configuration files
77
# used for generation of all files
8-
306a162bd34aef4c3753c84e38852da6:.
8+
51efca4da0e63268b2046a7a0604ed40:.
99
# end context for .
1010

1111
# begin context for .github/workflows/workflow.yml
@@ -80,7 +80,7 @@ c8281f46ba9a11d0b61bc8ef67eaa357:docs/style.css
8080

8181
# begin context for dune-project
8282
# file dune-project
83-
69659cb561ea7a5fbe7c54ac41297836:dune-project
83+
bc7c69c6baba24fa8481a31a1e33b88e:dune-project
8484
# end context for dune-project
8585

8686
# begin context for opam/cobol_ast.opam
@@ -115,7 +115,7 @@ fea158982cf75a9547f3ef0d352851cb:opam/cobol_data.opam
115115

116116
# begin context for opam/cobol_parser.opam
117117
# file opam/cobol_parser.opam
118-
e20b6d94b7638ca8bf1b1ed68291f39b:opam/cobol_parser.opam
118+
43dba93158fd4b90c93e2b7c9b770677:opam/cobol_parser.opam
119119
# end context for opam/cobol_parser.opam
120120

121121
# begin context for opam/cobol_preproc.opam
@@ -335,7 +335,7 @@ f5b5ba58f2a9ef21787bfca4f4268580:src/lsp/cobol_lsp/dune
335335

336336
# begin context for src/lsp/cobol_parser/dune
337337
# file src/lsp/cobol_parser/dune
338-
b68ae0e16fe9fde7a4b6b03d84be2680:src/lsp/cobol_parser/dune
338+
08706ca64cceec7220b7ffc2d654be97:src/lsp/cobol_parser/dune
339339
# end context for src/lsp/cobol_parser/dune
340340

341341
# begin context for src/lsp/cobol_parser/version.mlt

dune-project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
(cobol_preproc (= version))
289289
(cobol_common (= version))
290290
(cobol_ast (= version))
291+
(autofonce_lib ( >= 0.8 ))
291292
(menhir ( = 20220210 ))
292293
ppx_inline_test
293294
ppx_expect

opam/cobol_parser.opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ depends: [
5555
"cobol_preproc" {= version}
5656
"cobol_common" {= version}
5757
"cobol_ast" {= version}
58+
"autofonce_lib" {>= "0.8"}
5859
"menhir" {= "20220210"}
5960
"ppx_inline_test" {with-test}
6061
"ppx_expect" {with-test}

src/lsp/cobol_parser/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(public_name cobol_parser)
66
(wrapped true)
77
; use field 'dune-libraries' to add libraries without opam deps
8-
(libraries ppx_deriving menhirLib ez_file ebcdic_lib cobol_preproc cobol_common cobol_ast str)
8+
(libraries ppx_deriving menhirLib ez_file ebcdic_lib cobol_preproc cobol_common cobol_ast autofonce_lib str)
99
; use field 'dune-flags' to set this value
1010
(flags (:standard))
1111
; use field 'dune-stanzas' to add more stanzas here

src/lsp/cobol_parser/package.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ cobol_preproc = "version"
5959
ebcdic_lib = "version"
6060
ez_file = ">=0.3"
6161
ppx_deriving = ">=5.2.1"
62+
autofonce_lib = ">=0.8"
63+
6264
[dependencies.menhir]
6365
libname = "menhirLib"
6466
version = ">=1.2"

test/cobol_data/dune

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(tests
2+
(names test_qualified_map)
3+
(modules test_qualified_map)
4+
(libraries alcotest cobol_data))

test/cobol_data/test_qualified_map.ml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* Copyright (c) 2021-2023 OCamlPro SAS *)
4+
(* *)
5+
(* All rights reserved. *)
6+
(* This file is distributed under the terms of the *)
7+
(* OCAMLPRO-NON-COMMERCIAL license. *)
8+
(* *)
9+
(**************************************************************************)
10+
open Cobol_ast
11+
open Cobol_common.Srcloc.INFIX
12+
13+
type t =
14+
| Elementary of string * int
15+
| Group of string * int * t list
16+
17+
let wss =
18+
[Group ("Level 1", 0, [
19+
Group ("Level 3", 1, [
20+
Elementary ("Level 2", 2)]);
21+
Group ("Level 4", 3,[
22+
Elementary ("Level 2", 4)])
23+
]);
24+
Group ("X", 0, [
25+
Group ("Y", 5, [
26+
Elementary ("Z", 10)
27+
])
28+
])
29+
]
30+
31+
let unwrap = Result.get_ok
32+
let unwrap_err = Result.get_error
33+
let dummy_loc = Cobol_common.Srcloc.raw Lexing.(dummy_pos, dummy_pos)
34+
35+
let rec qualname_of_str_list: string list -> qualname = function
36+
| [] -> raise (Invalid_argument "The string list should not be empty")
37+
| hd::[] -> Name (hd &@ dummy_loc)
38+
| hd::tl -> Qual (hd &@ dummy_loc, qualname_of_str_list tl)
39+
40+
41+
let transform wss map =
42+
let rec aux str_list map = function
43+
| Group (name, elt, elts) ->
44+
let str_list = name::str_list in
45+
List.fold_left (aux str_list)
46+
(Cobol_data.Qualmap.add (qualname_of_str_list str_list) elt map)
47+
elts
48+
| Elementary (name, elt) ->
49+
Cobol_data.Qualmap.add (qualname_of_str_list (name::str_list)) elt map
50+
in
51+
aux [] map wss
52+
53+
let wss = List.fold_left
54+
(fun map grp ->
55+
transform grp map)
56+
Cobol_data.Qualmap.empty
57+
wss
58+
59+
let wss =
60+
Cobol_data.Qualmap.add
61+
(Qual ("Level 5" &@ dummy_loc,
62+
Qual ("Level 3" &@ dummy_loc,
63+
Name ("Level 1" &@ dummy_loc))))
64+
10
65+
wss
66+
67+
let elt = Alcotest.testable Format.pp_print_int (=)
68+
(* let error = Alcotest.testable *)
69+
(* (fun fmt -> function `AmbiguousQualification qualname -> Format.fprintf fmt "Duplicate(@[%a@])" pp_qualname qualname) *)
70+
(* (=) *)
71+
72+
let qual n qn =
73+
Qual (n &@ dummy_loc, qn)
74+
75+
let name n: qualname =
76+
Name (n &@ dummy_loc)
77+
78+
let access_elt_1 () =
79+
Alcotest.(check elt) "can access simple elt"
80+
(Cobol_data.Qualmap.find (name "Level 1") wss) 0
81+
82+
let access_elt_3 () =
83+
Alcotest.(check elt) "can access simple sub element"
84+
(Cobol_data.Qualmap.find (name "Level 3") wss) 1
85+
86+
let access_elt_3_2 () =
87+
Alcotest.(check elt) "can access qualified elt"
88+
(Cobol_data.Qualmap.find (qual "Level 2" (name "Level 3")) wss) 2
89+
90+
let access_elt_4_2 () =
91+
Alcotest.(check elt) "can access qualified elt"
92+
(Cobol_data.Qualmap.find (qual "Level 2" (name "Level 4")) wss) 4
93+
94+
let duplicate_2 () =
95+
let qualname: qualname = name "Level 2" in
96+
Alcotest.check_raises "Not_found on ambiguous"
97+
Not_found (fun () -> ignore @@ Cobol_data.Qualmap.find qualname wss)
98+
99+
let bad_name () =
100+
let qualname: qualname = qual "Y" (name "Z") in
101+
Alcotest.check_raises "Not_found on bad name"
102+
Not_found (fun () -> ignore @@ Cobol_data.Qualmap.find qualname wss)
103+
104+
let access_elt_x_y_z () =
105+
let qualname: qualname = qual "Z" (qual "Y" (name "X")) in
106+
Alcotest.(check elt) "can access qualified elt"
107+
(Cobol_data.Qualmap.find qualname wss) 10
108+
109+
let access_elt_x_z () =
110+
let qualname: qualname = qual "Z" (name "X") in
111+
Alcotest.(check elt) "can access partial qualified elt"
112+
(Cobol_data.Qualmap.find qualname wss) 10
113+
114+
let bad_order () =
115+
let qualname: qualname = qual "Z" (qual "X" (name "Y")) in
116+
Alcotest.check_raises "Not_found on invalid name order"
117+
Not_found (fun () -> ignore @@ Cobol_data.Qualmap.find qualname wss)
118+
119+
(* let pp_print_str_list =
120+
Format.(pp_print_list ~pp_sep:pp_print_space pp_print_string)
121+
122+
let pp_print_set fmt =
123+
Cobol_data.Qualmap.(fun elt ->
124+
pp_qualname fmt elt;
125+
Format.pp_print_break fmt 2 0)
126+
127+
let pp_print_map f fmt =
128+
Cobol_data.Qualmap.iter (fun l elt ->
129+
Format.fprintf fmt
130+
"Key: %a; Value: %a;\n"
131+
pp_qualname l
132+
f elt)
133+
134+
let pp_map fmt m =
135+
Format.fprintf
136+
fmt
137+
"Bindings: @[<h>%a@]@;"
138+
(pp_print_map Format.pp_print_int) m *)
139+
140+
(* let _ =
141+
Format.printf "%a" pp_map wss *)
142+
143+
let () =
144+
Alcotest.(run "qualified map" [
145+
"access", [
146+
test_case "Access Level 1" `Quick access_elt_1;
147+
test_case "Access Level 3" `Quick access_elt_3;
148+
test_case "Access Level 2 IN Level 3" `Quick access_elt_3_2;
149+
test_case "Access Level 2 IN Level 4" `Quick access_elt_4_2;
150+
test_case "Error on duplicate" `Quick duplicate_2;
151+
test_case "Error on unknown name" `Quick bad_name;
152+
test_case "Access Z OF Y OF X" `Quick access_elt_x_y_z;
153+
test_case "Access Z OF X" `Quick access_elt_x_z;
154+
test_case "Error on invalid order" `Quick bad_order;
155+
]])

test/cobol_parsing/dune

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(tests
2+
(names test_picture_parsing test_combined_relations_parsing)
3+
(modules test_picture_parsing test_combined_relations_parsing)
4+
(libraries alcotest cobol_parser cobol_data))

0 commit comments

Comments
 (0)