-
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/[email protected]" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.BindingFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/[email protected]" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.BindingFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/[email protected]" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.BindingFrontmatter.invalidMissingMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``mandatory comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/[email protected]" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.CommentFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/[email protected]" |> BinaryContent.fromFile | ||
Assert.Equal<byte array>(BinaryContent.Content.CommentFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/[email protected]" |> 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,120 +9,120 @@ open AVPRIndex.Domain | |
open ReferenceObjects | ||
|
||
|
||
module hashString = | ||
module hashString = | ||
|
||
[<Fact>] | ||
let ``String with no line endings`` () = | ||
let actual = Hash.hashString Hash.Input.noLineEndings | ||
Assert.Equal(Hash.Hashes.noLineEndings, actual) | ||
[<Fact>] | ||
let ``String with no line endings`` () = | ||
let actual = Hash.hashString Hash.Input.noLineEndings | ||
Assert.Equal(Hash.Hashes.noLineEndings, actual) | ||
|
||
[<Fact>] | ||
let ``String with CLRF`` () = | ||
let actual = Hash.hashString Hash.Input.windowsLineEndings | ||
Assert.Equal(Hash.Hashes.windowsLineEndings, actual) | ||
[<Fact>] | ||
let ``String with CLRF`` () = | ||
let actual = Hash.hashString Hash.Input.windowsLineEndings | ||
Assert.Equal(Hash.Hashes.windowsLineEndings, actual) | ||
|
||
[<Fact>] | ||
let ``String with LF`` () = | ||
let actual = Hash.hashString Hash.Input.unixLineEndings | ||
Assert.Equal(Hash.Hashes.unixLineEndings, actual) | ||
[<Fact>] | ||
let ``String with LF`` () = | ||
let actual = Hash.hashString Hash.Input.unixLineEndings | ||
Assert.Equal(Hash.Hashes.unixLineEndings, actual) | ||
|
||
[<Fact>] | ||
let ``String with mixed line endings`` () = | ||
let actual = Hash.hashString Hash.Input.mixedLineEndings | ||
Assert.Equal(Hash.Hashes.mixedLineEndings, actual) | ||
[<Fact>] | ||
let ``String with mixed line endings`` () = | ||
let actual = Hash.hashString Hash.Input.mixedLineEndings | ||
Assert.Equal(Hash.Hashes.mixedLineEndings, actual) | ||
|
||
module hashContent = | ||
module hashContent = | ||
|
||
[<Fact>] | ||
let ``mandatory binding frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Binding/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full binding frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Binding/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
|
||
Assert.Equal(Hash.Hashes.BindingFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid binding frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Binding/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.invalidMissingMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``mandatory comment frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Comment/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
|
||
Assert.Equal(Hash.Hashes.CommentFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full comment frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Comment/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
Assert.Equal(Hash.Hashes.CommentFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid comment frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Comment/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
Assert.Equal(Hash.Hashes.CommentFrontmatter.invalidMissingMandatoryFrontmatter, actual) | ||
|
||
module hashFile = | ||
[<Fact>] | ||
let ``mandatory binding frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Binding/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full binding frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Binding/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
|
||
Assert.Equal(Hash.Hashes.BindingFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid binding frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Binding/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.invalidMissingMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``mandatory comment frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Comment/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
|
||
Assert.Equal(Hash.Hashes.CommentFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full comment frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Comment/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
Assert.Equal(Hash.Hashes.CommentFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid comment frontmatter file`` () = | ||
let actual = | ||
"fixtures/Frontmatter/Comment/[email protected]" | ||
|> File.ReadAllText | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
Assert.Equal(Hash.Hashes.CommentFrontmatter.invalidMissingMandatoryFrontmatter, actual) | ||
|
||
module hashFile = | ||
|
||
[<Fact>] | ||
let ``mandatory binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.invalidMissingMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``mandatory comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.CommentFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.CommentFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.CommentFrontmatter.invalidMissingMandatoryFrontmatter, actual) | ||
[<Fact>] | ||
let ``mandatory binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid binding frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Binding/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.BindingFrontmatter.invalidMissingMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``mandatory comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.CommentFrontmatter.validMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``full comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.CommentFrontmatter.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid comment frontmatter file`` () = | ||
let actual = "fixtures/Frontmatter/Comment/[email protected]" |> Hash.hashFile | ||
Assert.Equal(Hash.Hashes.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
Oops, something went wrong.