Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0f66abc
chore: turned off ReSharper warnings in CommonAssertions
feO2x Sep 16, 2023
b6d675c
docs: added missing 'and' in IsApproximately XML comments
feO2x Sep 16, 2023
42df27d
feat: add IsGreaterThanOrApproximately for double
feO2x Sep 16, 2023
d9e74b7
feat: add IsGreaterThanOrApproximately for float
feO2x Sep 16, 2023
9cf7891
feat: added IsLessThanOrApproximately
feO2x Sep 16, 2023
28fc837
docs: fixed missing 'f' indicator in default tolerance for IsLessThan…
feO2x Sep 16, 2023
3915932
Merge pull request #87 from feO2x/features/floating-point-is-approxim…
feO2x Sep 16, 2023
1d07843
chore: removed ReSharper warnings in Check.StringAssertions.cs
feO2x Sep 17, 2023
3e8e1ad
feat: add IsTrimmed for string, ReadOnlySpan<char> and Span<char>
feO2x Sep 17, 2023
4c156d4
feat: add IsTrimmedAtStart for string, ReadOnlySpan<char> and Span<char>
feO2x Sep 17, 2023
109c07a
docs: changed 'sequence' to 'span' for new IsTrimmedXXX methods
feO2x Sep 17, 2023
c73e522
feat: add IsTrimmedAtEnd from string, ReadOnlySpan<char> and Span<char>
feO2x Sep 17, 2023
34ae80d
feat: add MustBeTrimmedXXX assertions
feO2x Sep 17, 2023
f64990f
tests: add tests for MustBeTrimmed
feO2x Sep 18, 2023
fb71402
tests: add tests for MustBeTrimmedAtStart
feO2x Sep 19, 2023
80988b7
tests: add tests for MustBeTrimmedAtEnd
feO2x Sep 19, 2023
60e291b
Merge pull request #89 from feO2x/features/must-be-trimmed
feO2x Sep 19, 2023
37627ed
build: add release to nuget GitHub action
feO2x Sep 20, 2023
b1d7f3c
build: release-on-nuget.yml supports workflow_dispatch
feO2x Sep 20, 2023
2ade733
build: Release-to-Nuget now publishes packages
feO2x Sep 21, 2023
e14d71f
build: build-and-test.yml will only execute when code or the workflow…
feO2x Sep 21, 2023
673ae10
Merge pull request #90 from feO2x/features/release-to-nuget
feO2x Sep 21, 2023
ecb245d
docs: updated readme and version for 10.2.0 release
feO2x Sep 22, 2023
36dda65
chore: update license year in SourceFileMerger
feO2x Sep 22, 2023
be162b1
chore: updated single file for 10.2.0 release
feO2x Sep 22, 2023
673f79b
docs: light logo now uses raw.githubusercontent.com instead of the CD…
feO2x Sep 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ name: Build and Test

on:
push:
branches: [ main, dev ]
branches: [main, dev]
paths: ['Code/**', 'build-and-test.yml']
pull_request:
branches: [ main, dev ]
branches: [main, dev]
paths: ['Code/**', 'build-and-test.yml']

jobs:
build-and-test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/release-on-nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release to NuGet

on:
release:
types: [published]
workflow_dispatch:
inputs:
dotnetVersion:
description: "The version of .NET to use"
required: false
default: "7.0.x"

jobs:
release-to-nuget:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ github.event.inputs.dotnetVersion || '7.0.x' }}
- name: Prepare SNK file
env:
LIGHT_GUARDCLAUSES_SNK: ${{ secrets.LIGHT_GUARDCLAUSES_SNK }}
run: |
echo $LIGHT_GUARDCLAUSES_SNK | base64 --decode > ./Code/Light.GuardClauses/Light.GuardClauses.snk
- name: Create NuGet packages
run: dotnet pack ./Code/Light.GuardClauses/Light.GuardClauses.csproj -c Release /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=Light.GuardClauses.snk /p:ContinuousIntegrationBuild=true
- name: Delete SNK file
run: rm ./Code/Light.GuardClauses/Light.GuardClauses.snk
- name: Push nupkg package
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push "./Code/Light.GuardClauses/bin/Release/Light.GuardClauses.*.nupkg" --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void CreateSingleSourceFile(SourceFileMergeOptions options)
.AppendLine($@"License information for Light.GuardClauses

The MIT License (MIT)
Copyright (c) 2016, 2021 Kenny Pflug mailto:[email protected]
Copyright (c) 2016, 2023 Kenny Pflug mailto:[email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the ""Software""), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using FluentAssertions;
using Xunit;

namespace Light.GuardClauses.Tests.CommonAssertions;

public static class IsGreaterThanOrApproximatelyTests
{
[Theory]
[InlineData(17.4, 17.3, true)]
[InlineData(19.9999999, 20.0, true)]
[InlineData(-5.49998, -5.5, true)]
[InlineData(-5.4998, -5.4996, false)]
public static void DoubleWithDefaultTolerance(double first, double second, bool expected) =>
first.IsGreaterThanOrApproximately(second).Should().Be(expected);

[Theory]
[InlineData(15.91, 15.9, 0.1, true)]
[InlineData(24.449, 24.45, 0.0001, false)]
[InlineData(-3.12, -3.2, 0.001, true)]
[InlineData(2.369, 2.37, 0.0005, false)]
public static void DoubleWithCustomTolerance(double first, double second, double tolerance, bool expected) =>
first.IsGreaterThanOrApproximately(second, tolerance).Should().Be(expected);

[Theory]
[InlineData(100.225f, 100.2f, true)]
[InlineData(-5.9f, -5.5f, false)]
[InlineData(0f, -0.02f, true)]
[InlineData(-0.001f, 0f, false)]
public static void FloatWithDefaultTolerance(float first, float second, bool expected) =>
first.IsGreaterThanOrApproximately(second).Should().Be(expected);

[Theory]
[InlineData(2.0f, 1.0f, 0.1f, true)]
[InlineData(1.0f, 1.0f, 0.1f, true)]
[InlineData(1.0f, 1.1f, 0.01f, false)]
[InlineData(1.0f, 2.0f, 0.1f, false)]
public static void FloatWIthCustomTolerance(float first, float second, float tolerance, bool expected) =>
first.IsGreaterThanOrApproximately(second, tolerance).Should().Be(expected);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using FluentAssertions;
using Xunit;

namespace Light.GuardClauses.Tests.CommonAssertions;

public static class IsLessThanOrApproximatelyTests
{
[Theory]
[InlineData(13.25, 13.5, true)]
[InlineData(48.99, 48.98999, true)]
[InlineData(19.775, 19.7, false)]
[InlineData(-14.32, -14.33, false)]
public static void DoubleWithDefaultTolerance(double first, double second, bool expected) =>
first.IsLessThanOrApproximately(second).Should().Be(expected);

[Theory]
[InlineData(50.3, 50.5, 0.5, true)]
[InlineData(2015.5, 2015.3, 0.3, true)]
[InlineData(-519, -519.5, 0.25, false)]
[InlineData(0, -1, 0.9, false)]
public static void DoubleWithCustomTolerance(double first, double second, double tolerance, bool expected) =>
first.IsLessThanOrApproximately(second, tolerance).Should().Be(expected);

[Theory]
[InlineData(13.25f, 13.5f, true)]
[InlineData(48.99f, 48.98999f, true)]
[InlineData(19.775f, 19.7f, false)]
[InlineData(-14.32f, -14.33f, false)]
public static void FloatWithDefaultTolerance(float first, float second, bool expected) =>
first.IsLessThanOrApproximately(second).Should().Be(expected);

[Theory]
[InlineData(50.3f, 50.5f, 0.5f, true)]
[InlineData(2015.5f, 2015.3f, 0.3f, true)]
[InlineData(-519f, -519.5f, 0.25f, false)]
[InlineData(0f, -1f, 0.9f, false)]
public static void FloatWithCustomTolerance(float first, float second, float tolerance, bool expected) =>
first.IsLessThanOrApproximately(second, tolerance).Should().Be(expected);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using FluentAssertions;
using Light.GuardClauses.Exceptions;
using Light.GuardClauses.FrameworkExtensions;
using Xunit;

namespace Light.GuardClauses.Tests.StringAssertions;

public static class MustBeTrimmedAtEndTests
{
[Theory]
[InlineData("")]
[InlineData("foo")]
[InlineData(" bar")]
[InlineData("Sto p")]
public static void StringIsTrimmedAtEnd(string input) =>
input.MustBeTrimmedAtEnd().Should().BeSameAs(input);

[Fact]
public static void StringIsNull()
{
var nullString = default(string);

// ReSharper disable once ExpressionIsAlwaysNull
var act = () => nullString.MustBeTrimmedAtEnd(nameof(nullString));

act.Should().Throw<ArgumentNullException>()
.And.ParamName.Should().Be(nameof(nullString));
}

[Theory]
[InlineData("abc ")]
[InlineData(" Let's go\n")]
[InlineData("not trimmed at the end\t")]
public static void StringIsNotTrimmedAtTheEnd(string invalidString)
{
var act = () => invalidString.MustBeTrimmedAtEnd(nameof(invalidString));

act.Should().Throw<StringException>()
.And.Message.Should().Contain($"invalidString must be trimmed at the end, but it actually is {invalidString.ToStringOrNull()}");
}

[Fact]
public static void CustomExceptionStringNull() =>
Test.CustomException(
default(string),
(@null, exceptionFactory) => @null.MustBeTrimmedAtEnd(exceptionFactory)
);

[Theory]
[InlineData("Not trimmed at end ")]
[InlineData("Meh\t")]
public static void CustomExceptionInvalidString(string invalidString) =>
Test.CustomException(
invalidString,
(@string, exceptionFactory) => @string.MustBeTrimmedAtEnd(exceptionFactory)
);

[Fact]
public static void CallerArgumentExpression()
{
const string invalidString = "not trimmed ";

var act = () => invalidString.MustBeTrimmedAtEnd();

act.Should().Throw<StringException>()
.And.ParamName.Should().Be(nameof(invalidString));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using FluentAssertions;
using Light.GuardClauses.Exceptions;
using Light.GuardClauses.FrameworkExtensions;
using Xunit;

namespace Light.GuardClauses.Tests.StringAssertions;

public static class MustBeTrimmedAtStartTests
{
[Theory]
[InlineData("")]
[InlineData("foo")]
[InlineData("bar\n")]
[InlineData("I have white space ")]
public static void StringIsTrimmedAtStart(string input) =>
input.MustBeTrimmedAtStart().Should().BeSameAs(input);

[Fact]
public static void StringIsNulL()
{
var nullString = default(string);

// ReSharper disable once ExpressionIsAlwaysNull
var act = () => nullString.MustBeTrimmedAtStart(nameof(nullString));

act.Should().Throw<ArgumentNullException>()
.And.ParamName.Should().Be(nameof(nullString));
}

[Theory]
[InlineData(" Hey")]
[InlineData("\tTab")]
[InlineData(" White space on both ends ")]
public static void StringIsNotTrimmedAtStart(string invalidString)
{
var act = () => invalidString.MustBeTrimmedAtStart(nameof(invalidString));

act.Should().Throw<StringException>()
.And.Message.Should().Contain($"invalidString must be trimmed at the start, but it actually is {invalidString.ToStringOrNull()}");
}

[Fact]
public static void CustomExceptionStringNull() =>
Test.CustomException(
default(string),
(@null, exceptionFactory) => @null.MustBeTrimmedAtStart(exceptionFactory)
);

[Theory]
[InlineData(" Not trimmed at the start")]
[InlineData("\nFoo")]
public static void CustomExceptionInvalidString(string invalidString) =>
Test.CustomException(
invalidString,
(@string, exceptionFactory) => @string.MustBeTrimmedAtStart(exceptionFactory)
);

[Fact]
public static void CallerArgumentExpression()
{
const string invalidString = " Not trimmed at start";

var act = () => invalidString.MustBeTrimmedAtStart();

act.Should().Throw<StringException>()
.And.ParamName.Should().Be(nameof(invalidString));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using FluentAssertions;
using Light.GuardClauses.Exceptions;
using Light.GuardClauses.FrameworkExtensions;
using Xunit;

namespace Light.GuardClauses.Tests.StringAssertions;

public static class MustBeTrimmedTests
{
[Theory]
[InlineData("")]
[InlineData("foo")]
[InlineData("bar")]
[InlineData("Another string\twith whitespace")]
public static void StringIsTrimmed(string input) =>
input.MustBeTrimmed().Should().BeSameAs(input);

[Fact]
public static void StringIsNull()
{
var nullString = default(string);

// ReSharper disable once ExpressionIsAlwaysNull
var act = () => nullString.MustBeTrimmed(nameof(nullString));

act.Should().Throw<ArgumentNullException>()
.And.ParamName.Should().Be(nameof(nullString));
}

[Theory]
[InlineData("123 ")]
[InlineData("\nFoo")]
[InlineData(" not trimmed ")]
public static void StringIsNotTrimmed(string invalidString)
{
var act = () => invalidString.MustBeTrimmed(nameof(invalidString));

act.Should().Throw<StringException>()
.And.Message.Should().Contain($"invalidString must be trimmed, but it actually is {invalidString.ToStringOrNull()}");
}

[Fact]
public static void CustomExceptionStringNull()
{
Test.CustomException(
default(string),
(@null, exceptionFactory) => @null.MustBeTrimmed(exceptionFactory)
);
}

[Theory]
[InlineData(" This is not trimmed at the start")]
[InlineData("And not at the end\t ")]
public static void CustomExceptionInvalidString(string invalidString)
{
Test.CustomException(
invalidString,
(@string, exceptionFactory) => @string.MustBeTrimmed(exceptionFactory)
);
}

[Fact]
public static void CallerArgumentExpression()
{
const string invalidString = " Not trimmed ";

var act = () => invalidString.MustBeTrimmed();

act.Should().Throw<StringException>()
.And.ParamName.Should().Be(nameof(invalidString));
}
}
Loading