File tree Expand file tree Collapse file tree 5 files changed +12
-23
lines changed
src/Infrastructure/HydraScript.Infrastructure
tests/HydraScript.IntegrationTests Expand file tree Collapse file tree 5 files changed +12
-23
lines changed Original file line number Diff line number Diff line change 11using System . Diagnostics . CodeAnalysis ;
2- using System . IO . Abstractions ;
32using HydraScript . Domain . FrontEnd . Lexer ;
43using Microsoft . Extensions . DependencyInjection ;
5- using Microsoft . Extensions . Options ;
64
75namespace HydraScript . Infrastructure . Dumping ;
86
97internal class DumpingLexer (
108 [ FromKeyedServices ( DecoratorKey . Value ) ]
119 ILexer lexer ,
12- IFileSystem fileSystem ,
13- IOptions < FileInfo > inputFile ) : ILexer
10+ IDumpingService dumpingService ) : ILexer
1411{
1512 [ ExcludeFromCodeCoverage ]
1613 public IStructure Structure => lexer . Structure ;
1714
1815 public List < Token > GetTokens ( string text )
1916 {
2017 var tokens = lexer . GetTokens ( text ) ;
21- var fileName = inputFile . Value . Name . Split ( ".js" ) [ 0 ] ;
22- fileSystem . File . WriteAllText (
23- $ "{ fileName } .tokens",
24- lexer . ToString ( ) ) ;
18+ dumpingService . Dump ( lexer . ToString ( ) , "tokens" ) ;
2519 return tokens ;
2620 }
2721}
Original file line number Diff line number Diff line change 1- using System . IO . Abstractions ;
21using HydraScript . Domain . FrontEnd . Parser ;
32using Microsoft . Extensions . DependencyInjection ;
43
54namespace HydraScript . Infrastructure . Dumping ;
65
76internal class DumpingParser (
87 [ FromKeyedServices ( DecoratorKey . Value ) ] IParser parser ,
9- IFileSystem fileSystem ) : IParser
8+ IDumpingService dumpingService ) : IParser
109{
1110 public IAbstractSyntaxTree Parse ( string text )
1211 {
1312 var ast = parser . Parse ( text ) ;
14- fileSystem . File . WriteAllText ( " ast.dot" , ast . ToString ( ) ) ;
13+ dumpingService . Dump ( ast . ToString ( ) , "dot" ) ;
1514 return ast ;
1615 }
1716}
Original file line number Diff line number Diff line change 1- using System . IO . Abstractions ;
21using HydraScript . Domain . BackEnd ;
32using Microsoft . Extensions . DependencyInjection ;
4- using Microsoft . Extensions . Options ;
53
64namespace HydraScript . Infrastructure . Dumping ;
75
86internal class DumpingVirtualMachine (
97 [ FromKeyedServices ( DecoratorKey . Value ) ]
108 IVirtualMachine virtualMachine ,
11- IFileSystem fileSystem ,
12- IOptions < FileInfo > inputFile ) : IVirtualMachine
9+ IDumpingService dumpingService ) : IVirtualMachine
1310{
1411 public IExecuteParams ExecuteParams => virtualMachine . ExecuteParams ;
1512
1613 public void Run ( AddressedInstructions instructions )
1714 {
18- var fileName = inputFile . Value . Name . Split ( ".js" ) [ 0 ] ;
19- fileSystem . File . WriteAllText ( $ "{ fileName } .tac", instructions . ToString ( ) ) ;
20-
15+ dumpingService . Dump ( instructions . ToString ( ) , "tac" ) ;
2116 virtualMachine . Run ( instructions ) ;
2217 }
2318}
Original file line number Diff line number Diff line change @@ -37,15 +37,16 @@ public static IServiceCollection AddApplication(this IServiceCollection services
3737 public static IServiceCollection AddInfrastructure (
3838 this IServiceCollection services ,
3939 bool dump ,
40- FileInfo inputFileInfo )
40+ FileInfo fileInfo )
4141 {
4242 services . AddSingleton < IFileSystem , FileSystem > ( ) ;
43- services . AddSingleton ( Options . Create ( inputFileInfo ) ) ;
43+ services . AddSingleton ( Options . Create ( fileInfo ) ) ;
4444
4545 services . AddSingleton < IStaticAnalyzer , StaticAnalyzer > ( ) ;
4646 services . AddSingleton < ICodeGenerator , CodeGenerator > ( ) ;
4747
4848 services . AddSingleton < ISourceCodeProvider , SourceCodeProvider > ( ) ;
49+ services . AddSingleton < IDumpingService , DumpingService > ( ) ;
4950
5051 if ( dump )
5152 {
Original file line number Diff line number Diff line change @@ -24,15 +24,15 @@ public void Invoke_DumpOptionPassed_FilesCreated()
2424 runner . Invoke ( ) ;
2525 fileSystemMock . File . Received ( 1 )
2626 . WriteAllText (
27- TestHostFixture . ScriptFileName + ".tokens" ,
27+ Arg . Is < string > ( s => s . EndsWith ( TestHostFixture . ScriptFileName + ".tokens" ) ) ,
2828 Arg . Any < string > ( ) ) ;
2929 fileSystemMock . File . Received ( 1 )
3030 . WriteAllText (
31- "ast .dot",
31+ Arg . Is < string > ( s => s . EndsWith ( TestHostFixture . ScriptFileName + " .dot") ) ,
3232 Arg . Any < string > ( ) ) ;
3333 fileSystemMock . File . Received ( 1 )
3434 . WriteAllText (
35- TestHostFixture . ScriptFileName + ".tac" ,
35+ Arg . Is < string > ( s => s . EndsWith ( TestHostFixture . ScriptFileName + ".tac" ) ) ,
3636 Arg . Any < string > ( ) ) ;
3737 }
3838}
You can’t perform that action at this time.
0 commit comments