-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow EditorConfigFile to be used in-memory without access or use of …
…physical file system. (#25) * Make it possible to create EditorConfigFile file from the memory + add tests * Allow editor config without base directory * fix test to work on non windows OS's --------- Co-authored-by: Martijn Laarman <[email protected]>
- Loading branch information
Showing
5 changed files
with
96 additions
and
12 deletions.
There are no files selected for viewing
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
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,58 @@ | ||
using System.IO; | ||
using EditorConfig.Core; | ||
using FluentAssertions; | ||
using Microsoft.VisualBasic; | ||
using NUnit.Framework; | ||
|
||
namespace EditorConfig.Tests.InMemory | ||
{ | ||
[TestFixture] | ||
public class CachingTests : EditorConfigTestBase | ||
{ | ||
[Test] | ||
public void InMemoryConfigIsUsable() | ||
{ | ||
var configContent = @""" | ||
root = true | ||
[*.cs] | ||
end_of_line = lf | ||
"""; | ||
var stringReader = new StringReader(configContent); | ||
var editorConfigFile = EditorConfigFile.Parse(stringReader); | ||
|
||
var parser = new EditorConfigParser(); | ||
var config = parser.Parse("myfile.cs", new[] { editorConfigFile }); | ||
|
||
config.EditorConfigFiles.Should().ContainSingle(f => f.IsRoot); | ||
config.EndOfLine.Should().Be(EndOfLine.LF); | ||
} | ||
|
||
[Test] | ||
public void InMemoryConfigIsUsableWithVirtualPath() | ||
{ | ||
var virtualDirectory = Path.Combine(Directory.GetDirectoryRoot("."), "VirtualPath"); | ||
|
||
var configContent = @""" | ||
root = true | ||
[*.cs] | ||
end_of_line = lf | ||
"""; | ||
var stringReader = new StringReader(configContent); | ||
var editorConfigFile = EditorConfigFile.Parse(stringReader, virtualDirectory); | ||
|
||
var parser = new EditorConfigParser(); | ||
|
||
var file = Path.Combine(virtualDirectory, "myfile.cs"); | ||
var config1 = parser.Parse(file, new[] { editorConfigFile }); | ||
config1.EditorConfigFiles.Should().ContainSingle(f => f.IsRoot); | ||
config1.EndOfLine.Should().Be(EndOfLine.LF); | ||
|
||
var directoryOutOfScope = Path.Combine(Directory.GetDirectoryRoot("."), "DifferentDirectory"); | ||
var fileOutOfScope = Path.Combine(directoryOutOfScope, "myfile.cs"); | ||
var config2 = parser.Parse(fileOutOfScope, new[] { editorConfigFile }); | ||
config2.EditorConfigFiles.Should().BeEmpty(); | ||
} | ||
} | ||
} |