-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BinaryContent module to AVPRIndex
- Loading branch information
Showing
7 changed files
with
273 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace AVPRIndex | ||
|
||
open System | ||
open System.IO | ||
open System.Text | ||
open System.Security.Cryptography | ||
|
||
type BinaryContent = | ||
|
||
/// reads the content of the file at the given path and ensures that line endings are unified to `\n` | ||
static member fromString (str: string) = | ||
str.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|
||
|
||
/// reads the content of the file at the given path and ensures that line endings are unified to `\n` | ||
static member fromFile (path: string) = | ||
path | ||
|> File.ReadAllText | ||
|> BinaryContent.fromString |
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,63 @@ | ||
namespace BinaryContentTests | ||
|
||
open System | ||
open System.IO | ||
open System.Text | ||
open Xunit | ||
open AVPRIndex | ||
open AVPRIndex.Domain | ||
open ReferenceObjects | ||
|
||
module fromString = | ||
|
||
[<Fact>] | ||
let ``String with no line endings`` () = | ||
let actual = BinaryContent.fromString BinaryContent.StringInput.noLineEndings | ||
Assert.Equal<byte array>(BinaryContent.Content.noLineEndings, actual) | ||
|
||
[<Fact>] | ||
let ``String with CLRF`` () = | ||
let actual = BinaryContent.fromString BinaryContent.StringInput.windowsLineEndings | ||
Assert.Equal<byte array>(BinaryContent.Content.windowsLineEndings, actual) | ||
|
||
[<Fact>] | ||
let ``String with LF`` () = | ||
let actual = BinaryContent.fromString BinaryContent.StringInput.unixLineEndings | ||
Assert.Equal<byte array>(BinaryContent.Content.unixLineEndings, actual) | ||
|
||
[<Fact>] | ||
let ``String with mixed line endings`` () = | ||
let actual = BinaryContent.fromString BinaryContent.StringInput.mixedLineEndings | ||
Assert.Equal<byte array>(BinaryContent.Content.mixedLineEndings, actual) | ||
|
||
module fromFile = | ||
|
||
[<Fact>] | ||
let ``mandatory binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/valid@1.0.0.fsx" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.BindingFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/valid@2.0.0.fsx" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.BindingFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/invalid@0.0.fsx" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.BindingFrontmatter.invalidMissingMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``mandatory comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/valid@1.0.0.fsx" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.CommentFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/valid@2.0.0.fsx" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.CommentFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/invalid@0.0.fsx" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.CommentFrontmatter.invalidMissingMandatoryFrontmatter, actual) |
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
Oops, something went wrong.