-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move our minify tests to be markdown based
- Loading branch information
Showing
14 changed files
with
125 additions
and
75 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(executable | ||
(name main) | ||
(libraries | ||
illuaminate | ||
illuaminate.core | ||
illuaminate.parser | ||
illuaminate.minify | ||
md_test_runner | ||
ppx_deriving.runtime)) | ||
|
||
(rule | ||
(deps | ||
(:markdown | ||
(glob_files t_*.md))) | ||
(action | ||
(with-stdout-to | ||
rules.new.inc | ||
(with-stdin-from | ||
%{dep:rules.inc} | ||
(run %{dep:../md_test_gen.exe} --extra %{markdown}))))) | ||
|
||
(rule | ||
(alias rules) | ||
(action | ||
(diff rules.inc rules.new.inc))) | ||
|
||
(alias | ||
(name runtest) | ||
(deps | ||
(alias rules))) | ||
|
||
(include rules.inc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
open IlluaminateMinify | ||
let () = | ||
Md_test_runner.run @@ fun out _ contents -> | ||
let name = Illuaminate.File_id.mk "=input" in | ||
|
||
let process ~name contents = | ||
let lexbuf = Lexing.from_string contents in | ||
let name = Illuaminate.File_id.mk name in | ||
Format.asprintf "%t" @@ fun out -> | ||
match IlluaminateParser.program name lexbuf with | ||
match IlluaminateParser.program name (Lexing.from_string contents) with | ||
| Error err -> | ||
Illuaminate.Console_reporter.display_of_string ~out ~with_summary:false | ||
(fun _ -> Some contents) | ||
[ IlluaminateParser.Error.to_error err ] | ||
| Ok parsed -> ( | ||
(* Minify our program. *) | ||
let updated = | ||
let buffer = Buffer.create 512 in | ||
let out = Format.formatter_of_buffer buffer in | ||
(minify parsed |> Emit.(with_wrapping out "%a" program)); | ||
(IlluaminateMinify.minify parsed | ||
|> IlluaminateMinify.Emit.(with_wrapping out "%a@\n" program)); | ||
Buffer.contents buffer | ||
in | ||
|
||
Format.pp_print_string out updated; | ||
|
||
let lexbuf = Lexing.from_string updated in | ||
match IlluaminateParser.program name lexbuf with | ||
(* Attempt to reparse it. This doesn't check the two are syntactically equivalent, only that | ||
it is syntactically valid. *) | ||
match IlluaminateParser.program name (Lexing.from_string updated) with | ||
| Ok _ -> () | ||
| Error err -> | ||
Format.pp_print_string out "\n--[==[\n"; | ||
Illuaminate.Console_reporter.display_of_string ~out ~with_summary:false | ||
(fun _ -> Some updated) | ||
[ IlluaminateParser.Error.to_error err ]; | ||
Format.pp_print_string out "]==]\n") | ||
|
||
let tests = | ||
OmnomnomGolden.of_directory process ~group:"Minify" ~directory:"data/minify" ~extension:".lua" () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(rule (deps (glob_files extra/*.lua)) (action (with-stdout-to t_minify.new (with-stdin-from %{dep:t_minify.md} (run %{dep:./main.exe} md))))) | ||
(rule (alias t_minify) (action (diff t_minify.md t_minify.new))) | ||
(alias | ||
(name runtest) | ||
(deps | ||
(alias t_minify))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
```lua | ||
local function printf(str, ...) | ||
print(string.format(str, ...)) | ||
end | ||
|
||
local h, s = {}, 1 | ||
for i = 1, 10 do | ||
printf("Hello", i * 2) | ||
end | ||
``` | ||
|
||
```txt | ||
local function e(t,...)print(string.format(t,...))end local a,o={},1 for i=1,10 | ||
do | ||
e("Hello",i*2)end | ||
``` | ||
|
||
|
||
# Literals | ||
Various literals are minified correctly. | ||
|
||
```lua | ||
local x | ||
|
||
x = 0 | ||
x = 0., .0, 0.0 | ||
x = 0. .. .0 | ||
x = - - 2 | ||
x = 2 and 2 | ||
do local x = 0 end | ||
|
||
x = "hello" | ||
x = 'hello' | ||
x = [[hello]] | ||
x = x[ [[hello]] ] | ||
``` | ||
|
||
```txt | ||
local e e=0 e=0.,.0,0.0 e=0. .. .0 e=- -2 e=2 and 2 do local e=0 end | ||
e="hello"e='hello'e=[[hello]]e=e[ | ||
[[hello]]] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(** Generate our [rules.inc] file. *) | ||
|
||
let () = | ||
let files = ref [] in | ||
let extra = ref false in | ||
Arg.parse | ||
[ ("--extra", Arg.Set extra, "Add a dependency on files in the extra/ directory.") ] | ||
(fun x -> files := Filename.remove_extension x :: !files) | ||
__MODULE__; | ||
let files = List.sort String.compare !files and extra = !extra in | ||
List.iter | ||
(fun name -> | ||
let println x = Printf.printf (x ^^ "\n") in | ||
println | ||
{|(rule %s(action (with-stdout-to %s.new (with-stdin-from %%{dep:%s.md} (run %%{dep:./main.exe} md)))))|} | ||
(if extra then "(deps (glob_files extra/*.lua)) " else "") | ||
name name; | ||
println {|(rule (alias %s) (action (diff %s.md %s.new)))|} name name name) | ||
files; | ||
print_string {| | ||
(alias | ||
(name runtest) | ||
(deps|}; | ||
List.iter (Printf.printf "\n (alias %s)") files; | ||
print_endline "))" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters