Skip to content

Commit 8bc7d39

Browse files
committed
More
1 parent 234ffba commit 8bc7d39

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

imlformat/imlformat.format.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { Buffer } from 'node:buffer';
44
import * as prettier from 'prettier';
55
import * as iml_prettier from './iml-prettier';
66

7-
export async function format(text: string): Promise<string> {
7+
export async function format(text: string, config_root: string = null): Promise<string> {
88
try {
9-
const config_file = await prettier.resolveConfigFile();
9+
const config_file = await prettier.resolveConfigFile(config_root);
1010
let options: prettier.Options | null = null;
1111
if (config_file)
1212
options = await prettier.resolveConfig(config_file);
1313
else {
1414
options = {
1515
semi: false
16-
}
16+
};
1717
}
1818
options.parser = "iml-parse";
1919
options.plugins = [iml_prettier];
@@ -29,5 +29,5 @@ export async function format_file(filename: string): Promise<string> {
2929
const buffer = Buffer.allocUnsafe(stats.size);
3030
const fd = fs.openSync(filename, "r");
3131
fs.readSync(fd, buffer, 0, buffer.length, 0);
32-
return await format(buffer.toString());
32+
return await format(buffer.toString(), filename);
3333
}

imlformat/test/comments.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ let f = 1
1212
let f = 1`))
1313
})
1414

15+
test("Comment 2", () => {
16+
format(`
17+
let f = 1
18+
(* This is a comment *)
19+
`).then(x =>
20+
expect(x).toEqual(`\
21+
(* This is a comment *)
22+
let f = 1`))
23+
})
24+
1525
test("Docstring 1", () => {
1626
format(`
1727
(** This is a docstring *)
@@ -21,3 +31,22 @@ let f = 1
2131
let f = 1
2232
(** This is a docstring *)`))
2333
})
34+
35+
test("Floating docstring", () => {
36+
format(`
37+
let f
38+
=
39+
1
40+
41+
(** This is a docstring *)
42+
43+
let
44+
g = 1
45+
`).then(x =>
46+
expect(x).toEqual(`\
47+
let f = 1
48+
49+
(** This is a docstring *)
50+
51+
let g = 1`))
52+
})

imlformat/test/theorems.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ test("theorem 1", () => {
77
let f x = (x) + (1)
88
99
theorem
10-
thm1 x y z
11-
= ((f x ) >
12-
x)
13-
&& ((f y ) > y)
14-
&& ((f z ) > z)
10+
thm1 x (y : int) z
11+
= f x >
12+
x
13+
&& f
14+
y > y
15+
&& f z > z
1516
[@@timeout 3600]
1617
[@@disable f] [@@by [%expand "f"] @> auto]
1718
[@@by
@@ -23,7 +24,7 @@ theorem
2324
expect(x).toEqual(`\
2425
let f x = x + 1
2526
26-
theorem thm1 x y z =
27+
theorem thm1 x (y : int) z =
2728
((f x) > x) && (((f y) > y) && ((f z) > z))
2829
[@@timeout 3600]
2930
[@@disable f]

0 commit comments

Comments
 (0)