Skip to content

Commit

Permalink
Add structured output tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 23, 2023
1 parent decfc0b commit f1f7b0a
Show file tree
Hide file tree
Showing 103 changed files with 8,685 additions and 69 deletions.
507 changes: 507 additions & 0 deletions tests/Visp.Compiler.UnitTests/StructuredOutputTests.generated.fs

Large diffs are not rendered by default.

84 changes: 57 additions & 27 deletions tests/Visp.Compiler.UnitTests/TestUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,63 @@ let parseCoreLibs () =
with :? ParseHelpers.SyntaxError as syn ->
raise (LexHelpers.syntaxErrorToParseError syn)

let runTest (name: string) =
parseCoreLibs ()

let path = getVispFilePath name
let fileName = Path.GetFileName path
let inline private verify (out: string) dir (param: string) =
async {
let task =
Verifier
.Verify(out)
.UseDirectory(dir)
.DisableDiff()
.UseParameters(param)
.ToTask()

let filePathToReplace =
Path.GetDirectoryName path |> Path.TrimEndingDirectorySeparator
return! (task |> Async.AwaitTask)
}

try
let parsed = CoreParser.parseFile path true

use stream = new StringWriter()
CoreParser.writeToStreamNew parsed stream fileName

let output =
stream
.ToString()
.Replace(filePathToReplace + "/", "")
.Replace(filePathToReplace + "\\", "")

Verifier
.Verify(output)
.UseDirectory("snapshots")
.DisableDiff()
.UseParameters(name.Replace('/', '_').Replace('\\', '_'))
.ToTask()
|> Async.AwaitTask
with :? ParseHelpers.SyntaxError as syn ->
raise (LexHelpers.syntaxErrorToParseError syn)
let runStructuredOutputTest (name: string) =
async {
parseCoreLibs ()
let path = getVispFilePath name

try
let parsed = CoreParser.parseFile path true

let nameParam = name.Replace('/', '_').Replace('\\', '_')

return! verify (sprintf "%A" parsed) "parsing-snapshots" nameParam
with :? ParseHelpers.SyntaxError as syn ->
return raise <| (LexHelpers.syntaxErrorToParseError syn)
}

let runWriteTest (name: string) =
async {
parseCoreLibs ()

let path = getVispFilePath name
let fileName = Path.GetFileName path

let filePathToReplace =
Path.GetDirectoryName path |> Path.TrimEndingDirectorySeparator

try
let parsed = CoreParser.parseFile path true

use stream = new StringWriter()
CoreParser.writeToStreamNew parsed stream fileName

let output =
stream
.ToString()
.Replace(filePathToReplace + "/", "")
.Replace(filePathToReplace + "\\", "")

let nameParam = name.Replace('/', '_').Replace('\\', '_')

return! verify output "snapshots" nameParam

with :? ParseHelpers.SyntaxError as syn ->
return raise <| (LexHelpers.syntaxErrorToParseError syn)
}

let runTest (name: string) = runWriteTest name
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Compile Include="TestUtils.fs" />
<Compile Include="WriterTest.fs" />
<Compile Include="ParsingTests.generated.fs" />
<Compile Include="StructuredOutputTests.generated.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ParsedFile
[AnonModule
([Expr
(LetOrUse
(Named (SynSymbol arr, (8,5--8,8)),
Collection
(SynCollection
(FsArray,
[Const (Int32 1, (8,12--8,13)); Const (Int32 2, (8,14--8,15));
Const (Int32 3, (8,16--8,17)); Const (Int32 4, (8,18--8,19));
Const (Int32 5, (8,20--8,21))], (8,9--8,24))), None,
(8,1--8,24)), (8,0--8,25));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("arr[0] %A", Regular, (10,9--10,20)), (10,9--10,20));
DotIndex
(Symbol (SynSymbol arr), [Const (Int32 0, (10,24--10,25))],
(10,22--10,30))], (10,1--10,31)), (10,0--10,32));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("arr[1] %A", Regular, (11,9--11,20)), (11,9--11,20));
DotIndex
(Symbol (SynSymbol arr), [Const (Int32 1, (11,24--11,25))],
(11,22--11,30))], (11,1--11,31)), (11,0--11,32));
Expr
(LetOrUse
(Named (SynSymbol visp_result_todo, (13,0--13,3)),
Symbol (SynSymbol arr), None, (13,0--13,3)), (13,0--13,3));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const (String ("%A", Regular, (13,0--13,3)), (13,0--13,3));
Symbol (SynSymbol visp_result_todo)], (13,0--13,3)), (13,0--13,3))],
(8,0--13,3))]
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
ParsedFile
[AnonModule
([Expr
(TypeAlias
(SynSymbol Grid, Array (2, Ident char, (8,14--8,21)), (8,1--8,21)),
(8,0--8,22));
Expr
(LetOrUse
(Named (SynSymbol arr, (10,5--10,8)),
FunctionCall
(Symbol (SynSymbol Array2D.create),
[Const (Int32 5, (10,25--10,26));
Const (Int32 5, (10,27--10,28));
Const (Char '.', (10,29--10,32))], (10,10--10,32)), None,
(10,1--10,33)), (10,0--10,34));
Expr
(LetOrUse
(Named (SynSymbol y, (12,5--12,6)), Const (Int32 4, (12,7--12,8)),
None, (12,1--12,8)), (12,0--12,9));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("arr[0,0]=%A", Regular, (14,9--14,22)), (14,9--14,22));
DotIndex
(Symbol (SynSymbol arr),
[Const (Int32 0, (14,26--14,27));
Const (Int32 0, (14,28--14,29))], (14,24--14,34))],
(14,1--14,35)), (14,0--14,36));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("arr[1,2]=%A", Regular, (15,9--15,22)), (15,9--15,22));
DotIndex
(Symbol (SynSymbol arr),
[Const (Int32 1, (15,26--15,27));
Const (Int32 1, (15,29--15,30))], (15,24--15,35))],
(15,1--15,36)), (15,0--15,37));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("arr[3,3]=%A", Regular, (16,9--16,22)), (16,9--16,22));
FunctionCall
(Symbol (SynSymbol Array2D.get),
[Symbol (SynSymbol arr); Const (Int32 3, (16,40--16,41));
Const (Int32 3, (16,42--16,43))], (16,24--16,43))],
(16,1--16,44)), (16,0--16,45));
Expr
(Set
(DotIndex
(Symbol (SynSymbol arr),
[Const (Int32 2, (18,9--18,10)); Const (Int32 2, (18,12--18,13))],
(18,7--18,18)), Const (Char '#', (18,20--18,23)), (18,1--18,23)),
(18,0--18,24));
Expr
(Set
(DotIndex
(Symbol (SynSymbol arr),
[Const (Int32 3, (19,9--19,10)); Const (Int32 4, (19,12--19,13))],
(19,7--19,18)), Const (Char '#', (19,20--19,23)), (19,1--19,23)),
(19,0--19,24));
Expr
(Set
(DotIndex
(Symbol (SynSymbol arr),
[Const (Int32 4, (20,9--20,10)); Const (Int32 4, (20,12--20,13))],
(20,7--20,18)), Const (Char '#', (20,20--20,23)), (20,1--20,23)),
(20,0--20,24));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("arr[3,4]=%A", Regular, (21,9--21,22)), (21,9--21,22));
ThreadLast
([Expr (Symbol (SynSymbol arr), (21,28--21,31));
Index
([Op
(Infix
(SynSymbol -,
[Symbol (SynSymbol y);
Const (Int32 1, (21,39--21,40))], (21,35--21,40)));
Op
(Infix
(SynSymbol +,
[Const (Int32 1, (21,46--21,47));
Const (Int32 1, (21,48--21,49));
Const (Int32 1, (21,50--21,51));
Const (Int32 1, (21,52--21,53))], (21,44--21,53)))],
(21,32--21,55))], (21,24--21,55))], (21,1--21,56)),
(21,0--21,57));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("arr[4,4]=%A", Regular, (22,9--22,22)), (22,9--22,22));
ThreadLast
([Expr (Symbol (SynSymbol arr), (22,28--22,31));
Index
([Symbol (SynSymbol y);
Op
(Infix
(SynSymbol +,
[Const (Int32 1, (22,40--22,41));
Const (Int32 1, (22,42--22,43));
Const (Int32 1, (22,44--22,45));
Const (Int32 1, (22,46--22,47))], (22,38--22,47)))],
(22,32--22,49))], (22,24--22,49))], (22,1--22,50)),
(22,0--22,51));
Expr
(LetOrUse
(Named (SynSymbol visp_result_todo, (25,0--25,3)),
Symbol (SynSymbol arr), None, (25,0--25,3)), (25,0--25,3));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const (String ("%A", Regular, (25,0--25,3)), (25,0--25,3));
Symbol (SynSymbol visp_result_todo)], (25,0--25,3)), (25,0--25,3))],
(8,0--25,3))]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ParsedFile
[AnonModule
([Expr
(TypeAlias
(SynSymbol Grid, Array (2, Ident char, (8,14--8,21)), (8,1--8,21)),
(8,0--8,22));
Expr
(LetOrUse
(Named (SynSymbol arr, (10,5--10,8)),
FunctionCall
(Symbol (SynSymbol Array2D.create),
[Const (Int32 5, (10,25--10,26));
Const (Int32 5, (10,27--10,28));
Const (Char '.', (10,29--10,32))], (10,10--10,32)), None,
(10,1--10,33)), (10,0--10,34));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("arr[*,0]=%A", Regular, (12,9--12,22)), (12,9--12,22));
DotIndex
(Symbol (SynSymbol arr),
[Symbol (SynSymbol *); Const (Int32 0, (12,28--12,29))],
(12,24--12,34))], (12,1--12,35)), (12,0--12,36));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("arr[0,*]=%A", Regular, (13,9--13,22)), (13,9--13,22));
DotIndex
(Symbol (SynSymbol arr),
[Const (Int32 0, (13,26--13,27)); Symbol (SynSymbol *)],
(13,24--13,34))], (13,1--13,35)), (13,0--13,36));
Expr
(LetOrUse
(Named (SynSymbol visp_result_todo, (15,0--15,3)),
Symbol (SynSymbol arr), None, (15,0--15,3)), (15,0--15,3));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const (String ("%A", Regular, (15,0--15,3)), (15,0--15,3));
Symbol (SynSymbol visp_result_todo)], (15,0--15,3)), (15,0--15,3))],
(8,0--15,3))]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
ParsedFile
[AnonModule
([HashDirective
(ParsedHashDirective
("nowarn", [String ("20", Regular, (9,8--9,12))], (9,0--9,12)),
(9,0--9,12));
Expr
(FunctionDef
(SynSymbol inc, None,
Args
(List
[Typed
(Named (SynSymbol v, (11,10--11,11)), Ident Value,
(11,9--11,19))], (11,8--11,20)),
[FunctionCall
(Symbol (SynSymbol Value.from),
[Op
(Infix
(SynSymbol +,
[Const (Int64 1L, (12,19--12,21));
FunctionCall
(Symbol (SynSymbol unwrapInt), [Symbol (SynSymbol v)],
(12,23--12,34))], (12,17--12,35)))], (12,5--12,36))],
(11,1--12,37)), (11,0--12,38));
Expr
(LetOrUse
(Named (SynSymbol count, (13,5--13,10)),
Atom (Const (Int64 0L, (13,17--13,19)), (13,12--13,19)), None,
(13,1--13,20)), (13,0--13,21));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("count is %O", Regular, (15,9--15,22)), (15,9--15,22));
Deref (true, Symbol (SynSymbol count), (15,23--15,29))],
(15,1--15,29)), (15,0--15,30));
Expr
(FunctionCall
(Symbol (SynSymbol swap!),
[Symbol (SynSymbol count); Symbol (SynSymbol inc)], (17,1--17,16)),
(17,0--17,17));
Expr
(LetOrUse
(Named (SynSymbol visp_result_todo, (19,0--19,30)),
FunctionCall
(Symbol (SynSymbol printfn),
[Const
(String ("count is %O", Regular, (19,9--19,22)),
(19,9--19,22));
Deref (true, Symbol (SynSymbol count), (19,23--19,29))],
(19,1--19,29)), None, (19,0--19,30)), (19,0--19,30));
Expr
(FunctionCall
(Symbol (SynSymbol printfn),
[Const (String ("%A", Regular, (19,0--19,30)), (19,0--19,30));
Symbol (SynSymbol visp_result_todo)], (19,0--19,30)),
(19,0--19,30))], (9,0--19,30))]
Loading

0 comments on commit f1f7b0a

Please sign in to comment.